- 13 Jul 2022
- 1 Minute to read
- Print
- DarkLight
Batch Apex Callouts to Stripe
- Updated on 13 Jul 2022
- 1 Minute to read
- Print
- DarkLight
Some customers use batch apex to make callouts to Stripe. This is supported for Product, Price, Coupon, Subscription, Subscription Item, Subscription Schedules, and Stripe Invoices. This functionality is available in conjunction with Salesforce's Change Data Capture feature.
Setup
- Optional: Add a batch apex class to your org that will work with the Change Data Capture feature. (This code will be dependent on your business use case. Use your in-house development team to decide what works best for your org.)
Some use cases use declarative means to identify new Stripe Billing objects. The apex code snippet below is only an example. Your setup may differ.
Example of a batch apex class:
Add the object you would like to use to the Change Data Capture setting in Setup.
Navigate to Setup > Custom Settings > Blackthorn Pay - Trigger Settings > Enable Change Data Capture = TRUE.
Create the records you would like sent to Stripe.
Optional: Execute apex code that will tell the Change Data Capture logic which records to send to Stripe.
The code snippet below is only an example of a way to call the apex class from step 1. Your use case may differ and may use other declarative means for sending new records to Stripe.
Example of code used in an Execute Anonymous window of the developer console:
Set<Id> recordIds = new Set<Id>{recordId1, recordId2, recordId3, recordId4};
SendingToStripeBatch batch = new SendingToStripeBatch(new Map<Id, SObject>([SELECT Id, bt_stripeTest__Push_To_Stripe__c FROM Product2 WHERE Id IN :recordIds]).keySet(), 1);
Database.executeBatch(batch);
Once the steps above have been configured and the code executed you will notice the related records are sent to Stripe.