1// Create a Map to store all the data of a Payment
2Map<String, Object> paymentMap = new Map<String, Object>();
3paymentMap.put('TotalAmt','20');
4paymentMap.put('DisplayName','Breadwinner Inc');
5paymentMap.put('CustomerRef' , new Map<String, Object>{'value' => '70'});
6
7// Link first Invoice to a Payment
8Map<String,Object> lineMap = new Map<String, Object>();
9lineMap.put('Amount','10');
10
11Map<String,Object> linkedTxnMap = new Map<String, Object>();
12linkedTxnMap.put('TxnId','233');
13linkedTxnMap.put('TxnType','Invoice');
14
15List<object> linkedTxnList = new List<object>();
16linkedTxnList.add(linkedTxnMap);
17
18lineMap.put('LinkedTxn',linkedTxnList);
19
20// Link second Invoice to a Payment
21Map<String,Object> paymentLineMap = new Map<String, Object>();
22paymentLineMap.put('Amount','10');
23
24Map<String,Object> paymentLinkedTxnMap = new Map<String, Object>();
25paymentLinkedTxnMap.put('TxnId','234');
26paymentLinkedTxnMap.put('TxnType','Invoice');
27
28List<object> paymentLinkedTxnList = new List<object>();
29paymentLinkedTxnList.add(paymentLinkedTxnMap);
30
31paymentLineMap.put('LinkedTxn',paymentLinkedTxnList);
32
33List<object> lineList = new List<object>();
34lineList.add(lineMap);
35lineList.add(paymentLineMap);
36paymentMap.put('Line' ,lineList);
37
38// Initializing the RequestJSON Data to be passed.
39Map<String, Object> requestJSONMap = new Map<String, Object>();
40requestJSONMap.put('payments', new List<Object>{paymentMap});
41String reqJSON = JSON.serialize(requestJSONMap);
42
43Map<String, Object> reqObj = new Map<String, Object>();
44reqObj.put('version', '1.0');
45reqObj.put('action', 'createPayment');
46reqObj.put('requestJSON', reqJSON);
47//Required, if QuickBooks Multi-Org is enabled in Breadwinner.
48//reqObj.put('qbOrgId', '4620816365285051610');
49System.debug(reqJSON);
50
51// Placing a request to Breadwinner Global API
52Map<String, Object> respMap = breadwinner_qbo.BreadwinnerQBAPI.call(reqObj);
53System.debug(respMap);