【问题标题】:302 url redirect to paypal home page302 url重定向到paypal主页
【发布时间】:2017-05-29 23:22:40
【问题描述】:

我们使用 PayPal AdaptivePayments SDK 已有一段时间了,

现在,50% 的时间使用 302 临时重定向将客户重定向到贝宝主页。

https://www.paypal.com/webscr&cmd=_ap-payment&paykey=XXXXXXXXXX.

代码主要是从贝宝示例中复制过去

public override string CreateRedirectUrl(NameValueCollection parameters)
{

    ReceiverList receiverList = new ReceiverList();
    receiverList.receiver = new List<Receiver>();

    PayRequest request = new PayRequest();
    RequestEnvelope requestEnvelope = new RequestEnvelope("en_CA");
    request.requestEnvelope = requestEnvelope;
    request.feesPayer = "PRIMARYRECEIVER";
    //request.feesPayer = "SECONDARYONLY";

    Receiver receiver1 = new Receiver();

    if (parameters["amount1"] != null && parameters["amount1"].Trim() != string.Empty)
    {
        // Required) Amount to be paid to the receiver
        receiver1.amount = Convert.ToDecimal(parameters["amount1"].ToString(), CultureInfo.InvariantCulture);
    }

    if (parameters["mail1"] != null && parameters["mail1"].Trim() != string.Empty)
    {
        // Receiver's email address. This address can be unregistered with
        // paypal.com. If so, a receiver cannot claim the payment until a PayPal
        // account is linked to the email address. The PayRequest must pass
        // either an email address or a phone number. Maximum length: 127 characters
        receiver1.email = parameters["mail1"];
    }

    //if (parameters["primaryReceiver1"] != null && parameters["primaryReceiver1"].Trim() != string.Empty)
    //{
    //    receiver1.primary = Convert.ToBoolean(parameters["primaryReceiver1"]);
    //}

    receiver1.primary = true;
    receiver1.invoiceId = parameters["invoiceId"];

    receiverList.receiver.Add(receiver1);

    Receiver receiver2 = new Receiver();

    if (parameters["amount2"] != null && parameters["amount2"].Trim() != string.Empty)
    {
        // (Required) Amount to be paid to the receiver
        receiver2.amount = Convert.ToDecimal(parameters["amount2"], CultureInfo.InvariantCulture);
    }

    if (parameters["mail2"] != null && parameters["mail2"].Trim() != string.Empty)
    {
        // Receiver's email address. This address can be unregistered with
        // paypal.com. If so, a receiver cannot claim the payment until a PayPal
        // account is linked to the email address. The PayRequest must pass
        // either an email address or a phone number. Maximum length: 127 characters
        receiver2.email = parameters["mail2"];
    }

    //if (parameters["primaryReceiver2"] != null && parameters["primaryReceiver2"].Trim() != string.Empty)
    //{
    //    receiver2.primary = Convert.ToBoolean(parameters["primaryReceiver2"]);
    //}

    receiverList.receiver.Add(receiver2);

    ReceiverList receiverlst = new ReceiverList(receiverList.receiver);
    request.receiverList = receiverlst;

    // (Optional) Sender's email address. Maximum length: 127 characters
    if (parameters["senderEmail"] != null && parameters["senderEmail"].Trim() != string.Empty)
    {
        request.senderEmail = parameters["senderEmail"];
    }

    // The action for this request. Possible values are: PAY – Use this
    // option if you are not using the Pay request in combination with
    // ExecutePayment. CREATE – Use this option to set up the payment
    // instructions with SetPaymentOptions and then execute the payment at a
    // later time with the ExecutePayment. PAY_PRIMARY – For chained
    // payments only, specify this value to delay payments to the secondary
    // receivers; only the payment to the primary receiver is processed.
    //if (parameters["actionType"] != null && parameters["actionType"].Trim() != string.Empty)
    //{
    //    request.actionType = parameters["actionType"];
    //}
    request.actionType = "PAY";

    // URL to redirect the sender's browser to after canceling the approval
    // for a payment; it is always required but only used for payments that
    // require approval (explicit payments)
    if (parameters["cancelURL"] != null && parameters["cancelURL"].Trim() != string.Empty)
    {
        request.cancelUrl = parameters["cancelURL"];
    }

    // The code for the currency in which the payment is made; you can
    // specify only one currency, regardless of the number of receivers
    if (parameters["currencyCode"] != null && parameters["currencyCode"].Trim() != string.Empty)
    {
        request.currencyCode = parameters["currencyCode"];
    }

    // URL to redirect the sender's browser to after the sender has logged
    // into PayPal and approved a payment; it is always required but only
    // used if a payment requires explicit approval
    if (parameters["returnURL"] != null && parameters["returnURL"].Trim() != string.Empty)
    {
        request.returnUrl = parameters["returnURL"];
    }

    request.requestEnvelope = requestEnvelope;

    // (Optional) The URL to which you want all IPN messages for this
    // payment to be sent. Maximum length: 1024 characters
    if (parameters["ipnNotificationURL"] != null && parameters["ipnNotificationURL"].Trim() != string.Empty)
    {
        request.ipnNotificationUrl = parameters["ipnNotificationURL"];
    }

    AdaptivePaymentsService service = null;

    try
    {
        // Configuration map containing signature credentials and other required configuration.
        // For a full list of configuration parameters refer in wiki page
        // (https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters)
        Dictionary<string, string> configurationMap = PaypalAdaptiveConfiguration.GetAcctAndConfig();

        // Creating service wrapper object to make an API call and loading
        // configuration map for your credentials and endpoint
        service = new AdaptivePaymentsService(configurationMap);

        Response = service.Pay(request);
    }
    catch (System.Exception ex)
    {
       // contextHttp.Response.Write(ex.Message);
        //return;
    }

    Dictionary<string, string> responseValues = new Dictionary<string, string>();
    string redirectUrl = null;

    if (!Response.responseEnvelope.ack.ToString().Trim().ToUpper().Equals(AckCode.FAILURE.ToString()) && !Response.responseEnvelope.ack.ToString().Trim().ToUpper().Equals(AckCode.FAILUREWITHWARNING.ToString()))
    {
        if (ConfigurationManager.AppSettings["PAYPAL_MODE"].ToLower() == "live")
        {
            redirectUrl = ConfigurationManager.AppSettings["PAYPAL_REDIRECT_URL_LIVE"] + "_ap-payment&paykey=" + Response.payKey;
        }
        else
        {
            redirectUrl = ConfigurationManager.AppSettings["PAYPAL_REDIRECT_URL"] + "_ap-payment&paykey=" + Response.payKey;
        }
        // The pay key, which is a token you use in other Adaptive Payment APIs 
        // (such as the Refund Method) to identify this payment. 
        // The pay key is valid for 3 hours; the payment must be approved while the 
        // pay key is valid. 
        responseValues.Add("Pay Key", Response.payKey);

        // The status of the payment. Possible values are:
        // CREATED – The payment request was received; funds will be transferred once the payment is approved
        // COMPLETED – The payment was successful
        // INCOMPLETE – Some transfers succeeded and some failed for a parallel payment or, for a delayed chained payment, secondary receivers have not been paid
        // ERROR – The payment failed and all attempted transfers failed or all completed transfers were successfully reversed
        // REVERSALERROR – One or more transfers failed when attempting to reverse a payment
        // PROCESSING – The payment is in progress
        // PENDING – The payment is awaiting processing
        responseValues.Add("Payment Execution Status", Response.paymentExecStatus);

        if (Response.defaultFundingPlan != null && Response.defaultFundingPlan.senderFees != null)
        {
            // Fees to be paid by the sender
            responseValues.Add("Sender Fees", Response.defaultFundingPlan.senderFees.amount + Response.defaultFundingPlan.senderFees.code);
        }
    }

    foreach (ErrorData ed in Response.error)
    {
        this.ErrorMessage += ed.message + " ";
    }
    if (!string.IsNullOrWhiteSpace(this.ErrorMessage))
    {
        new Tracker().sendToGenclikDev("PaypalAdaptiveGateway", this.ErrorMessage);
    }

    responseValues.Add("Acknowledgement", Response.responseEnvelope.ack.ToString().Trim().ToUpper());

        return redirectUrl;
}

