Search code examples
c#paypalchained-payments

How to Use PaymentAction in paypal adaptive chained payment system in c#


I am working on MVC Project in which i need to use adaptive chained payment system with authorization and capture.

Right Now, I am following this link:-

https://xadaptivepayments.codeplex.com/

This code is working fine for transferring Payments in more than one account. But I don't know how can i add paymentaction parameter while it redirects to sandbox account for payment so that Seller Can Capture Payment.

My Code is As Follows:-

    IPayPalAdaptivePaymentService _paysvc = new PayPalAdaptivePaymentService();
        Uri redirectUrl = new Uri(ConfigurationManager.AppSettings["REDIRECT-URL"]);
        Uri returnUrl = new Uri(ConfigurationManager.AppSettings["PAYPAL-RETURNURI"]);
        Uri cancelUrl = new Uri(ConfigurationManager.AppSettings["PAYPAL-CANCELURI"]);
        string str = "asdsadsadsads";
        string seller = ConfigurationManager.AppSettings["PAYPAL-SELLER"];
        string paymentref = "test123";
        string currency = "USD";
        List<x.paypal.model.Receiver> receivers = new List<x.paypal.model.Receiver>();
        receivers.Add(new x.paypal.model.Receiver { Amount = "3", Email = "[email protected]", InvoiceId = str, Description = "test paypal payment" });
        receivers.Add(new x.paypal.model.Receiver { Amount = "7", Email = "[email protected]", InvoiceId = str, Description = "test paypal payment 1" });
         IPayRequest payRequest = new x.paypal.model.PayRequest().CreateRequest().WithPaymentReference(paymentref).WithReturnUri(returnUrl).WithCancelUri(cancelUrl).Currency(currency).ReceiverList(receivers);
         var resp = _paysvc.RequestPayment(payRequest);
         return Redirect("https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_ap-payment&paymentaction=authorization&paykey=" + resp.PayKey);

Please help me Out in this one.

Thanks in Advance...


Solution

  • Authorization/Capture is not possible in Adaptive Payments as both of them are in different separate model.

    However, you can achieve the concept of Authorization/Capture in Adaptive Payments, that is using Preapproval Payments.

    By setting up preapproval with your buyer for a specific amounts within a specified time period, buyer can preapprove by granting your permission in charging him the amount stated in the future. (Authorization)

    With the preapproval key obtained, you can now charge the buyer in anytime you want, which is similiar to the concept of Capture.

    You will then use the Pay API operation by supplying the preapprovalKey and set actionType=PAY to charge the buyer and distribute the amount to primary and secondary receiver.

    The link you are referring to is very old, and I am not sure if it can support the above scenario. You can try researching it to achieve the concept above.

    If not, you can use the Adaptive Payment SDK here for .NET: https://www.nuget.org/packages/PayPalAdaptivePaymentsSDK/