1Map<String, Object> checkoutMap = new Map<String, Object>();
2// /You may only specify one of these parameters: 'customerId', 'customerEmail'
3//checkoutMap.put('customerId', stripeCustomerId);
4checkoutMap.put('customerEmail', customerEmail);
5checkoutMap.put('mode', 'payment');
6checkoutMap.put('paymentMethodTypes', new List<String>{'card'});
7checkoutMap.put('successUrl', 'https://example.com/success');
8checkoutMap.put('cancelUrl', 'https://example.com/cancel');
9
10List<Object> lineItemsList = new List<Object>();
11// The line_items parameter is required in payment and subscription mode, it's not required in setup mode
12// amount, quantity, currency and name are required for line item's price_data
13// Subscriptions require at least one recurring price or plan to be passed to line_items and quantity
14
15Map<String,Object> lineItemMap1 = new Map<String,Object>();
16//lineItemMap1.put('processorPriceId', processorPriceId);
17lineItemMap1.put('quantity', 1);
18lineItemMap1.put('unitPrice', 100);
19lineItemMap1.put('itemCurrency', 'USD');
20lineItemMap1.put('name', 'item1');
21
22Map<String,Object> lineItemMap2 = new Map<String,Object>();
23//lineItemMap2.put('processorPriceId', processorPriceId);
24lineItemMap2.put('quantity', 2);
25lineItemMap2.put('unitPrice', 120);
26lineItemMap2.put('itemCurrency', 'USD');
27lineItemMap2.put('name', 'item2');
28
29lineItemsList.add(lineItemMap1);
30lineItemsList.add(lineItemMap2);
31
32checkoutMap.put('lineItems', lineItemsList);
33
34Map<String,Object> PaymentIntentMetadata = new Map<String,Object>();
35PaymentIntentMetadata.put('order_id', 'abc123'); // any key-value pair
36checkoutMap.put('payment_intent_metadata', PaymentIntentMetadata);
37
38// Add subscriptionData only in subscription mode
39Map<String,Object> subscriptionData = new Map<String,Object>();
40//You can only specify one of these parameters: trialEnd, trialPeriodDays.
41DateTime dt = Datetime.newInstance(2022, 8, 30);
42//subscriptionData.put('trialEnd', dt);
43subscriptionData.put('trialPeriodDays', 2);
44
45Map<String,Object> subscriptonMetadata = new Map<String,Object>();
46subscriptonMetadata.put('sub_id', 'test_123'); // any key-value pair
47subscriptionData.put('subscriptionMetaData', subscriptonMetadata);
48
49checkoutMap.put('subscriptionData', subscriptionData);
50
51Map<String, Object> requestJSONMap = new Map<String, Object>();
52requestJSONMap.put('checkout', new List<Object>{checkoutMap});
53String reqJSON = JSON.serialize(requestJSONMap);
54
55Map<String, Object> reqObj = new Map<String, Object>();
56reqObj.put('version', '1.0');
57reqObj.put('action', 'CreateCheckoutURL');
58reqObj.put('processorId', stripeProcessorOrgId);
59reqObj.put('requestJSON', reqJSON);
60
61// Placing a request to Breadwinner Global API
62Map<String, Object> resp = bw_payments.BreadwinnerPaymentsAPI.call(reqObj);
63System.debug(resp);
64