paypal nvp api(退款)通过表单使用但不使用 curl 时工作
payapl nvp api (refund) working when using via a form but not working with curl
我正在尝试使用 Paypal 退款 API。我目前正在使用沙盒帐户。付款工作正常。当我使用表单字段 post 数据到 paypal 时,退款工作正常
<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 调用成功,但响应始终是来自 paypal 的内部错误 (10001)。我做错了什么。请帮忙
注意:我只是用星号替换了凭据。
我认为您不需要对 AMT 值进行 urlencode。它应该作为格式正确的十进制发送。另外,版本号也不用urlencode,据我所知目前最高版本是95,不是119
我正在尝试使用 Paypal 退款 API。我目前正在使用沙盒帐户。付款工作正常。当我使用表单字段 post 数据到 paypal 时,退款工作正常
<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 调用成功,但响应始终是来自 paypal 的内部错误 (10001)。我做错了什么。请帮忙
注意:我只是用星号替换了凭据。
我认为您不需要对 AMT 值进行 urlencode。它应该作为格式正确的十进制发送。另外,版本号也不用urlencode,据我所知目前最高版本是95,不是119