So firstly what is stripe? Stripe is the most commonly used payment gateway. Stripe is widely used by e-commerce, subscription based services and by many small as well as large scale businesses to manage their payments and subscriptions. With the help of Rest API’s Stripe makes it easy for us to manage our payments.
While I was integrating Salesforce to stripe I faced many challenges, with the help of this article I would like to share my learning and the steps for Salesforce to Stripe integration using input from a LWC component. I have also attached the link to my GIT for reference to code.
Some key use cases of Stripe:
- Manage customers.
- Manage their payment methods and also save the primary payment source.
- Initiate transaction from Salesforce.
Despite detailed documentation provided by Stripe, integration with Stripe using Apex was challenging while passing the nested object structure in url encoded format.
How we usually pass nested object structure in JSON.
How Stripe accepts nested objects(check the link to git for complete code)
Steps to integrate Stripe with Salesforce.
Firstly you would need the secret key from your stripe account. To get the secret key go to Developers->API key-> check on reveal key to get it.
- Once you have the key you can store it in your environment(I used a custom metadata to store it)
- Creating a screen for the inputs required for the integration, which will be calling the Helper for creating the customer, payment method and initiates the payments. I have shared the code which uses a Stripe helper to create the request and call Stripe API for customers, payment methods and then to initiate the payments.
3. Once the payment is processed check your stripe account for all the records and store the transaction Id in Salesforce for future reference(eg. Lead, if making payments for a lead record.)