PayPal Rest API 创建付款不返回销售 ID

Posted

技术标签:

【中文标题】PayPal Rest API 创建付款不返回销售 ID【英文标题】:PayPal Rest API Create Payment Not Returning the Sale Id 【发布时间】:2016-10-14 03:26:53 【问题描述】:

我正在尝试使用 PayPal 的 REST API(沙盒)执行信用卡付款。代码如下:

$payment = new Payment();
$payment->setIntent('sale');
...

try 
    $payment->create($this->apiContext);

    $saleId = $payment->getTransactions()[0]->getRelatedResources()[0]->getSale()->getId();
 catch (PayPalConnectionException $ex) 
    ...

这会发送以下 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","帐单地址":"line1":"123 测试街","line2":"","city":"测试 城市","州":"","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 恤 黑色的 小号","货币":"GBP","quantity":"1","sku":"abc123","price":"8.33"],"shipping_address":"recipient_name":"Jim 史密斯","line1":"123 测试街","line2":"","city":"测试 City","state":"Some State","postal_code":"XXXX XXX","country_code":"GB","description":"付款 详细信息","invoice_number":"XXXXX"]

直到最近它运行良好,但现在它不会为相关资源返回任何内容。这是我要返回的 json:

"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 测试街","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":"付款 details","item_list":"items":["name":"T恤黑色 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 州","postal_code":"XXXX XXX","country_code":"GB","related_resources":[]],"links":["href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-XXXXXXXXXXXXXXXXXXXXXX","re​​l":"self","method": “获取”]

请注意,我使用的是 1.7.2 版的 API,并且我最近升级到了 php 7 版。

如果有人能解释我做错了什么,我将不胜感激。

谢谢

【问题讨论】:

您还需要放置错误日志,并指定您的集成设置,例如端点设置为沙盒还是实时?您的 PAY api 调用的响应是什么.. @pp_pduan 我已经更新了问题,说明我正在使用沙箱并且我正在返回 json 响应。如您所见,related_resources 是空的。我希望这会有所帮助。 版本 1.7.2???有这样的版本号吗,当前版本是204 @SML 我将使用 composer 的最新版本。 packagist.org/packages/paypal/rest-api-sdk-php 我明白了,所以问题是在升级到 PHP 7 后才开始的,对吗?你之前用的是什么版本? 【参考方案1】:

虽然不是我自己的错,但我终于设法让它工作了。我的沙盒买家帐户似乎不再有效。我找到了以下文件:

https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/payments/CreatePaymentUsingPayPal.php

这很好,所以我玩了一个发现不同的游戏,唯一有助于解决问题的方法是使用他们样本中的卡片详细信息。我已经在这个问题上花费了相当长的时间,所以我将接受它工作正常,并希望我不会在生产过程中遇到任何问题。

【讨论】:

谢谢@nfplee 我现在对贝宝实施用户体验的流程感到非常困惑。

以上是关于PayPal Rest API 创建付款不返回销售 ID的主要内容,如果未能解决你的问题,请参考以下文章

PayPal REST API [沙盒] - 执行付款销售时出现 INTERNAL_SERVICE_ERROR

PayPal REST API“列出付款”不返回任何条目

使用 Paypal REST API 创建付款

PayPal REST API Payment::get 不返回电话

如何通过 REST SDK 获取已执行 PayPal 付款的销售 ID

PayPal Rest API 直接付款