Create
1 min
To create an Invoice in Square, use the action “CreateInvoice” 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 creating a Square Invoice where we are setting every possible field (See Invoice - Square for all the available fields). The response will return the response from Square, which includes the Invoice ID (internalId) plus the newly created Salesforce Invoice ID (salesforceId).
Map<String, Object> invoiceData = new Map<String, Object>();
invoiceData.put('processorCustomerId', 'processorCustomerId');
invoiceData.put('dueDate', '2023-06-12');
List<object> items = new List<object>();
Map<String, Object> itemData = new Map<String, Object>();
itemData.put('processorPriceId', 'processorPriceId');
itemData.put('quantity', 3);
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);