如何使用Payflow将securitytokenid作为对象传递?

时间:2015-11-09 15:47:50

标签: c# paypal payflowlink

我在Paypal的Payflow托管页面遇到问题。我收到一条错误消息,指出令牌丢失。我认为我的问题是安全令牌ID。我在代码中创建了一个安全的令牌ID,但我不知道如何将这个请求传递给PayPal。我收到0的响应和令牌回来但是当我重定向到托管页面时如果失败。我搜索得很远,似乎找不到我的问题的答案。我在https://developer.paypal.com/docs/classic/payflow/gs_ppa_hosted_pages/使用paypal指南 通过这个工作。任何帮助是极大的赞赏。以下是我的代码

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

1 个答案:

答案 0 :(得分:0)

您需要在

之后传递以下参数
// Create a new Auth Transaction.
        SaleTransaction Trans = new SaleTransaction(User, Connection, Inv, Tender, PayflowUtility.RequestId);

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

要阅读下面需要使用的安全令牌:

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

            TrxnResponse.SecureToken;
            TrxnResponse.SecureTokenId;