【问题标题】:How to pass the securitytokenid as an object with Payflow?如何使用 Payflow 将 securitytokenid 作为对象传递?
【发布时间】:2015-11-09 15:47:49
【问题描述】:

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

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

【问题讨论】:

    标签: c# paypal payflowlink


    【解决方案1】:

    后面需要传入以下参数

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

    【讨论】:

    • Eshan,我已经尝试了上面的代码和几个变体。 VS 声明 setCreateSecurityToken 或 setSecurityTokenId 没有定义。我在这里错过了什么吗?
    • 实际上我知道您正在使用 Java 并相应地发布。我刚刚更新了 VS 的答案。
    • 好的,让我重新表述一下。我在 Visual Studio 中使用 C#。 SalesTransaction 和 TransactionResponse 都没有对象名称 SecureToken、SecureTokenId 或 CreateSecureToken。也许我在这里遗漏了一些东西..?
    • 我使用了 payflow dll 并且能够看到这些对象。我从这里下载了 sdk:paypal.github.io/sdk/#payflow-gateway
    • 在手机上使用 PayPal 花了 4 个小时后,我们确定 dot net 不支持将数据作为托管页面的对象传递。我已经使用字符串中的名称值对更改了代码,并获得了我需要的响应,并成功重定向到 PayPal 主机网页。我认为肯定有空间向使用托管页面和点网的开发人员提供更多信息。谢谢峨山的帮助。由于解决方案不明确,我可能需要更改我的帖子或为可能正在处理此问题的其他人回答我自己的问题。
    猜你喜欢
    • 2012-06-09
    • 2016-12-07
    • 2021-11-22
    • 2019-10-19
    • 1970-01-01
    • 2015-12-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    相关资源
    最近更新 更多