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?

lnw
  • 11
  • 3

1 Answers1

0

I am including a step by step explanation that PayPal has on their developers website and the important part is that you get the "tx" value, and send it back with the PDT "Identity Token" which you can find on the PayPal account when you login to configure PDT.

The following steps illustrate the basic flow of a PDT transaction.

"A customer submits a payment. PayPal sends the transaction ID of the payment through HTTP as a GET variable (tx). This information is sent to the Return URL you specified in your PayPal account profile. Your return URL web page contains an HTML POST form that retrieves the transaction ID and sends the transaction ID and your unique PDT token to PayPal. PayPal replies with a message indicating SUCCESS or FAIL. The SUCCESS message includes transaction details, one per line, in the = format. This key-value pair string is URL encoded."

Ok, I just found this GitHub link that gives various code versions of how to get the "tx" and use it and the Identity Key to get all the name value pairs and parse them. It has an example in each language. Just click on the file name.

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

JustJohn
  • 1,362
  • 2
  • 22
  • 44