Home SalesforceApex Ultimate Guide to Integrate Stripe with Salesforce CRM

Ultimate Guide to Integrate Stripe with Salesforce CRM

by Dhanik Lal Sahni
https://res.cloudinary.com/salesforcecodex/image/upload/v1721055922/FF/Salesforce-Stripe-Integration-SalesforceCodex_bbyc30.webp

Businesses need payment integration to streamline operations and increase efficiency and revenue growth. Salesforce CRM supports integration with many payment systems like Paypal, Stripe, Payoneer, Square etc. These payment systems are integrated using configuration or using AppExchange products in Salesforce. This post will explain how to Integrate Stripe with Salesforce CRM using Apex Code.

What is Stripe?

Stripe is a global online payment processing platform that allows businesses to accept payments securely and efficiently. It can handle all the technical complexities of payment processing and allow businesses to focus on their business. business. Businesses can use Stripe for credit card payment, debit card payment, Apple Pay, Google Pay, recurring billing or ACH payment. Stripe also offers a suite of APIs that allow businesses to accept payments, manage subscriptions, handle payouts, and much more.

Use Case

XYZ Company is running an e-commerce business. Sometimes customers call customer care and ask for a payment link to purchase some products. The customer support executive should be able to provide a shareable payment link to customers for purchasing directly on the Stripe website.

Solution

Payment links enable businesses to create a payment page and send the link directly to customers, on social campaigns or in email. There are two ways to generate payment links.

  1. We can create a payment link on the Stripe dashboard page. This is no code approach and the user can directly generate a payment link on Stripe.
  2. We can generate payment links using Stripe REST API.

In the first approach, support executives will require stripe dashboard access. Businesses normally hesistate to give stripe dashboard access to them. In the second approach, the executive can create a link from Salesforce. In this post, we will generate a payment link using Stripe API in Salesforce Apex

Integrate Stripe with Salesforce CRM

The below steps need to be performed to integrate Stripe in Salesforce CRM.

  1. Stripe API Credential
  2. Create Named Credential and External Credential
  3. Create Apex Class for Stripe Integration
  4. Test Page

1. Stripe API Credential

We will integrate Stripe REST API in Salesforce to generate payment links. To handle this we need the Stripe API URL and its credentials. Payment link required a product and it’s price that is being sold using the link. You can get a price list from Stripe Admins. Price Lists are created for products for their sale price at a specific time. We can also create prices and products using product and price Strip API. For this post, I am only focusing on payment link generation. If you need help in creating prices and products using REST API, you can ping me on LinkedIn.

Payment Link API – https://api.stripe.com/v1/payment_links

Credential

You can get API credentials from the Stripe Administrator. It is available on the Stripe Developer dashboard page. If you have access then you can also generate. For testing and development always use test mode. Production API key starts with pk_live and the development/testing mode starts with pk_test.

2. Named Credential

Salesforce’s Named Credentials securely store and manage authentication credentials for external services or endpoints. We can create a Named Credential and External Credential using the above-mentioned URL and credentials. Check out our video Deep Dive into Salesforce Named Credential to learn about named credentials.

Create an External Credential in Salesforce

External Credentials contain authentication protocols, authentication parameters, and permission set information for accessing external systems. Let us create an external credential Stripe EC(StripeEC) to connect Stripe System.

Stripe External Credential for Stripe Integration

Create a named principal that will be used to assign external credentials in permission sets. Refer to our other post Accessing External Credential Parameters of Named Credential in Salesforce Apex to use authentication parameters.

Custom Headers

We will add two customer headers in the External Credential Custom Header section.

NameValue
Content-Typeapplication/x-www-form-urlencoded
Authorization<Your API key>

Create Named Credential

Create a named credential Stripe NC (StripeNC) and assign the above-created External Credential to it. Check Generate Authorization Header and Allow Formulas in HTTP Header in Callout Options to pass external credential parameters at runtime to callout.

Named Credential for Stripe Integration in Salesforce

Create a Permission Set and Assign it to yourself

Create a permission set Stripe User PS and add the above external credentials to the External Credential Principal Access section. Once the permission set is created assign this to the required user.

3. Create Apex Class for Stripe Integration

Once the initial setup is ready, we can create an apex class StripePaymentLinkService to integrate Stripe in Salesforce. This class uses the named credential StripeNC. Payment Link API requires price and quantity. So create a request body to pass these values dynamically.

Apex class StripePaymentLink is response wrapper class. Response data will be saved in this object. There are other information also in payment link respose, but we require few informaition only. If you need all details,then you can get detail from here.

It will generate a payment link based on the passed quantity and price list ID. If the wrong price list ID is passed then API will return the error “No such price: ‘price_1Pdf3WQLME5sGA4KeKvIGxqq1d’

Create Controller Class to call Service Class

Create a controller class to call the above method StripePaymentLinkService.createPaymentLink. We can add a price list for each product in custom metadata types. Based on a product we can extract the price list ID and pass this to StripePaymentLinkService.createPaymentLink to generate a payment link.

4. Test Page

When we call StripePaymentLinkController.generatePaymentLink with valid detail it will return the payment link URL similar to below page.

Payment Link to Integrate Stripe with Salesforce

References

Payment Link

Stripe Authentication

Related Posts

How to Seamlessly Integrate Shopify with Salesforce

Automating data synchronization between Salesforce and Amazon Seller

Shopify integration with Salesforce using Webhook

Extract Text From Images using Google Cloud Vision

Seamless YouTube Video API Integration in Salesforce

Integrate Slack in Salesforce for Real-Time Notifications

The Ultimate List of Salesforce Integration Resources

Stripe Implementation Required?

If you need stripe implementation in your salesforce org, you can contact us for implementation.

You may also like

Leave a Comment