From 16ebb737de3ffb9f60e4aa51bd64eb6c9e7eef9d Mon Sep 17 00:00:00 2001 From: Paul Siedler Date: Fri, 27 Feb 2026 17:39:57 +0100 Subject: [PATCH] fix: fall back to CustomerUser name for B2B addresses The Mollie API requires givenName and familyName on billing and shipping addresses. In B2B scenarios, ERP-imported addresses often only contain an organization name with no personal names. When the billing or shipping address lacks a first or last name, fall back to the CustomerUser's name which is always populated. Closes #54 --- Mapper/MollieDtoMapper.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Mapper/MollieDtoMapper.php b/Mapper/MollieDtoMapper.php index 2e00bdf..bb3dc78 100644 --- a/Mapper/MollieDtoMapper.php +++ b/Mapper/MollieDtoMapper.php @@ -203,6 +203,18 @@ public function getOrderData(PaymentTransaction $paymentTransaction) ), ]); + // Fall back to CustomerUser name when address has no first/last name (common in B2B) + $customerUser = $order->getCustomerUser(); + $mollieAddress = $orderData->getBillingAddress(); + if ( + $customerUser + && ((string) $billingAddress->getFirstName() === '' || (string) $billingAddress->getLastName() === '') + ) { + $mollieAddress->setGivenName($customerUser->getFirstName()); + $mollieAddress->setFamilyName($customerUser->getLastName()); + $orderData->setBillingAddress($mollieAddress); + } + $orderData->setLines( array_merge( $this->getOrderLinesData($orderLines), @@ -212,6 +224,16 @@ public function getOrderData(PaymentTransaction $paymentTransaction) if ($shippingAddress = $order->getShippingAddress()) { $orderData->setShippingAddress($this->getAddressData($shippingAddress, $order->getEmail())); + + if ( + $customerUser + && ((string) $shippingAddress->getFirstName() === '' || (string) $shippingAddress->getLastName() === '') + ) { + $mollieShipping = $orderData->getShippingAddress(); + $mollieShipping->setGivenName($customerUser->getFirstName()); + $mollieShipping->setFamilyName($customerUser->getLastName()); + $orderData->setShippingAddress($mollieShipping); + } } if ($frontendOwner = $paymentTransaction->getFrontendOwner()) {