Skip to content

Commit 7c9e261

Browse files
authored
Merge pull request #777 from Adyen/add-serialisation-test
Add test for JSON serialisation
2 parents 8772d6c + 0f3ea51 commit 7c9e261

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/Unit/ModelBasedCheckoutTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Adyen\Service\Checkout\PaymentLinksApi;
2020
use Adyen\Service\Checkout\PaymentsApi;
2121
use Adyen\Service\Checkout\RecurringApi;
22+
use Adyen\Model\Checkout\LineItem;
2223

2324
class ModelBasedCheckoutTest extends TestCaseMock
2425
{
@@ -380,4 +381,56 @@ public function testNonNullableSettersCanBeNulled()
380381
// Assert nulled value is not in serialised string
381382
$this->assertFalse(strpos($jsonString, 'billingAddress') !== false);
382383
}
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+
}
383436
}

0 commit comments

Comments
 (0)