You are currently viewing How To Integrate Stripe With Salesforce

How To Integrate Stripe With Salesforce

Sharing is caring!

In today’s digital era, customers spend most of their time chasing payments after sending invoices. When it comes to processing payments, it is imperative to have up-to-date information about your system. For seamless online payment processing and to improve the user experience, there is an absolute need for the most flexible way to facilitate payments and payout recipients.

Integrating Stripe with Salesforce within your business is an effective solution for better payments, invoicing, and financial management, automating your critical processes and saving valuable time and resources.

Here is a comprehensive guide to learn what Stripe is, its flow, the benefits of integrating Stripe and Salesforce, and the functional flow of a Stripe Customer and Payment method using Salesforce Integration.

Introduction To Stripe

Stripe is a SaaS payment management tool designed as a complete payment solution for any business, whether the company offers on-demand services, traditional product sales, or subscription services. Stripe’s tools, unrivaled features, and APIs are designed to assist users in various tasks related to managing this business, including issuing refunds, processing orders, and managing multiple subscriptions.

The Stripe API is organized around REST. This API has predictable resource-oriented URLs and uses HTTP response codes to indicate API errors. Its built-in HTTP functions, such as HTTP authentication and HTTP verbs, are understood by ready-made HTTP clients. It supports sharing resources from different backgrounds to safely interact with our API from a client-side web application (although you should never disclose your API secret key in the client code of a public website). JSON returns all API responses, including errors, even though our API library converts the responses into appropriate language-specific objects.

Benefits Of Stripe And Salesforce Integration

1. Sync customer information with Strip customers and make payments directly from Salesforce.

2. Sync your Salesforce products with Stripe products and make monthly payments with automatic recognition of customer data.

3. Stripe & Salesforce links provide a comprehensive view of customer data that is easy to access and edit.

4. With the integration solution, your company can view all Stripe payments – credit cards, bank accounts – in Salesforce as your data.

5. Integrating Salesforce with Stripe makes your marketing process more engaging by maintaining a subscription and coupon model.

6. Stripe supports WebHook and also helps companies build real-time systems to work faster.

7. Integrating Salesforce with Stripe helps companies grow their sales and improve acceptance rates.

Steps To Integrate Stripe With Salesforce

Step 1: Firstly, we need to create an account in stripes. For creating an Account on Stripe, follow the link: https://dashboard.stripe.com/test/dashboard.

  • Click the link and fill in all the information and then click on the create account button.
  • Verify your email address by checking your inbox and click verify your email address.
  • Now you can get your API Key by clicking on Developers→ API Keys. And then you can reveal your key.
  • When we want to test data in the stripe, we have to set it as the test mode by clicking on the toggle button named as viewing the test data. On the other hand, when we need to use this account in live mode, we need to turn off the toggle button.

Now Create the Remote Site Setting to start integration with stripe. 

  • Go to Setup
  • Click On the Quick Find Box and type Remote Site Setting.
  • Click On the Remote Site Setting and Click New.
  • Enter the Remote Site Url  https://api.stripe.com.

How To Create Customer In Stripe By Salesforce

We need to create customers first when we start in the stripe. The Customer resource is a core entity within Stripe. Use it to store all of the profile, billing, and tax information required to bill a customer for subscriptions and one-off invoices. Customers simply need a debit or credit card to pay.

Here is the code to create a customer from Salesforce to Stripe:

String accessToken = ‘sk_test_000001111111’;

Http http = new Http();

HttpRequest request = new HttpRequest();

request.setMethod(‘POST’); 

