Skip to content
Advertisement

How do I integrate PayPal Smart Button in Laravel 8?

I am trying to integrate PayPal Smart buttons in my Laravel 8 Website. These are the documentation I am using: https://developer.paypal.com/docs/checkout/integrate/

https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/

https://github.com/paypal/Checkout-PHP-SDK

Issue: I get two errors:

This error underlines the fetch in my front-end.

JavaScript
JavaScript

Here is my route file:

JavaScript

Here is my PayPalController Method:

JavaScript

Here is my front-end .blade.view file:

JavaScript

I have edited the PayPalClient.php file with my credentials.

Advertisement

Answer

A 500 error within your /createOrder route is something you’ll need to diagnose/debug internally. Try loading the URL in a browser and see if you get any more error output from Laravel. If you don’t, edit the corresponding PHP to output more useful information about what’s going on.

Once you sort that out and are returning an actual id as part of a JSON object, you need to change your front end code to read the key of that id. It looks like you are reading the key orderID, which won’t be set unless you specifically set it.

The following front-end demo code is better, and has error handling: https://developer.paypal.com/demo/checkout/#/pattern/server

This part of your front-end code:

JavaScript

Makes absolutely no sense, unless it’s just for testing purposes, but still really doesn’t make sense.

All you should have is a container <div> with the id paypal-button-container, for the JS to render its own button in. That button does not in any way use or work with an HTML form.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement