【问题标题】:PayPal PDT works in sandbox but not livePayPal PDT 在沙盒中工作,但不是实时的
【发布时间】:2019-01-09 09:43:30
【问题描述】:

我正在尝试在我们的网站上添加一个 Paypal 付款按钮。我开启了自动退货和支付数据传输。

当我指向沙盒时,一切正常,并返回到我的网站,并带有 url 中的交易 ID。

当我指向生产 PayPal 时,没有返回任何交易 ID。付款确实通过了。

表格代码如下:

    <form action="#VARIABLES.strHostAddress#" method="post" target="_top" id="testform">
        <input type="hidden" name="cmd" value="_donations">
        <input type="hidden" name="business" value="#VARIABLES.strBusinessEmail#">
        <input type="hidden" name="item_name" value="#VARIABLES.strGiftDesignation# - #VARIABLES.strGiftDesignation2#">
        <input type="hidden" name="amount" value="#VARIABLES.intPayAmt#">
        <input type="hidden" name="first_name" value="#VARIABLES.strFirstName#">
        <input type="hidden" name="last_name" value="#VARIABLES.strLastName#">
        <input type="hidden" name="address1" value="#VARIABLES.strLine1#">
        <input type="hidden" name="address2" value="#VARIABLES.strLine2#">
        <input type="hidden" name="city" value="#VARIABLES.strCity#">
        <input type="hidden" name="state" value="#VARIABLES.strState#">
        <input type="hidden" name="zip" value="#VARIABLES.strPostalCode#">
        <input type="hidden" name="email" value="#VARIABLES.strEmail#">
        <input type="hidden" name="cancel_return" value="#VARIABLES.strCancelPage#">
        <input type="hidden" name="return" value="#VARIABLES.strThankYouPage#">
        <input type="hidden" name="rm" value="2">
    </form>

其中#VARIABLES.strHostAddress# 是“https://www.paypal.com/cgi-bin/webscr”(实时)或“https://www.sandbox.paypal.com/cgi-bin/webscr”(沙盒)。

有什么建议或想法为什么会发生这种情况?

【问题讨论】:

    标签: paypal paypal-pdt


    【解决方案1】:

    我在他们的开发者网站上包含了 PayPal 的分步说明,重要的部分是您获得“tx”值,并使用您可以在 PayPal 上找到的 PDT“身份令牌”将其发送回登录以配置 PDT 时的帐户。

    以下步骤说明了 PDT 交易的基本流程。

    “客户提交付款。 PayPal 通过 HTTP 将付款的交易 ID 作为 GET 变量 (tx) 发送。此信息将发送到您在 PayPal 帐户资料中指定的退货 URL。 您的返回 URL 网页包含一个 HTML POST 表单,该表单检索交易 ID 并将交易 ID 和您的唯一 PDT 令牌发送到 PayPal。 PayPal 回复一条指示成功或失败的消息。 SUCCESS 消息包括交易详情,每行一个,格式为 =。这个键值对字符串是 URL 编码的。"

    好的,我刚刚找到了这个 GitHub 链接,它提供了如何获取“tx”并使用它和身份密钥来获取所有名称值对并解析它们的各种代码版本。它在每种语言中都有一个示例。只需点击文件名。

    // ASP .NET C#
    
    using System;
    using System.IO;
    using System.Text;
    using System.Net;
    using System.Web;
    using System.Collections.Generic;
    
    public partial class csPDTSample : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // CUSTOMIZE THIS: This is the seller's Payment Data Transfer authorization token.
            // Replace this with the PDT token in "Website Payment Preferences" under your account.
            string authToken = "Dc7P6f0ZadXW-U1X8oxf8_vUK09EHBMD7_53IiTT-CfTpfzkN0nipFKUPYy";
            string txToken = Request.QueryString["tx"];
            string query = "cmd=_notify-synch&tx=" + txToken + "&at=" + authToken;
    
            //Post back to either sandbox or live
            string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            string strLive = "https://www.paypal.com/cgi-bin/webscr";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
    
            //Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = query.Length;
    
    
            //Send the request to PayPal and get the response
            StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            streamOut.Write(query);
            streamOut.Close();
            StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
            string strResponse = streamIn.ReadToEnd();
            streamIn.Close();
    
            Dictionary<string,string> results = new Dictionary<string,string>();
            if(strResponse != "")
            {
                StringReader reader = new StringReader(strResponse);
                string line=reader.ReadLine();
    
                if(line == "SUCCESS")
                {
    
                    while ((line = reader.ReadLine()) != null)
                    {
                        results.Add(line.Split('=')[0], line.Split('=')[1]);
    
                            }                    
                    Response.Write("<p><h3>Your order has been received.</h3></p>");
                    Response.Write("<b>Details</b><br>");
                    Response.Write("<li>Name: " + results["first_name"] + " " + results["last_name"] + "</li>");
                    Response.Write("<li>Item: " + results["item_name"] + "</li>");
                    Response.Write("<li>Amount: " + results["payment_gross"] + "</li>");
                    Response.Write("<hr>");
                }
                else if(line == "FAIL")
                {
                    // Log for manual investigation
                    Response.Write("Unable to retrive transaction detail");
                }
            }
            else
            {
                //unknown error
                Response.Write("ERROR");
            }            
        }
    }
    

    PDT-Code-Samples on GitHub

    【讨论】:

      猜你喜欢
      • 2014-06-07
      • 2015-07-11
      • 2013-08-02
      • 1970-01-01
      • 2013-12-15
      • 2012-04-09
      • 2013-07-04
      • 2012-06-25
      • 1970-01-01
      相关资源
      最近更新 更多