Stripe is an online payment platform that helps businesses to process payments online securely and quickly. It is one of the most popular payment gateways that allows merchants to accept payments from customers in multiple currencies. Stripe offers several features to support subscription billing for merchants, which can be integrated into their web or mobile applications. This document will guide you through the process of using Stripe’s Card Payment Method element to create and pay for a subscription.
Conclusion
Install the Stripe PHP library
Install the library with composer and initialize it with your secret API key. Alternatively, if you’re starting from scratch and need a composer.json file, download the files using the link in the code editor.
Using Composer
composer requires stripe/stripe-php
Or download the stripe-php library source code directly from GitHub. : https://github.com/stripe/stripe-php
Create a PaymentIntent
Add an endpoint on your server that creates a PaymentIntent. A PaymentIntent tracks the customer’s payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent’s client secret in the response to finish the payment on the client.
Create file: create.php
In this file, we have written code for creating a customer (if we do not have a stripe customer id) and then need to create a subscription
Build a checkout page on the client: checkout.html
In the checkout file, we write code for mounting a card, for mounting a card add an empty placeholder div to your checkout form. Stripe inserts an iframe into this div that securely collects card information.
After creating checkout.html you should add style on the card element, So now create a CSS file style.css
Initialize Stripe.js
Initialize Stripe.js with your publishable API keys. You will use Stripe.js to create the card input field and complete the payment on the client.
// This is your test publishable API key.
const stripe = Stripe(“your publishable API key”);
Handle the submitted event
Listen to the form’s submit event to know when to confirm the payment through the Stripe API.
If you are looking for any ready solution for stripe gateway please contact us