Create and Send
1 min
To create and send an Invoice in Stripe, use the action "CreateInvoice," set the invoiceStatus to "SEND_TO_CUSTOMER," and pass the Invoice data in the RequestJSON under "invoices."
Note: You can only create one record at a time.
The following is an example of Create and Send an Invoice, where we are setting every possible field (See Invoice - Stripe for the available fields). The response will return the response from Stripe, which includes the new Stripe Invoice ID (internalId), plus the newly created Salesforce Invoice ID (salesforceId).
The following is an example of Create and Send an Invoice.
Map<String, Object> invoiceData = new Map<String, Object>();
invoiceData.put('processorCustomerId', 'processorCustomerId');
invoiceData.put('invoiceStatus', 'SEND_TO_CUSTOMER');
invoiceData.put('daysUntilDue', 2);
List<object> items = new List<object>();
Map<String, Object> itemData = new Map<String, Object>();
itemData.put('processorPriceId', 'processorPriceId');
itemData.put('quantity', 2);
items.add(itemData);
invoiceData.put('items', items);
// Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('invoices', new List<Object>{invoiceData});
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version','1.0');
reqObj.put('action','CreateInvoice');
reqObj.put('processorId', 'processorId');
reqObj.put('requestJSON',reqJSON);
// Placing a request to Breadwinner Global API
Map<String,Object> resp = bw_payments.BreadwinnerPaymentsAPI.call(reqObj);
System.debug(resp);