Why paypal smart button always return CORS error?

Recently in the process of developing integrated paypal support, according to a case to integrate paypal payments, the results of the test always show: CORS Access-Control-Allow-Origin missing or error.

Case tutorial:

  1. https://techsolutionstuff.com/post/how-to-integrate-paypal-payment-gateway-in-laravel-8

2. https://dev.to/alamriku/how-to-integrate-paypal-payment-gateway-in-laravel-8-x-ba6

Combined with two tutorials, using paypal sandbox debugging, click the payment button, then pop up paypal payment interface, click “pay now”, did not expect a CORS error.

Then the whole debugging to find information, the whole half a month, only to find that it is not the CORS error. The error came from the backend.

This sentence:

returnredirect()->away($links[‘href’])

This sentence returns the paypal payment link, send a 302 location, and then a CORS errored.

fix it:

return response()->json($response);

Modification reference:

Case Tutorial 2

official paypal example: https://developer.paypal.com/docs/checkout/standard/upgrade-integration/

Leave a comment

Design a site like this with WordPress.com
Get started