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

时间:2016-06-13 16:02:26

标签: php paypal paypal-rest-sdk

我尝试使用PayPal的其余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""意图":"销售"&# 34;付款人" {" payer_info" {"如first_name":"吉姆""姓氏":" Smith和#34;"电子邮件":" someone@somewhere.com","电话":""}"&PAYMENT_METHOD #34;:" CREDIT_CARD"" funding_instruments":[{" CREDIT_CARD" {"如first_name":"吉姆&#34 ;,"姓氏":"史密斯""数":" XXXXXXXXXXXX4487""类型":&#34 ;签证"" expire_month":" 06"" EXPIRE_YEAR":" 2020"" CVV2" :" 123"" billing_address" {"第1行":" 123   测试街"," line2":""," city":"测试   市""状态":""" POSTAL_CODE":" XXXX   XXX"" COUNTRY_CODE":" GB"}}}]},"记录":[{"量":{& #34;货币":" GBP""总":" 13.50""细节" {"航运":" 3.50""税":" 1.67""小计":" 8.33&# 34;}}," item_list" {"项目":[{"名称":" T恤   黑色   小""货币":" GBP""量":" 1"" SKU&#34 ;: " ABC123""价格":" 8.33"}]," shipping_address" {" RECIPIENT_NAME":& #34;吉姆   Smith"," line1":" 123 Test Street"," line2":""," city&#34 ;:"试验   City","州":"某些州"," postal_code":" XXXX   XXX"" COUNTRY_CODE":" GB"}},"描述":"付款   细节"" INVOICE_NUMBER":" XXXXX"}]}

直到最近这个工作正常,但是现在它没有为相关资源返回任何内容。这是我回来的json:

  

{" ID":"付费XXXXXXXXXXXXXXXXXXXXXX"" CREATE_TIME":" 2016-06-20T11:45:28Z&#34 ;, " UPDATE_TIME":" 2016-06-20T11:45:28Z""状态":"创建""意图&# 34;:"销售""付款人" {" PAYMENT_METHOD":" CREDIT_CARD"" funding_instruments":[ {" CREDIT_CARD" {"类型":"签证""数":" xxxxxxxxxxxx4487"&#34 ; expire_month":" 6"" EXPIRE_YEAR":" 2020""如first_name":"吉姆" "姓氏":"史密斯"" billing_address" {"第1行":" 123   Test Street"," city":" Test City"," postal_code":" XXXX   XXX"" COUNTRY_CODE":" GB"}}}]},"记录":[{"量":{& #34;总":" 13.50""货币":" GBP""细节" {"小计":" 8.33""税":" 1.67""航运":" 3.50&# 34;}},"描述":"付款   详情"," item_list":{" items":[{" name":" T-Shirt Black   小"" SKU":" ABC123""价格":" 8.33""货币" :" GBP""量":" 1"}]," shipping_address" {" RECIPIENT_NAME":& #34;吉姆   Smith"," line1":" 123 Test Street"," city":" Test City"," state&# 34;:"一些   国家"" POSTAL_CODE":" XXXX   XXX"" COUNTRY_CODE":" GB"}}," related_resources":[]}],"链接":[{ " HREF":" https://api.sandbox.paypal.com/v1/payments/payment/PAY-XXXXXXXXXXXXXXXXXXXXXX""相对":"自""方法&#34 ;: " GET"}]}

请注意我使用的是API 1.7.2版,我最近已升级到PHP版本7。

如果有人能解释我做错了什么,我会很感激。

由于

1 个答案:

答案 0 :(得分:1)

我终于成功地完成了这项工作,尽管这不是我自己的错。我的沙盒买家帐户似乎不再有效。我找到了以下文件:

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

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