1

I am trying to add a Paypal Payments button onto our website. I have Auto Return and Payment Data Transfer turned on.

When I point to sandbox, everything works correctly and it returns to my website with the transaction id in the url.

When I point to production PayPal, no transaction id is returned. Payment does go through.

Here is the form code:

    <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>

where #VARIABLES.strHostAddress# is "https://www.paypal.com/cgi-bin/webscr" for live or "https://www.sandbox.paypal.com/cgi-bin/webscr" for sandbox.

Any suggestions or idea why this would happen?

4

1 回答 1

0

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

以下步骤说明了 PDT 事务的基本流程。

“客户提交付款。PayPal 通过 HTTP 作为 GET 变量 (tx) 发送付款的交易 ID。此信息将发送到您在 PayPal 帐户配置文件中指定的返回 URL。您的返回 URL 网页包含 HTML POST检索交易 ID 并将交易 ID 和您的唯一 PDT 令牌发送到 PayPal 的表单。PayPal 回复一条指示 SUCCESS 或 FAIL 的消息。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");
        }            
    }
}

GitHub 上的 PDT 代码示例

于 2019-11-13T23:47:26.317 回答