我正在为paypal在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账户后,我怎样才能收到数据
为了避免重复测试,您可以使用price来测试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" />
当用户取消会员资格时,paypal将通知"notify_url"-在你的情况下,这将是文件your_listener_file.php。在这个文件中,你必须检查paypal POST变量'txn_type' = 'subscr_cancel'。这里有几个要点:
您必须验证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(); }
Second -检查数据库中是否存在使用唯一键的事务。你必须使用Paypal POST变量'custom'。
如果交易存在,只需做一些简单的检查:
if( !empty($_POST['txn_type']) && $_POST['txn_type'] == 'subscr_cancel' ) $paypalData['approved'] = 0;