如何使用txn_id阻止paypal重复付款?

时间:2017-05-22 19:28:40

标签: php curl paypal

所以我使用PHP cURL和PayPal IPN。

我不希望我的客户误付两次。我听说我可以使用txn_id做到这一点,但我不知道如何。

这是我的代码......

<?php

// connecting to database

// Prepare the URL to send via cURL
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
    $get_magic_quotes_exists = true;
}
foreach ($_POST as $key => $value) {
    if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
        $value = urlencode(stripslashes($value));
    } else {
        $value = urlencode($value);
    }
    $req .= "&$key=$value";
}

// Initial cURL
$ch = curl_init();

// Set opt
curl_setopt($ch, CURLOPT_URL,"https://www.paypal.com/cgi-bin/webscr");
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);

// Return result
$result = curl_exec($ch);

// Close cURL connection
curl_close($ch);



// If condition
if($result == "VERIFIED"){

    // perform database update

}
?>

如何阻止买家多付一次?

1 个答案:

答案 0 :(得分:0)

您在此处提供的代码适用于PayPal IPN,我认为这对于避免重复付款几乎没有帮助。相反,我建议您在付款数据中添加发票。由于PayPal系统默认使用相同的发票ID阻止付款,我希望这可以帮助您避免客户误付两次。

如果您要整合PayPal付款标准,请在下面的页面查看变量列表。

https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/

如果您正在整合PayPal Express Checkout,请查看以下页面。

https://developer.paypal.com/docs/classic/api/merchant/SetExpressCheckout_API_Operation_NVP/ https://developer.paypal.com/docs/classic/api/merchant/DoExpressCheckoutPayment_API_Operation_NVP/

相关问题