我只是试图用PayPal链式支付进行测试,这真的令人沮丧。我的测试目标是将主要接收器发送给15美元,然后将1美元发送给辅助接收器。这是我的代码:
$api = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay";
$input = array(
"actionType" => "PAY",
"currencyCode" => "USD",
"feesPayer" => "EACHRECEIVER",
"cancelUrl" => "https://www.google.com", //test url
"returnUrl" => "https://www.google.com", //test url
"receiverList" => array(
"receiver" => array( //send primary receiver $15
"amount" => "15.00",
"email" => "rbxseller1@gmail.com",
"primary" => true
),
"receiver" => array( //send owner of site $1 commission
"amount" => "1.00",
"email" => "rbxowner@gmail.com",
"primary" => false
)
),
"requestEnvelope" => array(
"errorLanguage" => "en_US"
)
);
$headers = array(
"X-PAYPAL-SECURITY-USERID: ".USER_ID, //predefined
"X-PAYPAL-SECURITY-PASSWORD: ".USER_PASS, //predefined
"X-PAYPAL-SECURITY-SIGNATURE: ".USER_SIG, //predefined
"X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
"X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T"
);
$ch = curl_init($api);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($input));
$response = curl_exec($ch);
var_dump($response);
当我尝试这样做时,它可以工作,但在我的付款细节中,它只向次级接收器显示$ 1,没有主接收器的踪迹:
{" paymentInfo":[{"接收机" {"量":" 1.00""电子邮件&# 34;:" rbxowner@gmail.com","主":"假"" paymentType":" SERVICE&#34 ;,"帐户ID":" 6LBSVJQNVE9DA"}" pendingRefund":"假"}]}
我尝试设置" actionType"到" PAY_PRIMARY"它给了我这个错误:
" message":"无效的请求参数:操作类型PAY_PRIMARY只能用于链式付款","参数":[" PAY_PRIMARY&# 34]
我在youtube,stackoverflow,一些论坛网站等上查找它并且找不到很多有用的信息,这让我非常沮丧。
非常感谢任何花时间阅读并帮助我的人!
答案 0 :(得分:0)
你的错误在于PHP数组语法:
"receiverList" => array(
"receiver" => array(/*primary receiver info*/),
"receiver" => array(/*secondary receiver info*/)
),
关联数组每个键只能有一个值(想象一下为什么,想象一下从这样声明的数组中访问$receiverList['receiver']
;它不知道你想要的是什么。)
对于PHP,这与编写$foo = 1; $foo = 2;
并期望1和2仍然在某处“存在”相同。所有被发送到Paypal的是:
"receiverList" => array(
"receiver" => array(/*secondary receiver info*/)
),
如果你回复json_encode($input)
,你可以自己看看。
我不知道数组应该是什么样子,但绝对不是那样的。我没有看到文档的最佳猜测是一个没有指定密钥的简单列表:
"receiverList" => array(
array(/*primary receiver info*/),
array(/*secondary receiver info*/)
),
或者可能需要"recevier"
密钥,并且这两个条目位于:
"receiverList" => array(
"receiver" => array(
array(/*primary receiver info*/),
array(/*secondary receiver info*/)
)
),
或者你可能误读了文档并且没有“receiverList”键,只有“receiver”:
"receiver" => array(
array(/*primary receiver info*/),
array(/*secondary receiver info*/)
),
无论哪种变体,在你理解这一点之前都没有必要改变你的查询的其余部分,因为现在你只是向Paypal发送了一组接收者细节。