I
I have been ask to implement Stripe payments into APEX. I see two options here. You can either do it in JavaScript or in PL/SQL. You can easily call a web service from PL/SQL, you wont need any extra JS library and code would be probably more secured. So let's do that.
You can find several other articles about this around. If you saw those, you can evaluate yourself on how is this different.
The easiest API choice on almost every payment gateway is called "checkout" or "checkout form". The beauty about this is that there are no sensitive data processed on your side, everything is processed on the payment gateway side. No worries about storing or processing client cards.
You should check the Stripe Checkout and specially Quickstart.
Stripe (and others) like to show the user a list of products with quantities and prices during the checkout. Hence you need to create products on Stripe and you have to do that everytime you add (or change) a new product. It is also good to synchronize list of customers (all you need to pass is a name and e-mail) and that will help you to track your orders and potential claims.
This is my simple data model:
- Products - list of products (product name, description and price)
- Customers - list of customers (e-mail)
- Shopping carts - list of cards mapped to customers
- Shopping cart items - items and amounts in specific cart
- Requests - list of payment requests made to payment gateway and results
I also have a package for you which handle adding new products, customers, managing shopping cart and initiating and verifying payments. Nothing complicated, below 600 lines. You have to add exception handling and logging of your choice. And you can easily modify this to handle payments on Square, Paypal or elsewhere.
The flow is simple. You create products, you create customers, you sync both to the Stripe (this is covered by create_product and create_customer procedures). Then you add items (products) to the shopping cart. You can adjust items and amounts in cart. When you are ready to purchase, you hit a button and that initiate payment on Stripe. That is covered by calling get_cart_checkout_url function, which also store the payment request in pay_requests table and get you the url for redirection to the payment gateway.
When you are done with the form on Stripe, you will get redirected back to your site. You can specify urls for success and failure and you will get redirected there by Stripe after the payment. In mo code I have added a security token to the link, which is unique to each request and store in pay_requests table. So it is easy to validate the payment during the immediate payment verification (see verify_checkout function).
You can get the PAY_APP package on my GitHub account under the MIT licence.
And there is also the 610 app which provides simple shopping cart management and redirection to Stripe and also handling the redirection from the Stripe. There is an install script on GitHub, just create your developer account on Stripe, fill the private key to the script and give it a go. Enjoy.
Comments
Post a Comment