Setting PayPal return URL and making it auto return?
这是一个后续问题:PHP:开始PayPal结帐的简便方法?
所以,我的问题是我要指定返回网址。 但是,在使用PayPal付款后,我看到的屏幕上显示:
You just completed your payment. XXXX, you just completed your payment.
Your transaction ID for this payment is: XXXXXXXXXXXXX.We'll send a confirmation email to [email protected]. This transaction will appear on your statement as PAYPAL.
1 Go to PayPal account overview
我需要它不显示此屏幕,而是直接转到返回URL。 我有:
- 设置"返回"变量
- 将" rm"变量设置为:2(根据指南="使用POST方法将买方的浏览器重定向到返回URL,并且包括所有付款变量")
实际上,这是我的整个表格:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <form method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr"> <input type="hidden" value="_xclick" name="cmd"> <input type="hidden" value="[email protected]" name="business"> <!-- <input type="hidden" name="undefined_quantity" value="1" /> --> <input type="hidden" value="Order at The Greek Merchant:<Br />Goldfish Flock BLG<br />" name="item_name"> <input type="hidden" value="NA" name="item_number"> <input type="hidden" value="22.16" name="amount"> <input type="hidden" value="5.17" name="shipping"> <input type="hidden" value="0" name="discount_amount"> <input type="hidden" value="0" name="no_shipping"> <input type="hidden" value="No comments" name="cn"> <input type="hidden" value="USD" name="currency_code"> <input type="hidden" value="http://XXX/XXX/XXX/paypal/return" name="return"> <input type="hidden" value="2" name="rm"> <input type="hidden" value="11255XXX" name="invoice"> <input type="hidden" value="US" name="lc"> <input type="hidden" value="PP-BuyNowBF" name="bn"> <input type="submit" value="Place Order!" name="finalizeOrder" id="finalizeOrder" class="submitButton"> </form> |
知道如何使它自动返回吗? 另外,如何将付款结果返回到我的网站,以便更新数据库? 什么是IPN?
您必须在PayPal帐户中启用自动返回功能,否则它将忽略
从文档中(已更新以反映新的版式2019年1月):
Auto Return is turned off by default.
To turn on Auto Return:Log in to your PayPal account at https://www.paypal.com or https://www.sandbox.paypal.com
The My Account Overview page appears.Click the gear icon top right.
The Profile Summary page appears.Click the My Selling Preferences link in the left column. Under the Selling Online section, click the Update link in the row for Website Preferences.
The Website Payment Preferences page appearsUnder Auto Return for Website Payments, click the On radio button to enable Auto
Return.In the Return URL field, enter the URL to which you want your payers redirected after
they complete their payments.
NOTE: PayPal checks the Return URL that you enter. If the URL is not properly formatted
or cannot be validated, PayPal will not activate Auto Return.Scroll to the bottom of the page, and click the Save button.
IPN用于即时付款通知。与自动返回相比,它将为您提供更多可靠/有用的信息。
IPN的文档位于:https://www.x.com/sites/default/files/ipnguide.pdf
IPN的在线文档:https://developer.paypal.com/docs/classic/ipn/gs_IPN/
一般过程是,您在请求中传递一个
使用PHP直接付款的示例表格。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="[email protected]"> <input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '"> <input type="hidden" name="amount_' . $x . '" value="' . $price . '"> <input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '"> <input type="hidden" name="custom" value="' . $product_id_array . '"> <input type="hidden" name="notify_url" value="https://www.yoursite.com/my_ipn.php"> <input type="hidden" name="return" value="https://www.yoursite.com/checkout_complete.php"> <input type="hidden" name="rm" value="2"> <input type="hidden" name="cbt" value="Return to The Store"> <input type="hidden" name="cancel_return" value="https://www.yoursite.com/paypal_cancel.php"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="currency_code" value="USD"> <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!"> </form> |
请通过字段notify_url,return,cancel_return
付款后,贝宝要求处理ipn的示例代码(my_ipn.php)。
有关创建IPN的更多信息,请参考此链接。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | <?php // Check to see there are posted variables coming into the script if ($_SERVER['REQUEST_METHOD'] !="POST") die("No Post Variables"); // Initialize the $req variable and add CMD key value pair $req = 'cmd=_notify-validate'; // Read the post from PayPal foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .="&$key=$value"; } // Now Post all of that back to PayPal's server using curl, and validate everything with PayPal // We will use CURL instead of PHP for this for a more universally operable script (fsockopen has issues on some environments) //$url ="https://www.sandbox.paypal.com/cgi-bin/webscr"; $url ="https://www.paypal.com/cgi-bin/webscr"; $curl_result = $curl_err = ''; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $req); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded","Content-Length:" . strlen($req))); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $curl_result = @curl_exec($ch); $curl_err = curl_error($ch); curl_close($ch); $req = str_replace("&"," ", $req); // Make it a nice list in case we want to email it to ourselves for reporting // Check that the result verifies if (strpos($curl_result,"VERIFIED") !== false) { $req .=" Paypal Verified OK"; } else { $req .=" Data NOT verified from Paypal!"; mail("[email protected]","IPN interaction not verified","$req","From: [email protected]"); exit(); } /* CHECK THESE 4 THINGS BEFORE PROCESSING THE TRANSACTION, HANDLE THEM AS YOU WISH 1. Make sure that business email returned is your business email 2. Make sure that the transaction?s payment status is ?completed? 3. Make sure there are no duplicate txn_id 4. Make sure the payment amount matches what you charge for items. (Defeat Price-Jacking) */ // Check Number 1 ------------------------------------------------------------------------------------------------------------ $receiver_email = $_POST['receiver_email']; if ($receiver_email !="[email protected]") { //handle the wrong business url exit(); // exit script } // Check number 2 ------------------------------------------------------------------------------------------------------------ if ($_POST['payment_status'] !="Completed") { // Handle how you think you should if a payment is not complete yet, a few scenarios can cause a transaction to be incomplete } // Check number 3 ------------------------------------------------------------------------------------------------------------ $this_txn = $_POST['txn_id']; //check for duplicate txn_ids in the database // Check number 4 ------------------------------------------------------------------------------------------------------------ $product_id_string = $_POST['custom']; $product_id_string = rtrim($product_id_string,","); // remove last comma // Explode the string, make it an array, then query all the prices out, add them up, and make sure they match the payment_gross amount // END ALL SECURITY CHECKS NOW IN THE DATABASE IT GOES ------------------------------------ //////////////////////////////////////////////////// // Homework - Examples of assigning local variables from the POST variables $txn_id = $_POST['txn_id']; $payer_email = $_POST['payer_email']; $custom = $_POST['custom']; // Place the transaction into the database // Mail yourself the details mail("[email protected]","NORMAL IPN RESULT YAY MONEY!", $req,"From: [email protected]"); ?> |
下图将帮助您了解Paypal流程。
要进一步阅读,请参考以下链接;
- https://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/howto_checkout-outside
- https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_html变量
希望这对您有帮助.. :)
我发现的一种方式:
尝试将此字段插入生成的表单代码中:
1 | <input type='hidden' name='rm' value='2'> |
rm表示返回方法;
2表示(发布)
在用户购买并返回到您的网站网址之后,该网址也将获得POST参数
ps。如果使用php,请尝试在返回网址(script)中插入
分享,因为我最近遇到了与此线程类似的问题
长期以来,我的脚本运行良好(基本付款形式),并将POST变量返回到我的success.php页面,并将IPN数据也返回为POST变量。但是,最近,我注意到返回页面(success.php)不再接收任何POST变量。我已经在Sandbox上进行了测试并投入使用,而且我很确定PayPal有所改变!
notify_url仍接收正确的IPN数据,允许我更新数据库,但是我无法在返回URL(success.php)页面上显示成功消息。
尽管尝试了多种组合来打开和关闭PayPal网站付款首选项和IPN中的选项,但是我必须对脚本进行一些更改以确保我仍然可以处理消息。在遵循了这份出色的指南之后,我通过打开PDT和自动返回来完成此操作。
现在一切正常,但是唯一的问题是返回URL包含所有PDT变量,这很丑陋!
您可能还会发现这很有帮助
我认为,Kevin所述设置自动返回值的想法有点奇怪!
举例来说,假设您有多个网站使用相同的PayPal帐户来处理付款,或者说您在一个网站中有多个部分执行不同的购买任务,并且在付款时需要使用不同的退货地址完成了。如果如上所述,在"使用PHP进行直接付款的示例表单"部分中所述的页面上放置一个按钮,您会看到那里有一行:
1 | input type="hidden" name="return" value="https://www.yoursite.com/checkout_complete.php" |
您可以在其中设置单个返回值。为什么还必须在配置文件部分中进行一般设置?!?!
另外,由于您只能在"配置文件"部分中设置一个值,因此(AFAIK)表示您不能在具有多项操作的网站上使用"自动返回"。
请发表评论?
在结帐页面上,查找" cancel_return"隐藏的表单元素:
将cancel_return表单元素的值设置为您希望返回的URL: