Hello everyone, I’m Atlas Can and today we are going to discuss and show how to automate an integration between Salesforce and Stripe using webhooks and the Stripe REST API!
In this first part, we will focus on creating a Stripe customer in Salesforce when a new customer is created in Stripe.
We will walk you through the process of using Stripe webhooks to create a Stripe Customer as an Account in Salesforce, storing their Stripe ID in a custom field. We will assume that you already have a Stripe and Salesforce account and that you have installed Declarative Webhooks from the Salesforce AppExchange.
Stripe webhooks allow you to receive real-time notifications about events that occur within your Stripe account. In this tutorial, we will use webhooks to send event data to Salesforce, which will then create a customer record using Declarative Webhooks.
Webhooks are user-defined HTTP callbacks that enable real-time communication between different applications by sending automated messages or data when a specific event occurs. They serve as a way for apps to “subscribe” to updates and changes in another system, allowing the receiving app to act on the information instantly without the need for continuous polling or manual data syncing.
When an event triggers a webhook, an HTTP request (usually a POST) is sent to the designated URL with a payload containing relevant information about the event. The receiving application then processes the data and takes the appropriate action, such as updating its records or sending notifications.
Webhooks are particularly useful in scenarios where timely updates are crucial, as they provide near-instantaneous communication between systems. They are widely used in various applications, including payment processing, customer relationship management (CRM) systems, content management systems (CMS), and more. By leveraging webhooks, developers can create seamless, automated workflows that enhance user experiences and streamline business processes.
The integration of Salesforce and Stripe enables you to streamline customer management and enhance your customer experience. By automating the creation of a customer in Salesforce when a new customer is created in Stripe, you can ensure that your CRM stays up-to-date and reduce the risk of data inconsistency.
Furthermore, this integration allows you to leverage Stripe’s robust payment infrastructure within your Salesforce CRM. You’ll be able to easily track customer payment information and gain insights into your customer’s purchasing behavior. This will help you make data-driven decisions to optimize your sales and marketing strategies.
In addition to customer management, Stripe offers various supplementary services such as fraud detection, invoicing, and subscription management. By integrating these services with Salesforce, you can create a seamless, end-to-end customer experience.
To start, log in to your Stripe account, navigate to the Dashboard, and click on “Developers” in the left-hand menu. From there, click on “Webhooks” and then “Add endpoint.”
If you want to test a webhook you created, you can use beeceptor to quickly listen to events that are sent by a webhook. After you receive the JSON payload you can create a mapping based on this payload in your inbound callout template.
Select the “customer.created” event type from the list of available events and click “Add endpoint” to save your webhook configuration.
Now that we have configured the Stripe webhook, let’s create an Inbound Callout Template in Salesforce using Declarative Webhooks.
Here are the steps to creating the template:
Let’s break it down to steps, first we are going to determine the format of the request body, declare it’s method and determine the main object which is going to be Account for our case. Stripe can send authenticated webhooks on its request headers, but we’re going with public URL for our demo.
Map the fields from the Stripe webhook payload to the corresponding fields in Salesforce. For example, map “data.object.id” from the payload to the “Stripe_Customer_ID__c” custom field in the Account object.
Here’s how the record should look like after mapping is done, remember the URL is unique for every org so make sure to copy your own for the webhook address on Stripe. You can also import this template here.
When integrating Stripe and Salesforce using webhooks, it’s important to follow these best practices to ensure a secure, reliable, and scalable integration, there are also other events you can listen to for advanced scenarios.:
We will now walk you through the process of creating a Stripe charge from a Salesforce opportunity using Declarative Webhooks.
We are going to use the Stripe REST API, which fosters uniformity, modularity, and scalability, making it easier to manage and expand Salesforce applications.
With the integration of Salesforce and Stripe, you’ll be able to streamline your payment processing and enhance your customer experience. By automating the payment process when an opportunity is closed, your sales team can focus on selling without worrying about manual payment handling. This not only saves time but also reduces the risk of human error.
Furthermore, this integration brings the benefits of Stripe’s robust payment infrastructure to your Salesforce CRM. You’ll have access to a secure, reliable, and flexible payment platform that supports a variety of payment methods and currencies. Combining the power of Salesforce and Stripe will help you grow your business by making it easier to accept payments from customers around the world.
Additionally, having payment data directly in Salesforce allows for better reporting and analysis. You can easily create reports and dashboards to track payment metrics and gain insights into your sales performance. This will help you make data-driven decisions to optimize your sales strategy and improve your revenue. In short, integrating Salesforce and Stripe helps you create a seamless payment experience, making it easier for your team to close deals and for your customers to do business with you.
Stripe’s comprehensive documentation and active developer community make it easy to find support and resources for troubleshooting and learning. The platform is continuously evolving, ensuring that developers have access to the latest features and security updates.
In addition to payment processing, Stripe offers a variety of supplementary services such as fraud detection, invoicing, and subscription management, which allow developers to build more comprehensive solutions with minimal effort. The platform’s global reach enables businesses to accept payments from customers all around the world, in multiple currencies, and using various payment methods.
I think they are a great example of building a community and supporting their ecosystem and their developers. You can check out their annual letter here.
Maybe I am biased because they also have a cool product named Stripe Atlas but that’s another post!
In this simple integration scenario, speaking in more of Salesforce lingo we’ll create a connection between Salesforce and Stripe using REST APIs to process a payment when a new opportunity is closed-won in Salesforce using Declarative Webhooks!
We are assuming the first part of the integration is complete and we have a customer and a default payment method in our test mode-enabled Stripe account. The first part of the integration is where we capture the customers generated in Stripe to Salesforce and store their Stripe Id. We are going to use this Stripe Id now to create a charge.
As a refresher for the first post, we are using test mode so always check this if you have an activated account. Stripe has a different mechanism for validating and using their API keys which you can learn from here.
We are going to use the test mode and test mode secret key to build our integration.
In Stripe, to charge a credit card or other payment source, you create a Charge object. If your API key is in test mode, the supplied payment source (e.g., card) won’t actually be charged, although everything else will occur as if in live mode. (Stripe assumes that the charge would have been completed successfully).
We are going to call the create charge endpoint which is https://api.stripe.com/v1/charges, when you explore the documentation, you can also see that they have options for update, capture and search the charge with their respective endpoints and methods. Feel free to experiment as long as you’re in test mode.
Now that we have the Stripe API keys, let’s create a Callout Template in Salesforce using Declarative Webhooks.
Remember that we are going to use the formula field on Opportunity, Account_Stripe_ID__c to map the Stripe ID of this account in the template. The other fields we are going to use are standard fields that you can find on the Opportunity object.
Here are the steps to creating the template:
Here’s how mapping should look below, you can also import this template by clicking this link.
The key part is that Stripe is accepting incoming requests as the smallest currency unit (cent in our example). This is why we are multiplying the amount field by 100 since if we don’t and we send an Opportunity record with a 100 USD amount field, it will show in Stripe as 1 USD!
This is why you should always read the documentation carefully, whether you’re a developer or an admin, every integration is different with sometimes overlapping features.
For example, we are using the application/x-www-form-urlencoded header instead of our usual application/json. If you send a JSON body to this endpoint you would get an error since the API specifically allows for application/x-www-form-urlencoded.
In Salesforce, follow these steps to create a Record-Triggered Flow that fires the callout when an opportunity is marked as ‘Closed Won’ also, grab the developer name for the callout template we just created so we can use it inside the Apex Action element.
It’s time to test our integration! After you activate this flow, check your template is active and the Stripe endpoint is added to the remote sites, after you change the stage of an Opportunity with the Account Stripe ID field populated, you should see the charge created in Stripe almost instantly!
In this tutorial, we demonstrated how to create a Stripe Customer as an Account in Salesforce, storing the Stripe ID as an External Id. We also created a Stripe Charge from Salesforce when an Opportunity gets closed/won using Declarative Webhooks with a simple scenario.
Keep in mind Declarative Webhooks is a powerful tool that allows you to build complex integrations with just a few clicks, without the need for any code and this was a simple exercise!
As always thank you for reading and I will see you in the next post.
Thank you for following this quick guide.
If you want to learn more about Declarative Webhooks, please follow the links below:
More Integration Guides
© Omnitoria, All Rights Reserved.