request.setEndpoint(‘https://api.stripe.com/v1/customers);

request.setHeader(‘Content-Type’,’application/x-www-form-urlencoded’);    request.setHeader(‘Authorization’,’Bearer ‘+accessToken );

String body = ‘name=Customer&email=abc@gmail.com&description=customer’;

HttpResponse response = new HttpResponse();

request.setBody(body);

response = http.send(request);

String responseBody = response.getBody();

We need to save the customer ID from the response to perform further action like Adding the payment method. We can use the above code to create a customer in Stripe and use more parameters to add in the body. 

Follow the link:  https://stripe.com/docs/api/customers

How To Create Payment Method In Stripe By Salesforce

We can create two types of payment methods in stripe.

  1. Card type (Debit card or credit card): When we want to add a card type, we need to make two callouts.
    1. We need to create a payment method.by providing the card details.
    2. We get a card Id then we need to attach it to the customer.
  2. ACH Type (Bank Account): When we want to add an ACH type, we need to make Three callouts.
    1. We need to create a payment method.by providing the bank Account details.
    2. We get a bank Id then we need to attach it to the customer.
    3. We need to verify the account by filling two small amounts which the bank requested.

Follow the steps to create the payment Methods of Card type:

  1. Creating the payment method to get the Id:

String accessToken = ‘sk_test_000001111111’;

Http http = new Http();

HttpRequest request = new HttpRequest();

request.setMethod(‘Post’);

request.setEndpoint(‘https://api.stripe.com/v1/payment_methods‘);

request.setHeader(‘Content-Type’, ‘application/x-www-form-urlencoded’);

request.setHeader(‘Authorization’,’Bearer ‘+accessToken);

String bodyRequest = ‘type=card’;+’&card[number]=4242424242424242&card[exp_month]=12&card[exp_year]=2024&card[cvc]=123′;

request.setBody(bodyRequest);

HttpResponse response = http.send(request);

String responseBody = response.getBody();

We need to store the  Payment method id which we get from the response to add the payment method to the customer.

  1. Now attach this payment method with the customer.

//This is id which we get from the Creating the Customer

String CustomerId = ‘Cus_00000000’;

//This is id which we get from the Creating the payment method

String cardId = ‘PM_00000000’;

String accessToken = ‘sk_test_000001111111’;

Http http = new Http();

HttpRequest request = new HttpRequest();

request.setMethod(‘POST’);          request.setEndpoint(‘https://api.stripe.com/v1/payment_methods/’+cardId+’/attach’);

request.setHeader(‘Content-Type’, ‘application/x-www-form-urlencoded’);

request.setHeader(‘Authorization’,’Bearer ‘+accessToken);

request.setBody(‘customer=’+CustomerId);

HttpResponse response = http.send(request);

String responseBody = response.getBody();

Follow the steps to create the payment Methods of ACH type:

  1. Creating Bank Account Token:

String accessToken = ‘sk_test_000001111111’;

Http http = new Http();

HttpRequest request = new HttpRequest();

request.setMethod(‘Post’);

request.setEndpoint(‘https://api.stripe.com/v1/tokens’);

request.setHeader(‘Content-Type’, ‘application/x-www-form-urlencoded’);

request.setHeader(‘Authorization’,’Bearer ‘+accessToken);

String bodyRequest = bank_account[country]=US&bank_account[currency]=USD’&bank_account[account_holder_name]=Jenny Rosen&bank_account[account_holder_type]=Individual’&bank_account[routing_number]=11000000000’&bank_account[account_number]=000123456789’;

request.setBody(bodyRequest);

HttpResponse response = http.send(request);

String responseBody = response.getBody();

We need to store the token id we get from the response to create a source (Bank Account).

  1. Now attach this Account with the customer using the token id:

//This is the id which we get from the Creating the token

String token = ‘btok_00011110000;

String accessToken = ‘sk_test_000001111111’;

Http http = new Http();

HttpRequest request = new HttpRequest();

request.setMethod(‘POST’);

request.setEndpoint(‘https://api.stripe.com/v1/customers/’+custId+’/sources‘);

request.setHeader(‘Content-Type’, ‘application/x-www-form-urlencoded’);

request.setHeader(‘Authorization’,’Bearer ‘+accessToken);

request.setBody(‘source=’+token);

HttpResponse response = http.send(request);

String responseBody = +response.getBody();

We need to store the bank ID we get from the response to attach this method to the customer.

  1. Verifying the account with the amount.

//This is id which we get from the Creating the Customer

String CustomerId = ‘Cus_00000000’;

//This is id which we get from the Creating the payment method

String cardId = ‘ba_00000000’;

String accessToken = ‘sk_test_000001111111’;

Http http = new Http();

HttpRequest request = new HttpRequest();

request.setMethod(‘POST’);            request.setEndpoint(‘https://api.stripe.com/v1/customers/’+custId+’/sources/’+bankId+’/verify‘);

request.setHeader(‘Content-Type’, ‘application/x-www-form-urlencoded’);

request.setHeader(‘Authorization’,’Bearer ‘+accessToken);

 request.setBody(‘amounts[]=32’&amounts[]=45);

 HttpResponse response = http.send(request);

Reference: https://stripe.com/docs/api

Conclusion

Stripe’s integration with Salesforce is an intuitive and flexible solution that allows companies of all sizes to optimize their sales and financial data, including payment methods such as online credit card payments and more. By syncing Salesforce with Stripe, you give your team a comprehensive overview of your customers’ financial status in real-time.

Salesforce is one of the most powerful CRMs globally, while Stripe is a feature-rich SaaS-based all-in-one payment solution. With the Stripe & Salesforce integration, you can streamline payments, manage subscription services, develop on-demand marketplaces and build crowdfunding platforms. Would you like to integrate Stripe with Salesforce to optimize your company’s revenue potential and provide a seamless customer experience? Get in touch with Cloud Analogy, a leading Salesforce Integration partner, now!

Suraj

Suraj Tripathi

Salesforce Consultant | Solutions Engineering Head
"Suraj Tripathi, a certified Salesforce Principal Consultant of repute, is a wonderful mentor and leader. A certified Salesforce Architect and a 7x Salesforce Certified Platform Application Developer by passion and profession, Suraj has rich experience in languages such as Aura, HTML, Angular, Bootstrap, APEX, and JavaScript. With more than five years of expertise in Salesforce Development, Suraj has worked on more than 50+ projects out of which 20+ projects were related to Salesforce Integration, Writing Triggers, Batch classes, VisualForce pages, and Aura Components.

Hire the best Salesforce Development Company. Choose certified Salesforce Developers from Cloud Analogy now.

Leave a Reply

× How can I help you?