Skip to content

Commit

Permalink
NTR: PISHPS-204: store bank data in order custom fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalij Mik committed Dec 11, 2023
1 parent ab42644 commit aa18cc9
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/Service/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(),
Expand Down
113 changes: 104 additions & 9 deletions src/Struct/Order/OrderAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ class OrderAttributes
*/
private $order;

/**
* @var string
*/
private $bankName;

/**
* @var string
*/
private $bankAccount;

/**
* @var string
*/
private $bankBic;

/**
* @param OrderEntity $order
Expand All @@ -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');
}

Expand Down Expand Up @@ -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
*/
Expand All @@ -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<string,mixed>
Expand Down Expand Up @@ -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,
];
Expand All @@ -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;
}

Expand Down
8 changes: 0 additions & 8 deletions src/Subscriber/CheckoutConfirmPageSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
43 changes: 43 additions & 0 deletions tests/PHPUnit/Struct/Order/OrderAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit aa18cc9

Please sign in to comment.