【问题标题】:How to capture response from PayPal payment using PHP script?如何使用 PHP 脚本捕获来自 PayPal 支付的响应?
【发布时间】:2015-05-14 08:47:49
【问题描述】:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
        <input type="hidden" name="cmd" value="_s-xclick">
        <input type="hidden" name="hosted_button_id" value="Y43MR9C35KS88">
        <input class="btn btn-success btn-block" type="submit" value="Recharge via PayPal or Credit Card">
</form>

以上代码是从 PayPal 企业帐户生成的。这会将买家带到 PayPal 网站,在那里他可以完成付款流程。在生成代码期间,付款金额固定为 20 美元。我需要捕获付款金额和付款确认,以便更新本地数据库表以记录付款。

我该怎么做?

【问题讨论】:

    标签: php paypal response payment checkout


    【解决方案1】:

    要接收有关已完成/待处理/已取消付款的信息,您应该使用 PayPal 的即时付款通知 (IPN)。您可以在表单中添加notify_url,并附上付款流程后信息应转到的 URL。

    有关 IPN 的更多信息(包括字段): https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNIntro/

    有关可能的表单字段的更多信息 https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/

    要保存/捕获值,您需要读出相关的 $_REQUEST 或 $_GET 变量,例如
    $amount = $_REQUEST["mc_gross"];$amount = $_GET["mc_gross"];

    希望对你有帮助, 萨沙

    【讨论】:

      【解决方案2】:

      您可以将 GET 方法与来自 paypal 的响应一起使用。

      $amount = $_GET['amt']; 
      $currency = $_GET['cc'];
      $check_amount = '20.00';
      $check_currency='USD';
      
      if($amount==$check_amount && $currency==$check_currency)
      {
      // Do stuff for correct value
      }
      else
      {
      // Do stuff if failed
      }
      

      【讨论】:

        猜你喜欢
        • 2013-11-03
        • 2013-11-07
        • 2014-01-23
        • 2013-03-20
        • 2016-02-24
        • 2016-12-12
        • 2014-03-07
        • 2012-10-23
        • 1970-01-01
        相关资源
        最近更新 更多