1// Create a Map to store all the data of a Payment
2Map<String, Object> paymentMap = new Map<String, Object>();
3paymentMap.put('DisplayName','Breadwinner Inc');
4paymentMap.put('CustomerRef' , new Map<String, Object>{'value' => '71'});
5
6// Providing zero as the total payment amount since we only want the credit note amount to be applied to an invoice.
7paymentMap.put('TotalAmt','0.00');
8
9// Put the Invoice into the proper map
10Map<String,Object> invoiceLineMap= new Map<String, Object>();
11invoiceLineMap.put('Amount','100');
12
13Map<String,Object> invoiceLinkedTxnMap = new Map<String, Object>();
14invoiceLinkedTxnMap.put('TxnId','243');
15invoiceLinkedTxnMap.put('TxnType','Invoice');
16
17List<object> invoiceLinkedTxnList = new List<object>();
18invoiceLinkedTxnList .add(invoiceLinkedTxnMap);
19
20invoiceLineMap.put('LinkedTxn',invoiceLinkedTxnList );
21
22// Put the CreditMemo into the proper map
23Map<String,Object> creditNoteLineMap = new Map<String, Object>();
24creditNoteLineMap.put('Amount','100');
25
26Map<String,Object> creditNoteLinkedTxnMap = new Map<String, Object>();
27creditNoteLinkedTxnMap.put('TxnId','244');
28creditNoteLinkedTxnMap.put('TxnType','CreditMemo');
29
30List<object> creditNoteLinkedTxnList = new List<object>();
31creditNoteLinkedTxnList .add(creditNoteLinkedTxnMap);
32
33creditNoteLineMap.put('LinkedTxn',creditNoteLinkedTxnList );
34
35// Link the Invoice and Credit Memo to the Payment
36List<object> lineList = new List<object>();
37lineList.add(invoiceLineMap);
38lineList.add(creditNoteLineMap);
39paymentMap.put('Line' ,lineList);
40
41// Initializing the RequestJSON Data to be passed.
42Map<String, Object> requestJSONMap = new Map<String, Object>();
43requestJSONMap.put('payments', new List<Object>{paymentMap});
44String reqJSON = JSON.serialize(requestJSONMap);
45
46Map<String, Object> reqObj = new Map<String, Object>();
47reqObj.put('version', '1.0');
48reqObj.put('action', 'createPayment');
49reqObj.put('requestJSON', reqJSON);
50//Required, if QuickBooks Multi-Org is enabled in Breadwinner.
51//reqObj.put('qbOrgId', '4620816365285051610');
52system.debug(reqJSON);
53
54// Placing a request to Breadwinner Global API
55Map<String, Object> respMap = breadwinner_qbo.BreadwinnerQBAPI.call(reqObj);
56System.debug(respMap);