PayPal自适应支付返回URL被调用两次。

8
我已实现了PayPal的自适应支付方法并使用Web流程。 当我进行付款后,当我明确点击返回按钮时,返回网址会调用两次,但如果等待自动重定向,则仅调用一次。
我不理解为什么返回网址会调用两次。
请给予建议。
我正在使用以下代码。
public static ActionOutput MakeTransactionUsingPaypal(PaymentDetails payment, ShopCart shop_cart)
{
    ReceiverList receiverList = new ReceiverList();
    receiverList.receiver = new List<Receiver>();
    string action_type = "PAY_PRIMARY";
    decimal amnt_to_admin = ((shop_cart.TotalAmountToBePaid * 10) / 100);

    /*Total Amount to Admin Account */
    Receiver rec1 = new Receiver(shop_cart.TotalAmountToBePaid);
    rec1.email = Config.AdminPaypalBusinessAccount;
    rec1.primary = true;

    /*Amount after deducting to Admin Commision to Seller */
    Receiver rec2 = new Receiver(Math.Round((shop_cart.TotalAmountToBePaid - amnt_to_admin), 2, MidpointRounding.ToEven));
    rec2.email = payment.PaypalEmail; // "anuj_merchant@xicom.biz";

    receiverList.receiver.Add(rec1);
    receiverList.receiver.Add(rec2);
    PayRequest req = new PayRequest(new RequestEnvelope("en_US"), action_type, Config.PaypalCancelURL, "USD", receiverList, Config.PaypalReturnURL);

    // All set. Fire the request            
    AdaptivePaymentsService service = new AdaptivePaymentsService();

    PayResponse resp = null;
    //TransactionDetail details = new TransactionDetail();

    resp = service.Pay(req);
    String PayKey = resp.payKey;
    String PaymentStatus = resp.paymentExecStatus;
    ResponseEnvelope ResponseEnvelope = resp.responseEnvelope;
    PayErrorList errorList = resp.payErrorList;
    List<ErrorData> errorData = resp.error;
    if (errorData.Count > 0)
    {
        return new ActionOutput
        {
            Status = ActionStatus.Error,
            Message = errorData[0].message
        };
    }
    FundingPlan defaultFundingPlan = resp.defaultFundingPlan;
    WarningDataList warningDataList = resp.warningDataList;
    string redirectUrl = null;
    if (!(resp.responseEnvelope.ack == AckCode.FAILURE) &&
        !(resp.responseEnvelope.ack == AckCode.FAILUREWITHWARNING))
    {
        redirectUrl = ConfigurationManager.AppSettings["PAYPAL_REDIRECT_URL"] + "_ap-payment&paykey=" + resp.payKey;

    }
    return new ActionOutput
    {
        Status = ActionStatus.Successfull,
        Message = "Redirecting to paypal...",
        Results = new List<string> { redirectUrl, resp.payKey }
    };
}

1
我可以验证这个。我的特定设置是Ruby 1.9.3/Rails 3.2.13,并使用'paypal-sdk-adaptivepayments' gem。 - Dale Campbell
@Oshuma:你有找到解决方案了吗?还是这是PayPal的一个bug? - Jitendra Pancholi
1个回答

3
@jitendra,我曾遇到同样的问题,并发现PayPal使用了一个服务器端脚本,一段时间后将用户重定向到返回URL,当我们显式点击“返回”按钮时,PayPal服务器脚本会再次自动访问返回URL,因此我们会收到两个响应/访问返回URL。
我们可以通过检查/维护在PayPal支付后接收到的响应数量来解决这个问题。
我们可以使用客户端的cookie或服务器上的session或类似的其他内容来维护它。
希望这能帮助您。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接