0

I am having trouble with Paypal's Payflow hosted pages. I get an error message stating the Token is missing. I think my issue is the secure token id. I create a secure token id in code but I don't know how to pass this in the request to PayPal. I get a response of 0 and the token back but when I redirect to the hosted page if fails. I have searched far and wide and can't seem to find an answer to my issue. I am using the paypal guide at https://developer.paypal.com/docs/classic/payflow/gs_ppa_hosted_pages/ to work through this. Any help is greatly appreciated. Below is my code

    //Controller that gets some data from a database table and passes it to the paypal utility class
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult RedirectInstruct(PayPalModel Submit)
    {

        bool recordRetrieved = false;
        bool secureTokenRetrieved = false;
        string orderId = "A3420-789632-15115151935";
        string secureToken = "";
        string secureTokenId = "";
        string[,] InvoiceArray = new string[9, 2];

        dbConnect = new SQLDatabaseUtility(orderId);

        //Here I get some data from a database table that is used as the information passed to the inventor object
        recordRetrieved = dbConnect.QryCustOrderDetails();

        if (recordRetrieved)
        {
            InvoiceArray = dbConnect.RetrieveCustOrder();

            paymentProcessing = new PaymentProcessingUtility(InvoiceArray);

            //Here I call the method in the paypal utility class to get the secure token
            paymentProcessing.GetSecureToken();
            secureToken = paymentProcessing.PassSecureToken();
            secureTokenId = paymentProcessing.PassSecureTokenId();

            if (secureTokenRetrieved)
            {
                //Here I insert the token information into the url string and then redirect user to paypal website
                string url = "https://payflowlink.paypal.com?MODE=TEST&SECURETOKENID=" + secureTokenId + "&SECURETOKEN=" + secureToken;

                Response.Redirect(url);
            }
            else
            {
                //secure token retrieval failed
            }
    }

    //Method in the paypal utility class that creates the securitytokenid and gets the security token from paypal
    public void GetSecureToken()
    {
        decimal total = 0;
        string licenseNo = "";
        string orderID = "";
        string requestType = "";

        //set the values
        orderID = InvoiceArray[0, 1];
        total = Convert.ToDecimal(InvoiceArray[8, 1]);
        requestType = InvoiceArray[2, 1];

        //Here I create the securitytokenid
        Guid id = Guid.NewGuid();
        SECURETOKENID = Convert.ToString(id).Replace("-", "");

        // create the user object
        UserInfo User = new UserInfo("myuserid", "vender",
                                 "partner", "password");

        // Create the Payflow  Connection data object with the required connection details.
        PayflowConnectionData Connection = new PayflowConnectionData();

        // Create a new Invoice data object with the Amount, Billing Address etc. details.
        Invoice Inv = new Invoice();

        //Here I place some transaction details into the inventory object
        Currency Amt = new Currency(total, "USD");
        Inv.Amt = Amt;
        Inv.InvoiceDate = DateTime.Now.ToShortDateString();
        Inv.Comment1 = licenseNo;
        Inv.CustRef = orderID;
        Inv.OrderDesc = requestType;

        //create a new express checkout request
        ECSetRequest setRequest = new ECSetRequest(ConfigurationManager.AppSettings["ReturnURL"], ConfigurationManager.AppSettings["CancelURL"]);

        PayPalTender Tender = new PayPalTender(setRequest);

        // Create a new Auth Transaction.
        SaleTransaction Trans = new SaleTransaction(User, Connection, Inv, Tender, PayflowUtility.RequestId);

        // Submit the Transaction
        Response Resp = Trans.SubmitTransaction();

        // Display the transaction response parameters.
        if (Resp != null)
        {
            // Get the Transaction Response parameters.
            TransactionResponse TrxnResponse = Resp.TransactionResponse;
            ExpressCheckoutResponse eResponse = Resp.ExpressCheckoutSetResponse;

            if ((TrxnResponse != null) && (eResponse != null))
            {
                //get the token
                SECURETOKEN = eResponse.Token;
                //Below I have tested to see if the requestid or correlationid is the securetokenid I need...
                //SECURETOKENID = Trans.Response.RequestId;
                //SECURETOKENID = Trans.Response.TransactionResponse.CorrelationId;
            }
        }
    }

    //Here I am passing the values back to the calling class
    public string PassSecureToken()
    {
        return SECURETOKEN;
    }

    public string PassSecureTokenId()
    {
        return SECURETOKENID;
    }
Joshua
  • 108
  • 11

1 Answers1

0

You need to pass the below parameters after

// Create a new Auth Transaction.
        SaleTransaction Trans = new SaleTransaction(User, Connection, Inv, Tender, PayflowUtility.RequestId);

  Trans.CreateSecureToken = "Y";
  Trans.SecureTokenId = PayflowUtility.RequestId;

And to read the secure token you need to use below :

// Get the Transaction Response parameters.
            TransactionResponse TrxnResponse = Resp.TransactionResponse;

            TrxnResponse.SecureToken;
            TrxnResponse.SecureTokenId;
Eshan
  • 3,647
  • 1
  • 11
  • 14
  • Eshan, I have tried the above code and several variations. VS is stating there is no definition for setCreateSecurityToken or setSecurityTokenId. Am I missing something here? – Joshua Nov 09 '15 at 16:35
  • Actually I tot you are using Java and posted accordingly . I just updated my answer for VS . – Eshan Nov 09 '15 at 16:59
  • Ok, let me rephrase this. I am working with C# in Visual Studio. Neither SalesTransaction nor TransactionResponse has object names SecureToken, SecureTokenId, or CreateSecureToken. Maybe I am missing something here..? – Joshua Nov 09 '15 at 17:18
  • I used the payflow dll and was able to see those objects . I downloaded the sdk from here : http://paypal.github.io/sdk/#payflow-gateway – Eshan Nov 11 '15 at 21:53
  • After spending 4 hours on the phone with PayPal we determined that dot net does not support passing data as an object for hosted pages. I have changed the code using name value pairs in a string and got the response I needed and was successful in redirecting to the PayPal host webpage. I think that there is definitely room to get more informative information out to developers working with hosted pages and dot net. Thank you for the help Eshan. I may need to alter my post or answer my own questions for others who may be dealing with this issue as the solution was not clear. – Joshua Nov 11 '15 at 23:39