Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test Paypal Express Checkout integration?

I want to write unit test to test my Paypal Express Checkout integration.

I have problem in the step where buyer authorize payment in Paypal screen

enter image description here

Is there a way to simulate this action in my test code?

I use sandbox test account

like image 685
Farid Movsumov Avatar asked Dec 19 '25 20:12

Farid Movsumov


2 Answers

As the interface to PayPal is all controlled by PayPal, why not simply use a mock, and avoid the interaction. This way, any changes there will work, and your code just has to know how to send the first request, and validate the return from PayPal, which is all in the Mock setup.

If you want to do the actual test, then the Paypal Sandbox Instructions for the classic API may be followed.

like image 75
Steven Scott Avatar answered Dec 22 '25 08:12

Steven Scott


This method is not suitable for automated unit testing but works great on test that are manually run.

Once you have a Token from SetExpressCheckout, create a new HttpListener that has the same address as the 'ReturnUrl' specified in SetExpressCheckout and wait for a request (synchronously). Point a browser to the PayPal authentication screen with Process.Start and once the payment has been authorized/canceled the user browser will be redirected to the local address of your HttpListener that you can then use to grab the Token & PayerID.

like image 41
Anth12 Avatar answered Dec 22 '25 10:12

Anth12



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!