设置PayPal返回URL并使其自动返回?

cod*_*ama 126 paypal return

这是一个跟进问题:PHP:简单的方式来启动PayPal结账?

所以,我的问题是我指定了返回网址.但是,在使用PayPal付款后,我最终会在一个屏幕上显示:

您刚刚完成了付款.XXXX,您刚刚完成了付款.此付款的交易ID为:XXXXXXXXXXXXX.

我们会发送一封确认电子邮件至XX@XXXX.com.此交易将在您的对帐单上显示为PAYPAL.

Go to PayPal account overview
Run Code Online (Sandbox Code Playgroud)

我需要它不显示此屏幕并直接转到返回URL.我有:

  • 设置"返回"变量
  • 将"rm"变量设置为:2(根据指南=" 使用POST方法将买方的浏览器重定向到返回URL,并包含所有付款变量 ")

事实上,这是我的整个形式:

<form method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr">
  <input type="hidden" value="_xclick" name="cmd">
  <input type="hidden" value="onlinestore@thegreekmerchant.com" name="business">
  <!-- <input type="hidden" name="undefined_quantity" value="1" /> -->
  <input type="hidden" value="Order at The Greek Merchant:&lt;Br /&gt;Goldfish Flock BLG&lt;br /&gt;" 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>
Run Code Online (Sandbox Code Playgroud)

知道我怎么能让它自动返回?或者,如何将付款结果返回到我的网站,以便我可以更新数据库?什么是IPN?

Kev*_*ker 192

您必须在PayPal帐户中启用自动退货,否则将忽略该return字段.

从文档(更新以反映2019年1月的新布局):

默认情况下,自动返回已关闭.要启用自动返回:

  1. 通过https://www.paypal.comhttps://www.sandbox.paypal.com登录您的PayPal帐户. 将显示"我的帐户概述"页面.
  2. 单击右上角的齿轮图标.将显示"配置文件摘要"页
  3. 单击左列中的"我的销售首选项"链接.
  4. 在"在线销售"部分下,单击"网站首选项"行中的"更新"链接.将显示"网站付款首选项"页面
  5. 在"网站付款的自动退货"下,单击"打开"单选按钮以启用"自动退货".
  6. 在"返回网址"字段中,输入您希望付款人在完成付款后重定向到的网址.注意:PayPal会检查您输入的返回URL.如果URL格式不正确或无法验证,PayPal将不会激活自动返回.
  7. 滚动到页面底部,然后单击"保存"按钮.

IPN用于即时付款通知.它会为您提供比自动返回更可靠/有用的信息.

有关IPN的文档,请访问:https://www.x.com/sites/default/files/ipnguide.pdf

IPN的在线文档:https://developer.paypal.com/docs/classic/ipn/gs_IPN/

一般程序是您通过notify_url请求传递参数,并设置一个处理和验证IPN通知的页面,PayPal将向该页面发送请求,以便在付款/退款/等时通知您.经过.然后,该IPN处理程序页面将是更新数据库以将订单标记为已付款的正确位置.

  • 你是我的英雄,顺便说一下.:-) (9认同)
  • 使用Paypal的新网站布局,这已不再准确.步骤3)点击"我的销售工具"步骤4)点击"在线销售"下的"网站首选项" (5认同)
  • 哈,很高兴我能帮忙. (2认同)
  • 看看这里https://www.paypal.com/cgi-bin/webscr?cmd=p/mer/express_return_summary-outside (2认同)
  • 应该使用 IPN 来验证订单是否由 PayPal 正确处理,但是,您仍然需要返回 url 向用户显示您知道成功。很多时候用户没有收到您发送的电子邮件,因此如果他们可以立即访问产品(下载等),那就太好了。 (2认同)
  • _你必须在你的PayPal账户中启用自动退货,这是不太准确的,否则它将忽略'return`字段."_你传递给结账的任何`return` URL参数都将被尊重并覆盖任何自动返回URL(在卖家的PayPal帐户资料中配置,但如果他们没有启用自动退货,则买家需要手动点击结帐结束以便重定向到该网址,而不是自动重定向. (2认同)

小智 42

使用PHP进行直接付款的示例表单.

<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="you@youremail.com">

    <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>
Run Code Online (Sandbox Code Playgroud)

请通过字段notify_url,return,cancel_return

用于处理ipn(my_ipn.php)的示例代码,该代码是在付款后由paypal请求的.

有关创建IPN的更多信息,请参阅链接.

<?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("&", "\n", $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 .= "\n\nPaypal Verified OK";
} else {
    $req .= "\n\nData NOT verified from Paypal!";
    mail("you@youremail.com", "IPN interaction not verified", "$req", "From: you@youremail.com");
    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 != "you@youremail.com") {
//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("you@youremail.com", "NORMAL IPN RESULT YAY MONEY!", $req, "From: you@youremail.com");
?>
Run Code Online (Sandbox Code Playgroud)

下图将帮助您了解paypal过程. Paypal流程

有关进一步阅读,请参阅以下链接;

希望这可以帮助你.. :)


T.T*_*dua 23

我发现的一种方式:

尝试将此字段插入生成的表单代码中:

<input type='hidden' name='rm' value='2'>
Run Code Online (Sandbox Code Playgroud)

rm表示返回方法 ;

2表示(帖子)

用户购买并返回您的网站网址后,该网址也会获取POST参数

ps如果使用php,尝试var_dump($_POST);在你的返回URL(脚本)中插入,然后进行测试购买,当你返回到你的网站时,你会看到你的网址上有哪些变量.