I am looking into cover our PayPal integration with integration tests to verify all payment flows work correct.
We are currently supporting both Stripe and Paypal as payment providers. With Stripe, its possible to generate payment tokens etc. through their api and thereby "simulate" an end to end payment scenario.
I am looking into doing the same with Paypal adaptive payments (preapproval flow), but I can't seem to find any resources for "approving" my preapproval token through their API.
Even if I assign a sender to the preapproval request where I have permissions to make charges on their behalf (3rd party "AUTH_CAPTURE").
Anyone that can help point me in the right direction for fully automated testing of paypal payment flows. Having to manually log in and approve every key for every test is not a scalable solution :(
I already have working implementation of the needed functionality, but I would like to completely automate the testing of the integration.
What I am trying to achieve in my testcase:
[Test]
public void _Test(){
s.AuthorizePayment(booking);
s.ApprovePaymentTokenInTest(booking.PaymentToken); <----
s.CapturePayment(booking).Should().BeTrue();
}
public void AuthorizePayment(Booking booking){
...
preapproveRequest.senderEmail = TestSenderEmail;
AdaptivePaymentsService adaptivePaymentsService = new AdaptivePaymentsService(configurationMap);
PreapprovalResponse preapprovalResponse = adaptivePaymentsService.Preapproval(preapproveRequest);
...
}
public bool CapturePayment(Booking booking){
...
pr.preapprovalKey = booking.PaymentToken;
PayResponse payResponse = adaptivePaymentsService.Pay(pr);
...
return payResponse.paymentExecStatus == PayPalPaymentState.Completed;
}