Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal Rest API Create Payment Not Returning the Sale Id

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

like image 299
nfplee Avatar asked Nov 08 '22 13:11

nfplee


1 Answers

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.

like image 138
nfplee Avatar answered Nov 14 '22 22:11

nfplee