asp.net - Paypal 自适应支付返回 url 被调用两次

标签 asp.net paypal payment-gateway paypal-adaptive-payments

我已经实现了 paypal 自适应支付方式并使用了网络流程。 付款后,当我明确点击返回按钮时,返回 url 会调用两次,但如果我等待自动重定向,则它只会调用一次。

我不明白为什么 return url 调用了两次。

请指教。

我正在使用下面的代码。

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

最佳答案

@jitendra,我遇到了同样的问题,发现 paypal 使用服务器端脚本,一段时间后将用户重定向到返回 url,当我们明确点击返回按钮时,paypal 服务器脚本再次点击自己返回 url,因此我们在返回 url 上得到两个响应/点击。

我们可以通过检查/维护我们在 paypal 上付款后收到的回复数量来解决这个问题。

我们可以在客户端使用 cookie 或在服务器上使用 session 或其他类似的东西来维护它。

希望这对您有所帮助。

关于asp.net - Paypal 自适应支付返回 url 被调用两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16337604/

相关文章:

php - 如何使用PHP获取返回页面上的paypal买家地址

android - "PayU"Android 集成中的 INVALID_USER_CREDENTIALS/JSON_EXCEPTION

通过存储用户凭据在 php 中集成 Paypal

asp.net - Facebook 开发者 : making a permission optional

javascript - DataTables 未捕获类型错误 : Cannot set property '0' of undefined

node.js - NODE JS - 在建立安全 TLS 连接之前客户端网络套接字断开连接

Paypal IPN vs PDT vs REST API app webhooks vs NVP/SOAP API webhooks

php - 提前整合ccavenue

asp.net - 为什么asp.net中只有特定的控件继承自IPostBackDataHandler接口(interface)

javascript - ASP.NET MVC 验证不适用于 Bootstrap 模式