我正在尝试使用 Paypal 的退款 API。我目前正在使用沙盒帐户。付款工作正常。当我使用表单字段将数据发布到贝宝时,退款工作正常,如下所示
<form action="https://api-3t.sandbox.paypal.com/nvp" METHOD="GET">
<input type="text" name="USER" value="**********"/>
<input type="text" name="PWD" value="**********"/>
<input type="text" name="SIGNATURE" value="**********"/>
<input type="text" name="METHOD" value="RefundTransaction"/>
<input type="text" name="VERSION" value="94"/>
<input type="text" name="TRANSACTIONID" value="<?php echo $data['transaction_id']; ?>"/>
<input type="text" name="REFUNDTYPE" value="Partial"/>
<input type="text" name="AMT" value="<?php echo $amount; ?>"/>
<input type="text" name="CURRENCYCODE" value="GBP"/>
<input type="text" name="NOTE" value="refund"/>
<input type="submit" value="pay"/>
</form>
响应会自动打印在屏幕上,并显示退款成功。但我需要比较响应的 ACK 才能在退款后执行其他操作。所以我尝试使用如下 curl 。
$req = array(
'USER' => urlencode('**************'),
'PWD' => urlencode('***************'),
'SIGNATURE' => ************'),
'METHOD' => 'RefundTransaction',
'VERSION' => urlencode(119),
'TRANSACTIONID' => $data[transaction_id],
'REFUNDTYPE' => 'Partial',
'AMT' => urlencode($amount),
'CURRENCYCODE' => 'GBP',
'NOTE' => urlencode('test'),
);
$ch = curl_init('https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
if(!($res = curl_exec($ch)) ) {
error_log("Got " . curl_error($ch) . " when processing IPN data");
curl_close($ch);
exit;
}
curl_close($ch);
echo "response is : ".urldecode($res);
curl 调用成功,但响应始终是来自贝宝的内部错误 (10001)。我做错了什么。请帮忙
注意:我只是用星号替换了凭据。