Stripe Integration with Salesforce
So firstly what is a 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 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 the code.
Some key use cases of Stripe:
- Manage customers.
- Manage their payment methods and also save the primary payment source.
- Initiate transactions from Salesforce.
Key Challenge:
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 the 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, and payment method and initiating 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 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.)
sanjeet2401/Salesforce
Contribute to sanjeet2401/Salesforce development by creating an account on GitHub.
github.com

Checkout the below video to know more:
Keep the Stripe secret key out of your code
In the original build I kept the secret key in custom metadata. Today the safer way is a named credential, so the key never appears in Apex, metadata or a deployment package:
- Create an external credential with the authentication protocol set to Custom.
- Add a principal and store the Stripe secret key as an authorization parameter on it.
- Add a custom header to the external credential:
Authorizationwith the valueBearerfollowed by a reference to that key. - Create a named credential with the URL
https://api.stripe.comthat uses the external credential. - Give the users or integration user access to the principal through a permission set.
Your Apex callout then points at callout:Stripe/v1/customers (where “Stripe” is the named credential’s name) and Salesforce adds the header for you. Use a test-mode key in sandboxes and the live key only in production.
Sending Stripe’s nested parameters from Apex
This was the hardest part of the original build. Stripe’s API takes form-encoded request bodies, not JSON, and nested values use square brackets in the key. For example, an address and a metadata field on a customer look like this:
name=Jane+Doe&email=jane%40example.com&address[city]=Austin&metadata[salesforce_id]=00Q5g00000ABCDE
A small helper that walks a Map<String, Object> and builds the key[child] names, running every value through EncodingUtil.urlEncode(value, 'UTF-8'), saves you from hand-building strings. Set the header Content-Type: application/x-www-form-urlencoded on the request.
Getting Stripe events back into Salesforce
Creating a payment from Salesforce is only half the job. Cards fail, subscriptions renew and refunds happen in Stripe, and Salesforce needs to hear about them. Stripe sends these as webhook events, such as payment_intent.succeeded, invoice.paid and charge.refunded.
- Receive them with an Apex REST endpoint exposed through a Salesforce Site, or through middleware that then updates Salesforce.
- Verify every event before trusting it. Stripe signs each request in the
Stripe-Signatureheader. Recompute the HMAC SHA-256 of the timestamp and payload with your webhook signing secret (for example withCrypto.generateMac('hmacSHA256', ...)) and reject anything that doesn’t match. - Store the Stripe IDs (customer, payment intent, invoice) on the Salesforce record so you can match events and avoid processing the same event twice.
Custom code, an app, or middleware?
Custom Apex like this gives you full control and suits a few well-defined payment flows. An AppExchange app is usually faster when you need standard card payments, invoices and subscriptions without writing code. Middleware fits when Stripe also has to talk to an ERP or accounting system. Our Stripe Salesforce integration guide compares these options in more detail.
Kizzy Consulting
Kizzy Consulting is a Salesforce Consulting Partner based in Panchkula, India. Kizzy has successfully implemented 120+ Salesforce projects for 100+ clients across sectors like Financial Services, Insurance, Retail, Sales, Manufacturing, Real estate, Logistics, and Healthcare in countries like the US, Europe, Germany, and Australia. Get a free consultation now by emailing us at [email protected] or Contact us.
Free Salesforce Org Health Check
Connecting Stripe to Salesforce?
Our certified consultants review your org and send you the top fixes ranked by business impact, plus a scoped estimate. It’s free, there’s no obligation, and we reply within 1 business day.
Request Free Health Check →Prefer to send us a quick message?
Tell us what you need help with. A Salesforce consultant will reply within 1 business day.



