// Create a Map to store all the data of a Payment
Map<String, Object> paymentMap = new Map<String, Object>();
paymentMap.put('DisplayName','Breadwinner Inc');
paymentMap.put('CustomerRef' , new Map<String, Object>{'value' => '71'});
// Providing zero as the total payment amount since we only want the credit note amount to be applied to an invoice.
paymentMap.put('TotalAmt','0.00');
// Put the Invoice into the proper map
Map<String,Object> invoiceLineMap= new Map<String, Object>();
invoiceLineMap.put('Amount','100');
Map<String,Object> invoiceLinkedTxnMap = new Map<String, Object>();
invoiceLinkedTxnMap.put('TxnId','243');
invoiceLinkedTxnMap.put('TxnType','Invoice');
List<object> invoiceLinkedTxnList = new List<object>();
invoiceLinkedTxnList .add(invoiceLinkedTxnMap);
invoiceLineMap.put('LinkedTxn',invoiceLinkedTxnList );
// Put the CreditMemo into the proper map
Map<String,Object> creditNoteLineMap = new Map<String, Object>();
creditNoteLineMap.put('Amount','100');
Map<String,Object> creditNoteLinkedTxnMap = new Map<String, Object>();
creditNoteLinkedTxnMap.put('TxnId','244');
creditNoteLinkedTxnMap.put('TxnType','CreditMemo');
List<object> creditNoteLinkedTxnList = new List<object>();
creditNoteLinkedTxnList .add(creditNoteLinkedTxnMap);
creditNoteLineMap.put('LinkedTxn',creditNoteLinkedTxnList );
// Link the Invoice and Credit Memo to the Payment
List<object> lineList = new List<object>();
lineList.add(invoiceLineMap);
lineList.add(creditNoteLineMap);
paymentMap.put('Line' ,lineList);
// Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('payments', new List<Object>{paymentMap});
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'createPayment');
reqObj.put('requestJSON', reqJSON);
//Required, if QuickBooks Multi-Org is enabled in Breadwinner.
//reqObj.put('qbOrgId', '!aa00TM');
system.debug(reqJSON);
// Placing a request to Breadwinner Global API
Map<String, Object> respMap = breadwinner_qbo.BreadwinnerQBAPI.call(reqObj);
System.debug(respMap);