diff --git a/src/Service/OrderService.php b/src/Service/OrderService.php index 46def6f4a..47dfacc75 100644 --- a/src/Service/OrderService.php +++ b/src/Service/OrderService.php @@ -222,7 +222,7 @@ public function updateMollieDataCustomFields(OrderEntity $order, string $mollieO $thirdPartyPaymentId = ''; $molliePaymentID = ''; $creditCardDetails = null; - + $bankTransferDetails = null; try { // Add the transaction ID to the order's custom fields // We might need this later on for reconciliation @@ -238,6 +238,7 @@ public function updateMollieDataCustomFields(OrderEntity $order, string $mollieO # check if we have a Bank Transfer reference if (isset($molliePayment->details, $molliePayment->details->transferReference)) { $thirdPartyPaymentId = $molliePayment->details->transferReference; + $bankTransferDetails = $molliePayment->details; } # check for creditcard @@ -257,6 +258,7 @@ public function updateMollieDataCustomFields(OrderEntity $order, string $mollieO $customFieldsStruct->setMolliePaymentId($molliePaymentID); $customFieldsStruct->setThirdPartyPaymentId($thirdPartyPaymentId); $customFieldsStruct->setCreditCardDetails($creditCardDetails); + $customFieldsStruct->setBankTransferDetails($bankTransferDetails); $this->updateOrderCustomFields->updateOrder( $order->getId(), diff --git a/src/Struct/Order/OrderAttributes.php b/src/Struct/Order/OrderAttributes.php index 58dd60429..a9f0375b1 100644 --- a/src/Struct/Order/OrderAttributes.php +++ b/src/Struct/Order/OrderAttributes.php @@ -89,6 +89,20 @@ class OrderAttributes */ private $order; + /** + * @var string + */ + private $bankName; + + /** + * @var string + */ + private $bankAccount; + + /** + * @var string + */ + private $bankBic; /** * @param OrderEntity $order @@ -110,6 +124,9 @@ public function __construct(OrderEntity $order) $this->creditCardCountryCode = $this->getCustomFieldValue($order, 'creditCardCountryCode'); $this->creditCardSecurity = $this->getCustomFieldValue($order, 'creditCardSecurity'); $this->creditCardFeeRegion = $this->getCustomFieldValue($order, 'creditCardFeeRegion'); + $this->bankName = $this->getCustomFieldValue($order, 'bankName'); + $this->bankAccount = $this->getCustomFieldValue($order, 'bankAccount'); + $this->bankBic = $this->getCustomFieldValue($order, 'bankBic'); $this->timezone = $this->getCustomFieldValue($order, 'timezone'); } @@ -315,6 +332,56 @@ public function setCreditCardFeeRegion(string $creditCardFeeRegion): void $this->creditCardFeeRegion = $creditCardFeeRegion; } + /** + * @return string + */ + public function getBankName(): string + { + return $this->bankName; + } + + /** + * @param string $bankName + */ + public function setBankName(string $bankName): void + { + $this->bankName = $bankName; + } + + /** + * @return string + */ + public function getBankAccount(): string + { + return $this->bankAccount; + } + + /** + * @param string $bankAccount + */ + public function setBankAccount(string $bankAccount): void + { + $this->bankAccount = $bankAccount; + } + + /** + * @return string + */ + public function getBankBic(): string + { + return $this->bankBic; + } + + /** + * @param string $bankBic + */ + public function setBankBic(string $bankBic): void + { + $this->bankBic = $bankBic; + } + + + /** * @return string */ @@ -337,29 +404,45 @@ public function setTimezone(string $timezone): void */ public function setCreditCardDetails(?stdClass $details) { - if (!empty($details->cardNumber)) { + if (! empty($details->cardNumber)) { $this->creditCardNumber = $details->cardNumber; } - if (!empty($details->cardHolder)) { + if (! empty($details->cardHolder)) { $this->creditCardHolder = $details->cardHolder; } - if (!empty($details->cardAudience)) { + if (! empty($details->cardAudience)) { $this->creditCardAudience = $details->cardAudience; } - if (!empty($details->cardLabel)) { + if (! empty($details->cardLabel)) { $this->creditCardLabel = $details->cardLabel; } - if (!empty($details->cardCountryCode)) { + if (! empty($details->cardCountryCode)) { $this->creditCardCountryCode = $details->cardCountryCode; } - if (!empty($details->cardSecurity)) { + if (! empty($details->cardSecurity)) { $this->creditCardSecurity = $details->cardSecurity; } - if (!empty($details->feeRegion)) { + if (! empty($details->feeRegion)) { $this->creditCardFeeRegion = $details->feeRegion; } } + /** + * @param null|stdClass $details + * @return void + */ + public function setBankTransferDetails(?stdClass $details) + { + if (! empty($details->bankName)) { + $this->bankName = $details->bankName; + } + if (! empty($details->bankAccount)) { + $this->bankAccount = $details->bankAccount; + } + if (! empty($details->bankBic)) { + $this->bankBic = $details->bankBic; + } + } /** * @return array @@ -433,6 +516,18 @@ public function toArray(): array $mollieData['timezone'] = $this->timezone; } + if ((string)$this->bankName !== '') { + $mollieData['bankName'] = $this->bankName; + } + + if ((string)$this->bankAccount !== '') { + $mollieData['bankAccount'] = $this->bankAccount; + } + + if ((string)$this->bankBic !== '') { + $mollieData['bankBic'] = $this->bankBic; + } + return [ 'mollie_payments' => $mollieData, ]; @@ -445,12 +540,12 @@ public function isTypeSubscription(): bool { # if we already have a mollie subscription ID # then we KNOW it's a subscription - if (!empty($this->mollieSubscriptionId)) { + if (! empty($this->mollieSubscriptionId)) { return true; } # also a shopware subscription id reference, means we have one - if (!empty($this->swSubscriptionId)) { + if (! empty($this->swSubscriptionId)) { return true; } diff --git a/src/Subscriber/CheckoutConfirmPageSubscriber.php b/src/Subscriber/CheckoutConfirmPageSubscriber.php index 2a2755fb6..e3f5187c6 100644 --- a/src/Subscriber/CheckoutConfirmPageSubscriber.php +++ b/src/Subscriber/CheckoutConfirmPageSubscriber.php @@ -6,9 +6,6 @@ use Kiener\MolliePayments\Factory\MollieApiFactory; use Kiener\MolliePayments\Gateway\MollieGatewayInterface; use Kiener\MolliePayments\Handler\Method\CreditCardPayment; -use Kiener\MolliePayments\Handler\Method\PosPayment; -use Kiener\MolliePayments\Repository\Language\LanguageRepositoryInterface; -use Kiener\MolliePayments\Repository\Locale\LocaleRepositoryInterface; use Kiener\MolliePayments\Service\CustomerService; use Kiener\MolliePayments\Service\CustomFieldService; use Kiener\MolliePayments\Service\MandateServiceInterface; @@ -19,13 +16,8 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Method; -use Mollie\Api\Resources\Terminal; use Mollie\Api\Types\PaymentMethod; use Shopware\Core\Checkout\Customer\CustomerEntity; -use Shopware\Core\Checkout\Payment\PaymentMethodEntity; -use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; -use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; -use Shopware\Core\System\Language\LanguageEntity; use Shopware\Storefront\Page\Account\Order\AccountEditOrderPageLoadedEvent; use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; diff --git a/tests/PHPUnit/Struct/Order/OrderAttributesTest.php b/tests/PHPUnit/Struct/Order/OrderAttributesTest.php index 33a46f401..58e8a6d1c 100644 --- a/tests/PHPUnit/Struct/Order/OrderAttributesTest.php +++ b/tests/PHPUnit/Struct/Order/OrderAttributesTest.php @@ -54,4 +54,47 @@ public function testIsSubscriptionWithShopwareId() $this->assertEquals(true, $attributes->isTypeSubscription()); } + + public function testReadBankDataFromCustomFields() + { + + $expectedBankName = 'Stichting Mollie Payments'; + $expectedBankBIC = 'TESTNL10'; + $expectedBankAccount = 'NL10TEST000100100'; + $order = new OrderEntity(); + $order->setCustomFields([ + 'mollie_payments' => [ + 'bankName' => $expectedBankName, + 'bankBic' => $expectedBankBIC, + 'bankAccount' => $expectedBankAccount, + ] + ]); + + $attributes = new OrderAttributes($order); + + $this->assertSame($expectedBankName, $attributes->getBankName()); + $this->assertSame($expectedBankBIC, $attributes->getBankBic()); + $this->assertSame($expectedBankAccount, $attributes->getBankAccount()); + } + + public function testBankTransferDetailsAreSetFromApiStruct() + { + $expectedBankName = 'Stichting Mollie Payments'; + $expectedBankBIC = 'TESTNL10'; + $expectedBankAccount = 'NL10TEST000100100'; + + $bankTransferDetails = new \stdClass(); + $bankTransferDetails->bankName = $expectedBankName; + $bankTransferDetails->bankAccount = $expectedBankAccount; + $bankTransferDetails->bankBic = $expectedBankBIC; + + $order = new OrderEntity(); + + $attributes = new OrderAttributes($order); + $attributes->setBankTransferDetails($bankTransferDetails); + + $this->assertSame($expectedBankName, $attributes->getBankName()); + $this->assertSame($expectedBankBIC, $attributes->getBankBic()); + $this->assertSame($expectedBankAccount, $attributes->getBankAccount()); + } }