I'm trying to execute a credit card payment with PayPal's rest API (sandbox). Here's the code:
$payment = new Payment();
$payment->setIntent('sale');
...
try {
$payment->create($this->apiContext);
$saleId = $payment->getTransactions()[0]->getRelatedResources()[0]->getSale()->getId();
} catch (PayPalConnectionException $ex) {
...
}
This sends the following JSON:
{"experience_profile_id":"XX-XXXX-XXXX-XXXX-XXXX","intent":"sale","payer":{"payer_info":{"first_name":"Jim","last_name":"Smith","email":"[email protected]","phone":""},"payment_method":"credit_card","funding_instruments":[{"credit_card":{"first_name":"Jim","last_name":"Smith","number":"XXXXXXXXXXXX4487","type":"visa","expire_month":"06","expire_year":"2020","cvv2":"123","billing_address":{"line1":"123 Test Street","line2":"","city":"Test City","state":"","postal_code":"XXXX XXX","country_code":"GB"}}}]},"transactions":[{"amount":{"currency":"GBP","total":"13.50","details":{"shipping":"3.50","tax":"1.67","subtotal":"8.33"}},"item_list":{"items":[{"name":"T-Shirt Black Small","currency":"GBP","quantity":"1","sku":"abc123","price":"8.33"}],"shipping_address":{"recipient_name":"Jim Smith","line1":"123 Test Street","line2":"","city":"Test City","state":"Some State","postal_code":"XXXX XXX","country_code":"GB"}},"description":"Payment details","invoice_number":"XXXXX"}]}
This was working fine until recently, however now it doesn't return anything for the related resources. here's the json I am getting back:
{"id":"PAY-XXXXXXXXXXXXXXXXXXXXXX","create_time":"2016-06-20T11:45:28Z","update_time":"2016-06-20T11:45:28Z","state":"created","intent":"sale","payer":{"payment_method":"credit_card","funding_instruments":[{"credit_card":{"type":"visa","number":"xxxxxxxxxxxx4487","expire_month":"6","expire_year":"2020","first_name":"Jim","last_name":"Smith","billing_address":{"line1":"123 Test Street","city":"Test City","postal_code":"XXXX XXX","country_code":"GB"}}}]},"transactions":[{"amount":{"total":"13.50","currency":"GBP","details":{"subtotal":"8.33","tax":"1.67","shipping":"3.50"}},"description":"Payment details","item_list":{"items":[{"name":"T-Shirt Black Small","sku":"abc123","price":"8.33","currency":"GBP","quantity":"1"}],"shipping_address":{"recipient_name":"Jim Smith","line1":"123 Test Street","city":"Test City","state":"Some State","postal_code":"XXXX XXX","country_code":"GB"}},"related_resources":[]}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-XXXXXXXXXXXXXXXXXXXXXX","rel":"self","method":"GET"}]}
Please note I'm using version 1.7.2 of the API and I have recently upgraded to PHP version 7.
I'd appreciate it if someone could explain what I'm doing wrong.
Thanks
I have finally managed to get this working although from no fault of my own. It appears my sandbox buyer account is no longer working. I found the following document:
https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/payments/CreatePaymentUsingPayPal.php
This worked fine so I played a game of spot the different and the only thing which helped resolve the issue was using the card details in their sample. I've already spent some considerable time on this problem so I'm going to accept that it's working fine and hopefully I won't run into any issues during production.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With