|
19 | 19 | use Adyen\Service\Checkout\PaymentLinksApi; |
20 | 20 | use Adyen\Service\Checkout\PaymentsApi; |
21 | 21 | use Adyen\Service\Checkout\RecurringApi; |
| 22 | +use Adyen\Model\Checkout\LineItem; |
22 | 23 |
|
23 | 24 | class ModelBasedCheckoutTest extends TestCaseMock |
24 | 25 | { |
@@ -380,4 +381,56 @@ public function testNonNullableSettersCanBeNulled() |
380 | 381 | // Assert nulled value is not in serialised string |
381 | 382 | $this->assertFalse(strpos($jsonString, 'billingAddress') !== false); |
382 | 383 | } |
| 384 | + |
| 385 | + // test request JSON payload serialization |
| 386 | + public function testJsonSerializationMatchesExpected() |
| 387 | + { |
| 388 | + $amount = new Amount(); |
| 389 | + $amount->setCurrency('EUR')->setValue(10000); |
| 390 | + |
| 391 | + $lineItem1 = new LineItem(); |
| 392 | + $lineItem1->setQuantity(1)->setAmountIncludingTax(5000)->setDescription('Sunglasses'); |
| 393 | + $lineItem2 = new LineItem(); |
| 394 | + $lineItem2->setQuantity(1)->setAmountIncludingTax(5000)->setDescription('Headphones'); |
| 395 | + |
| 396 | + $request = new CreateCheckoutSessionRequest(); |
| 397 | + $request |
| 398 | + ->setChannel('Web') |
| 399 | + ->setAmount($amount) |
| 400 | + ->setCountryCode('NL') |
| 401 | + ->setMerchantAccount('YOUR_MERCHANT_ACCOUNT') |
| 402 | + ->setReference('YOUR_PAYMENT_REFERENCE') |
| 403 | + ->setReturnUrl('https://mycompany.example.org/redirect?orderRef=YOUR_PAYMENT_REFERENCE') |
| 404 | + ->setLineItems([$lineItem1, $lineItem2]); |
| 405 | + |
| 406 | + $expectedJson = <<<JSON |
| 407 | + { |
| 408 | + "channel": "Web", |
| 409 | + "amount": { |
| 410 | + "currency": "EUR", |
| 411 | + "value": 10000 |
| 412 | + }, |
| 413 | + "countryCode": "NL", |
| 414 | + "merchantAccount": "YOUR_MERCHANT_ACCOUNT", |
| 415 | + "reference": "YOUR_PAYMENT_REFERENCE", |
| 416 | + "returnUrl": "https://mycompany.example.org/redirect?orderRef=YOUR_PAYMENT_REFERENCE", |
| 417 | + "lineItems": [ |
| 418 | + { |
| 419 | + "quantity": 1, |
| 420 | + "amountIncludingTax": 5000, |
| 421 | + "description": "Sunglasses" |
| 422 | + }, |
| 423 | + { |
| 424 | + "quantity": 1, |
| 425 | + "amountIncludingTax": 5000, |
| 426 | + "description": "Headphones" |
| 427 | + } |
| 428 | + ] |
| 429 | + } |
| 430 | + JSON; |
| 431 | + |
| 432 | + $actualJson = json_encode($request, JSON_PRETTY_PRINT); |
| 433 | + |
| 434 | + $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson); |
| 435 | + } |
383 | 436 | } |
0 commit comments