简体   繁体   中英

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":"someone@somewhere.com","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-XXXXXXXXXXXX XXXXXXXXXX ","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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM