Create
1 min
To create a Checkout URL in Stripe, use the "CreateCheckoutURL" action. You need to prepare a request object and a list of line items. The request object should include the mode, processorId, and action. See the Checkout URL - Stripe for all required fields.
Please note that you can only request one Checkout URL at a time.
The resp will return a response that includes the new Stripe Checkout URL.
The following is an example of a Checkout URL for Stripe.
Map<String, Object> checkoutMap = new Map<String, Object>();
// /You may only specify one of these parameters: 'customerId', 'customerEmail'
//checkoutMap.put('customerId', stripeCustomerId);
checkoutMap.put('customerEmail', customerEmail);
checkoutMap.put('mode', 'payment');
checkoutMap.put('paymentMethodTypes', new List<String>{'card'});
checkoutMap.put('successUrl', 'https://example.com/success');
checkoutMap.put('cancelUrl', 'https://example.com/cancel');
List<Object> lineItemsList = new List<Object>();
// The line_items parameter is required in payment and subscription mode, it's not required in setup mode
// amount, quantity, currency and name are required for line item's price_data
// Subscriptions require at least one recurring price or plan to be passed to line_items and quantity
Map<String,Object> lineItemMap1 = new Map<String,Object>();
//lineItemMap1.put('processorPriceId', processorPriceId);
lineItemMap1.put('quantity', 1);
lineItemMap1.put('unitPrice', 100);
lineItemMap1.put('itemCurrency', 'USD');
lineItemMap1.put('name', 'item1');
Map<String,Object> lineItemMap2 = new Map<String,Object>();
//lineItemMap2.put('processorPriceId', processorPriceId);
lineItemMap2.put('quantity', 2);
lineItemMap2.put('unitPrice', 120);
lineItemMap2.put('itemCurrency', 'USD');
lineItemMap2.put('name', 'item2');
lineItemsList.add(lineItemMap1);
lineItemsList.add(lineItemMap2);
checkoutMap.put('lineItems', lineItemsList);
Map<String,Object> PaymentIntentMetadata = new Map<String,Object>();
PaymentIntentMetadata.put('order_id', 'abc123'); // any key-value pair
checkoutMap.put('payment_intent_metadata', PaymentIntentMetadata);
// Add subscriptionData only in subscription mode
Map<String,Object> subscriptionData = new Map<String,Object>();
//You can only specify one of these parameters: trialEnd, trialPeriodDays.
DateTime dt = Datetime.newInstance(2022, 8, 30);
//subscriptionData.put('trialEnd', dt);
subscriptionData.put('trialPeriodDays', 2);
Map<String,Object> subscriptonMetadata = new Map<String,Object>();
subscriptonMetadata.put('sub_id', 'test_123'); // any key-value pair
subscriptionData.put('subscriptionMetaData', subscriptonMetadata);
checkoutMap.put('subscriptionData', subscriptionData);
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('checkout', new List<Object>{checkoutMap});
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'CreateCheckoutURL');
reqObj.put('processorId', stripeProcessorOrgId);
reqObj.put('requestJSON', reqJSON);
// Placing a request to Breadwinner Global API
Map<String, Object> resp = bw_payments.BreadwinnerPaymentsAPI.call(reqObj);
System.debug(resp);