1// Create a Map to store all the data of a Customer
2Map<String, Object> checkoutMap = new Map<String, Object>();
3//checkoutMap.put('locationId',locationId); // if not entered, we will request to Square and fetch the main Location Id
4checkoutMap.put('customerId',customerId);
5checkoutMap.put('checkoutType', 'orderCheckout');
6checkoutMap.put('allowTipping', true);
7
8//Creating the line items
9Map<String,Object> line_item = new Map<String,Object>();
10 line_item.put('quantity', '5');
11 line_item.put('unitPrice', '100');
12 line_item.put('itemCurrency', 'USD');
13 line_item.put('name', 'Ball');
14 line_item.put('note', 'To play cricket');
15
16Map<String,Object> line_item1 = new Map<String,Object>();
17 line_item1.put('quantity', '1');
18 line_item1.put('unitPrice', '75000');
19 line_item1.put('itemCurrency', 'USD');
20 line_item1.put('name', 'Laptop');
21 line_item1.put('note', 'For gaming');
22
23List<Object> line_items = new List<Object>();
24 line_items.add(line_item);
25 line_items.add(line_item1);
26// Adding the line items
27checkoutMap.put('lineItems', line_items);
28
29// Initializing the RequestJSON Data to be passed.
30Map<String, Object> requestJSONMap = new Map<String, Object>();
31requestJSONMap.put('checkout', new List<Object>{checkoutMap});
32String reqJSON = JSON.serialize(requestJSONMap);
33
34Map<String, Object> reqObj = new Map<String, Object>();
35reqObj.put('version', '1.0');
36reqObj.put('action', 'CreateCheckoutURL');
37reqObj.put('processorId',processorOrgId);
38reqObj.put('requestJSON', reqJSON);
39
40// Placing a request to Breadwinner Global API
41Map<String, Object> resp = bw_payments.BreadwinnerPaymentsAPI.call(reqObj);
42System.debug(resp);
43