2525use Magento \Vault \Api \Data \PaymentTokenInterface ;
2626use Magento \Vault \Model \Method \Vault ;
2727use PHPUnit \Framework \MockObject \MockObject ;
28+ use Adyen \Payment \Observer \AdyenCcDataAssignObserver ;
2829
2930class 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}
0 commit comments