Skip to content

Commit 1976336

Browse files
[ECP-9623] Installment Feature Not Working with Saved Credit Cards (#2936)
* Installment Feature Not Working with Saved Credit Cards * Updating unit tests
1 parent 6622739 commit 1976336

File tree

3 files changed

+60
-30
lines changed

3 files changed

+60
-30
lines changed

Gateway/Request/RecurringVaultDataBuilder.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\Payment\Gateway\Helper\SubjectReader;
2121
use Magento\Payment\Gateway\Request\BuilderInterface;
2222
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;
23+
use Adyen\Payment\Observer\AdyenCcDataAssignObserver;
2324

2425
class RecurringVaultDataBuilder implements BuilderInterface
2526
{
@@ -97,6 +98,14 @@ public function build(array $buildSubject): array
9798
);
9899
}
99100

101+
$numberOfInstallments = $payment->getAdditionalInformation(
102+
AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS
103+
);
104+
105+
if (!empty($numberOfInstallments)) {
106+
$requestBody['installments']['value'] = (int) $numberOfInstallments;
107+
}
108+
100109
return [
101110
'body' => $requestBody
102111
];

Test/Unit/Gateway/Request/RecurringVaultDataBuilderTest.php

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Magento\Vault\Api\Data\PaymentTokenInterface;
2626
use Magento\Vault\Model\Method\Vault;
2727
use PHPUnit\Framework\MockObject\MockObject;
28+
use Adyen\Payment\Observer\AdyenCcDataAssignObserver;
2829

2930
class RecurringVaultDataBuilderTest extends AbstractAdyenTestCase
3031
{
@@ -62,13 +63,14 @@ protected function tearDown(): void
6263
* @param $tokenDetails
6364
* @param $tokenType
6465
* @param $isInstantPurchase
66+
* @param $numberOfInstallments
6567
*
6668
* @return void
6769
* @throws LocalizedException
6870
*
6971
* @dataProvider dataProvider
7072
*/
71-
public function testBuild($paymentMethodCode, $tokenDetails, $tokenType, $isInstantPurchase)
73+
public function testBuild($paymentMethodCode, $tokenDetails, $tokenType, $isInstantPurchase, $numberOfInstallments)
7274
{
7375
$quoteId = 1;
7476
$storeId = 1;
@@ -98,8 +100,13 @@ public function testBuild($paymentMethodCode, $tokenDetails, $tokenType, $isInst
98100
$paymentMock->method('getMethodInstance')->willReturn($paymentMethodInstanceMock);
99101
$paymentMock->method('getExtensionAttributes')->willReturn($extensionAttributesMock);
100102
$paymentMock->method('getAdditionalInformation')
101-
->with('instant-purchase')
102-
->willReturn($isInstantPurchase);
103+
->willReturnCallback(function ($key) use ($isInstantPurchase, $numberOfInstallments) {
104+
return match ($key) {
105+
'instant-purchase' => $isInstantPurchase,
106+
AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS => $numberOfInstallments,
107+
default => null,
108+
};
109+
});
103110

104111
$buildSubject = [
105112
'payment' => $this->createConfiguredMock(PaymentDataObject::class, [
@@ -113,7 +120,8 @@ public function testBuild($paymentMethodCode, $tokenDetails, $tokenType, $isInst
113120
if ($tokenType === PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD && !$isInstantPurchase) {
114121
$this->stateDataHelperMock->expects($this->once())
115122
->method('getStateData')
116-
->with($quoteId);
123+
->with($quoteId)
124+
->willReturn([]);
117125
}
118126

119127
$request = $this->recurringVaultDataBuilder->build($buildSubject);
@@ -127,47 +135,59 @@ public function testBuild($paymentMethodCode, $tokenDetails, $tokenType, $isInst
127135
} else {
128136
$this->assertArrayNotHasKey('additionalData', $request['body']);
129137
}
138+
139+
if (!empty($numberOfInstallments)) {
140+
$this->assertArrayHasKey('installments', $request['body']);
141+
$this->assertEquals(['value' => (int) $numberOfInstallments], $request['body']['installments']);
142+
}
130143
}
131144

132145
public static function dataProvider(): array
133146
{
134147
return [
135148
[
136-
'paymentMethodCode' => 'adyen_cc_vault',
137-
'tokenDetails' => '{"type":"visa","maskedCC":"1111","expirationDate":"3\/2030", "tokenType": "CardOnFile"}',
138-
'tokenType' => 'card',
139-
'isInstantPurchase' => false
149+
'adyen_cc_vault',
150+
'{"type":"visa","maskedCC":"1111","expirationDate":"3\/2030", "tokenType": "CardOnFile"}',
151+
'card',
152+
false,
153+
'3'
140154
],
141155
[
142-
'paymentMethodCode' => 'adyen_cc_vault',
143-
'tokenDetails' => '{"type":"visa","maskedCC":"1111","expirationDate":"3\/2030"}',
144-
'tokenType' => 'card',
145-
'isInstantPurchase' => false
156+
'adyen_cc_vault',
157+
'{"type":"visa","maskedCC":"1111","expirationDate":"3\/2030"}',
158+
'card',
159+
false,
160+
null
146161
],
147162
[
148-
'paymentMethodCode' => 'adyen_cc_vault',
149-
'tokenDetails' => '{"type":"visa","maskedCC":"1111","expirationDate":"3\/2030"}',
150-
'tokenType' => 'card',
151-
'isInstantPurchase' => true
163+
'adyen_cc_vault',
164+
'{"type":"visa","maskedCC":"1111","expirationDate":"3\/2030"}',
165+
'card',
166+
true,
167+
null
152168
],
153169
[
154-
'paymentMethodCode' => 'adyen_klarna_vault',
155-
'tokenDetails' => '{"type":"klarna", "tokenType": "CardOnFile"}',
156-
'tokenType' => 'account',
157-
'isInstantPurchase' => false
170+
'adyen_klarna_vault',
171+
'{"type":"klarna", "tokenType": "CardOnFile"}',
172+
'account',
173+
false,
174+
null
158175
],
159176
[
160-
'paymentMethodCode' => 'adyen_klarna_vault',
161-
'tokenDetails' => '{"type":"klarna"}',
162-
'tokenType' => 'account',
163-
'isInstantPurchase' => false
177+
'adyen_klarna_vault',
178+
'{"type":"klarna"}',
179+
'account',
180+
false,
181+
null
164182
],
165183
[
166-
'paymentMethodCode' => 'adyen_klarna_vault',
167-
'tokenDetails' => '{"type":"klarna"}',
168-
'tokenType' => 'account',
169-
'isInstantPurchase' => true
184+
'adyen_klarna_vault',
185+
'{"type":"klarna"}',
186+
'account',
187+
true,
188+
null
170189
]
171190
];
172191
}
192+
173193
}

view/frontend/web/js/view/payment/method-renderer/adyen-cc-vault-method.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,9 @@ define([
256256
additional_data: {
257257
stateData: stateData,
258258
public_hash: this.publicHash,
259-
numberOfInstallments: this.installment(),
260-
frontendType: 'default'
259+
'number_of_installments': self.installment(),
260+
frontendType: 'default',
261+
'cc_type': self.getCcCodeByAltCode(self.getCardType())
261262
},
262263
};
263264
},

0 commit comments

Comments
 (0)