【问题讨论】:

    标签: paypal paypal-adaptive-payments


    【解决方案1】:

    自 2017 年 1 月 13 日星期五以来,我们遇到了完全相同的问题。它似乎主要发生在第一次付款重定向请求上。如果您从 Paypal 主屏幕返回,使用浏览器的后退按钮并使用新令牌再次发布,它可以工作。

    任何知道解决方案的人都会有很大帮助!

    【讨论】:

    • 这里是来自 paypal 的答案:我们的工程师仍在调查这个问题。我会尽快为您提供更新。谢谢你,祝你有美好的一天!
    • 您有指向 paypal 上未决问题的链接吗?我们如何跟进?谢谢
    【解决方案2】:

    我们也遇到了同样的问题,但通过做一个小改动就能解决。

    您需要更改重定向网址:

    来自: https://www.paypal.com/webscr&cmd=_ap-payment&paykey=XXXXXXXXXX

    收件人: https://www.paypal.com/webscr?cmd=_ap-payment&paykey=XXXXXXXXXX

    注意“webscr”后面的“?”。

    【讨论】:

      猜你喜欢
      • 2012-06-29
      • 2013-08-17
      • 1970-01-01
      • 2020-07-24
      • 1970-01-01
      • 1970-01-01
      • 2017-01-29
      • 2015-10-01
      • 2014-10-25
      相关资源
      最近更新 更多