Quick Start to Integrating Stripe in Your Application
Stripe is an international payment system known for its high level of security and reputable protection of personal data. Due to its easy user-friendly interface and rich functionality, Stripe is one of the most preferred payment services to be integrated into web and mobile applications. In the guide below, we’ll walk you through the Stripe integration process and will explain how to set the system up so your business can receive the maximal benefit from it.
Before starting your work with Stripe, we’d like to explain what makes Stripe so popular among business owners. Its advantages include:
Support of international businesses;
Simple yet powerful subscription features;
Clear and informative reports;
Transparent service fees;
Advanced customization of development tools.
At the same time, Stripe has several pitfalls that should be considered before integrating this service into your system. They are:
No support for high-risk countries;
Very strict monitoring of adherence to Stripe regulations.
No direct phone support line.
Despite the points above, Stripe remains incredibly popular because its pros clearly outweigh its cons. So how do you make Stripe work within your system?
Let’s consider how to use the Stripe payment system in your Java Application. To integrate the Stripe API into your application, you need to open a Stripe account. For this, you need to create an account and then confirm it with your email and phone number. You can then find the authentication keys in the toolbar.
These keys must be included in the application.properties:
Every account has authentication keys for a test mode and a production mode. It’s highly recommended to use the test mode for the development because any changes made will not affect the ongoing transactions. This, in turn, guarantees the immutability of your real customers and fees and won’t affect them in any way.
There are also two types of keys: secret and public. Public ones are used for account identification and for token creation; these keys can be placed in the Java code or in mobile applications. Secret keys are used to execute the API requests to Stripe and should be kept secret and on your server only.
Stripe provides an option to create customers, plans, subscriptions, maps, and other necessary elements through the toolbar in your Stripe account. Stripe also provides its own libraries for different programming languages and these libraries also allow you to create different objects through the API.
Once you create an account, you can start creating products. A product is an object that you will offer to your customers and charge a fee for it. There are two kinds of products that you can create: goods and services. As a rule, products are created and managed in a Stripe dashboard.
To create a new product, go to the "Products" section of the toolbar, click “New”, enter the needed values, and click on “Create product”.
You can also create products through the API.
After creating a product, you will be automatically transferred to the page with different tariff plans. You can set them up either in the Stripe dashboard or by using the API. You can also have several tariff plans for one product. Different plans will display the differences in price and the duration of validity.
Once the product plan is created, you will be able to change only its metadata and name. The price, currency, and payment frequency will remain constant. Thus, if you need to change these values you will need to create a new plan. Note that the deletion of a plan will not affect its current subscribers (their subscription plan will remain the same) but this plan will not be available for new subscribers anymore.
Overall, it is not recommended to delete product plans as this may affect the history of your transactions and the data in general. But if you really need to do that, there is an option to delete a plan via the API methods in the class “Plan package com.stripe.model”. In addition to object variables, this class also contains methods for creating, receiving, and deleting a plan.
“amount” – a positive integer in cents (or 0 for a free plan) representing how much to charge on a recurring basis.
“currency” – a three-letter ISO currency code, in lowercase. Must be a currency supported by Stripe.
“interval” – specifies billing frequency. Can be either daily, weekly, monthly, or annually.
As for the customers, you can create them either via the API or via the Stripe dashboard:
The package ‘com.stripe.model’ contains all the necessary classes for creating necessary entities, such as Customer, Subscription, Charge, Card, Event, and others.
To create a regular payment page, you need to follow these steps:
1. Create products and plans.
2. Create a verification session on the server.
3. Order redirection.
You can define several plans with different parameters for each product on offer. Every plan has its own identifier that can be used instead of a link during the checkout process. You can also set up a trial period for every plan.
After testing the products, you can create their duplicates and send them to production without the need to recreate new products. To do so, go to the detailed product view, click the drop-down list next to the “Add plan”, and click on “Copy product online." This can be done only once and the changes made to the test product will not affect the product on offer.
Creating a session
Next, a session is created with the subscription_data (a subset of parameters that are passed when creating a subscription for verification sessions) and a plan identifier.
A Checkout Session is a customer’s session for a one-time purchase or a subscription. It is recommended that you create a new session every time a payment is made and you should not store the session for reusing.
After the user is redirected to the checkout session, Stripe provides a preferred form of payment. Upon successful payment, the client is redirected to the success_url of your site. If the payment was not completed, the user will be redirected to the exit_url and will get to the same page that led to the checkout before.
After successful payment, the session will provide a link to the client. This link will get them back to the app. The user will also receive the details of the payment method or their subscription plan. Note that the checkout session expires in 24 hours. Do not rely on redirecting to success_url after completing the purchases as attackers can gain direct access to success_url or users will not always be able to achieve success_url after the payment.
Once the Checkout session is successfully completed, there are two ways to get the Session object:
1. Asynchronously: handle ‘checkout.session.completed’ webhooks that contain a Session object ;
2. Synchronously: get sessionId URL when the user is redirected back to your site. However, this may not always happen: for example, if the user closes the browser tab before the redirection happens. Working with webhooks prevents this form of dropout.
A subscription is created by combining a customer and a product. After placing the order, the user is invited to pay the bill. If the card was not entered before, you must create a new ‘card’ object in Stripe. Subscriptions allow you to charge a customer on a recurring basis. If a one-time purchase is made, instead of an object Subscription, the Charge object is created.
Add Charge using Stripe library:
Or create a Subscription using Stripe library:
You can also configure webhooks to receive notifications about events that happen in your account. The endpoint must have an URL and a list of enabled_events. If you wish, you can specify the connection parameter too. If its value is true, you will receive notifications to the specified URL about all events from all connected accounts. If its value is false, notifications about your account will be sent to the specified URL only.
Usually, webhooks are configured in the Stripe toolbar. But you can use the API to create an object:
When you create a payment in Stripe, a security token is created that you can use only once. In order not to request the card data every time, Stripe creates a Custom object. You can use it for subscriptions or for one-time payments. To make the card available for other payments, it is necessary to create a Custom object instead of a Charge object and save the client’s identifier.
In order to debit from a specific client, you just need to pass the identifier instead of the card data in the debit request. Stripe also has a system for automatically updating the card data if the card was reissued by the bank (in case of its loss, replacement due to the validity period, etc.). However, the option of automatic data update depends on the bank’s participation in the Stripe network and the provision of this data. This feature is widely used in America and allows customers to continuously use the service.
Clients can use several payment methods and the first saved one will be selected as the default_source and will be used every time a subscription payment is made. As for creating and deleting a card, it is also possible to update the client’s data and selecting another card as the default one.
Transactions are cash flows resulting from approved permits and actions of the cardholder. They are created when the card is used to send or to receive money. Transactions contain information about the card used, the cardholder, and the seller.
Sometimes after authorization is approved, the merchant will retain its monetary amount for a period of time. In most cases, it happens within 24 hours, although the retention may take up to 7 days. Most merchants won’t be allowed to retain this monetary amount for longer than 7 days, although a few merchant categories (including hotels, airlines, and car rental companies) have up to 30 days of retention.
When authorization is retained, two things happen at the same time:
The status of the Authorization object changes to closed and releases the purchase amount held by that authorization. A balance transaction of type “issuing_authorization_release” is created to represent this. In addition, an ‘issuing_authorization.updated’ webhook event is triggered.
A new Transaction object of the “retention” type is created. It deducts the purchase amount from your account balance. Another balance transaction of type “issuing_transaction” is created to represent this. In addition, an “issuing_transaction.created” webhook event is triggered.
Both refunds (in case of legitimate transactions) and credits (in case of accidentally-duplicated captures from the acquirer) result in transactions with a type of refund. Refunds may also be reversed (in case of duplicated refunds from the acquirer), which results in a transaction with a “refund_reversal” type.
When we create a transaction representing a refund, a credit, or a refund reversal, we try to link it to the original authorization. But sometimes this isn’t possible. In these cases, the authorization field of the transaction is set to null and the transaction won’t be linked to the authorization in the Issuing dashboard.
The Issuing transactions dashboard lists all transactions across all issued cards, providing details such as:
You can filter which transactions you want to see by specifying the ID of an issued card or you can download all transactions as a CSV file.
You can also retrieve transactions by using the API to develop and generate custom reports. For example, you can retrieve transactions to generate a typical credit card statement by listing all transactions within a certain period of time (e.g., 30 days) for a particular card.
A list can include a maximum of 100 objects. If you need to retrieve more transactions, use pagination to perform additional requests.
Transactions usually contain the ID of their original authorization in the authorization field. In some cases, when including refunds or a force-cleared purchase, there isn’t an authorization that a transaction can link to. In this case, the authorization field has a null value.
You can also include pending purchases in your statements by listing authorizations that have a pending status. These authorizations hold funds but were not yet captured. As a result, no transactions were created for them yet.
By automating this process, you can quickly generate card statements every month for each of your cardholders.
Another valuable Stripe feature is cash withdrawal. It allows cardholders to receive a cash advance or use their cards in ATMs to withdraw cash. This feature isn’t currently available on issued cards.
Stripe is currently available in more than 26 countries and is mostly used in Europe and America. If your country is not on the list of countries supported by Stripe, you can request notifications from Stripe in order to know when your country gets added to the list.
Also, if Stripe is not supported in your country, you can use the Stripe Atlas program to set up your online business as a combined company from Delaware (this program is available only for online businesses). The cost of this program is $ 500 when connected, an annual account update is $ 100, and maintaining an account with an American bank is worth $ 25 per month.
Despite the geographical limited availability of Stripe, it supports operations with more than 135 types of currencies, which makes it really convenient for international business. Also, Stripe has no hidden fees and this is another advantage that contributes to its reliability and transparency.
Victor is an experienced PM manager with a proven track record. He successfully manages projects in various business domains such as healthcare, retail, fintech, communication and transportation. Victor is an encouraging person who is always ready to share his knowledge.View all articles by this author.
Hello there! I simply wish to give you a huge thumbs uup for the great information you’ve got right here on this post. I am returning to your blog for more soon.