5
votes

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

1
You need to put up the error logs as well, and specify the setups of your integration e.g. endpoint set to sandbox or live? what's in the response of your PAY api call..pp_pduan
@pp_pduan I have updated the question stating that I am using the sandbox and the json response I am getting back. As you can see the related_resources is empty. I hope this helps.nfplee
version 1.7.2??? Does such version number exist?, the current version is 204SML
@SML I'm going by the latest version on composer. packagist.org/packages/paypal/rest-api-sdk-phpnfplee
I see, so the problem only started after upgrading to PHP version 7, correct? What version were you using before then?SML

1 Answers

1
votes

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.