繁体   English   中英

每月在Paypal中使用php进行定期付款

[英]Recurring payment in paypal every month in php

我正在为php中的贝宝进行定期付款。 我已经看到了一些示例,下面的代码对我来说似乎很容易理解。

    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="info@capleswebdev.com">
<!-- Specify a Subscribe button. -->
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<!-- Identify the subscription. -->
<input type="hidden" name="item_name" value="Alice's Weekly Digest">
<input type="hidden" name="item_number" value="DIG Weekly">
<!-- Set the terms of the regular subscription. -->
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="5.00">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<!-- Display the payment button. -->
<input type="image" name="submit" border="0" src="https://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypal.com/en_US/i/scr/pixel.gif" >
</form> 

根据上面的代码,它将每月收取5美元。 我真的不知道该代码是否有效。 我也想知道,在上面的代码中,Paypal API用户名,密码和秘密密钥没有选项,只有通过Paypal注册的电子邮件ID才能完成业务。正确地做。 请为我提供一些建议,以及在用户取消或成功将钱支付到我的Paypal帐户后如何接收数据

为了避免重复测试,您可以使用价格(例如0,01)进行测试。 要创建定期付款,请使用以下HTML表单:

<form method="post" name="formName" id="submitThisForm" action="https://www.paypal.com/cgi-bin/webscr" >
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="your@papypamail.com" />
<input type="hidden" name="item_name" value="Your Membership" />
<input type="hidden" name="a3" value="0.01">
<input type="hidden" name="p3" value="1"> 
<input type="hidden" name="t3" value="M">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="hidden" name="item_number" value="2" />
<input type="hidden" name="custom" value="SECURITYCODE" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="quantity" value="1" />
<input type="hidden" name="no_shipping" value="1" />
<input type="hidden" name="return" value="page going after payment" />
<input type="hidden" name="cancel_return" value="" />
<input type="hidden" name="cbt" value="ITEM DESCRIPTION" />
<input type="hidden" name="rm" value="2" />
<input type="hidden" name="notify_url" value="your_listener_file.php" />

当用户取消会员资格后,贝宝将在“ notify_url”上进行通知-在您的情况下,该文件将为your_listener_file.php。 在此文件中,您必须检查paypal POST变量'txn_type'='subscr_cancel'。 有几个要点:

  1. 您必须验证ipn事务:

      $post = array( 'cmd' => '_notify-validate' ); foreach($_POST as $key=>$value){ $post[$key] = $value; } $c = curl_init(); curl_setopt_array($c, array( CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_CONNECTTIMEOUT => 15, CURLOPT_MAXREDIRS => 15, CURLOPT_TIMEOUT => 15, CURLOPT_URL => 'https://www.paypal.com/cgi-bin/webscr', CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post, )); $res = curl_exec($c); curl_close($c); $res = trim($res); if( $res != 'VERIFIED' ) { exit(); } 
  2. 其次-使用唯一键检查数据库中是否存在事务。 您必须使用Paypal POST变量“ custom”。

  3. 如果该事务存在,则进行一些简单的检查:

     if( !empty($_POST['txn_type']) && $_POST['txn_type'] == 'subscr_cancel' ) $paypalData['approved'] = 0; 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM