Paypal responsive payment returns URL twice

I implemented PayPal adaptive payment method and used web stream. After making the payment, when I explicitly press the return button, the returned URL calls twice, but if I wait for the automatic redirection, it calls only once.

I cannot understand why return url calls twice.

Please advice.

I am using the code below.

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 } }; } 
+6
source share
1 answer

@jitendra, I had the same problem, and it turned out that paypal uses the server side of the script, which redirects the user to the returned url after a while, and when I explicitly press the return button, then the PayPal script again accesses the returned URL on its own so we get two responses / hits at our return url.

We can deal with this by checking / maintaining the lack of responses that we receive after payments are made on paypal.

We can support this with cookies on the client side or on the server, using sessions or something like that.

Hope this helps.

+2
source

Source: https://habr.com/ru/post/944115/


All Articles