Below is the code I have tried to write by creating a container .Not sure if I can do it through container.
In some places I see that it needs a contract class to serialize as well as deserialize the json request and response.
Please help me create a contract class for serializing all the values into json string to form the request body.
str order_id = projInvoiceJour.proposalid;
str order_amount = num2Str(projInvoiceJour.invoiceamount,0,0,0,0);
str order_currency = projInvoiceJour.currencyid;
str order_expiry_time = date2Str(projInvoiceJour.duedate, 321,DateDay::Digits2,DateSeparator::Hyphen,DateMonth::Digits2, DateSeparator::Hyphen,DateYear::Digits4);
str customerId = projInvoiceJour.InvoiceAccount;
str customerPhone = dirPartyContactInfoView.Locator;
str terminalId = parameters.CFTerminalID;
str terminalPhone = parameters.CFTerminalPhone;
str invoiceId = projInvoiceJour.projinvoiceid;
str invoiceDate = date2Str(projInvoiceJour.invoicedate, 321,DateDay::Digits2,DateSeparator::Hyphen,DateMonth::Digits2, DateSeparator::Hyphen,DateYear::Digits4);
str gstin = taxReg.registrationNumber;
str gst = num2Str(abs(taxTransCGST.taxAmountCur) + abs(taxTransSGST.taxAmountCur),0,0,0,0);
str cgst = num2Str(abs(taxTransCGST.taxAmountCur),0,0,0,0);
str sgst = num2Str(abs(taxTransSGST.taxAmountCur),0,0,0,0);
str invoice_name = projInvoiceJour.DeliveryName;
jsonContainer = [
['order_id', order_id],
['order_amount', order_amount],
['order_currency', order_currency],
['customer_details', [
['customer_id', customerId],
['customer_phone', customerPhone]
]],
['terminal', [
['cf_terminal_id', terminalId],
['terminal_type', 'SPOS'],
['terminal_phone_no', terminalPhone]
]],
['order_expiry_time', order_expiry_time],
['order_tags', [
['invoice_number', invoiceId],
['invoice_date', invoiceDate],
['gstin', gstin],
['gst', gst],
['cgst', cgst],
['sgst', sgst],
['invoice_name', invoice_name]
]]
];
str orderJson = FormJsonSerializer::serializeClass(ContractClass);
encoding = System.Text.Encoding::get_UTF8();
stringContent = new System.Net.Http.StringContent(orderJson, encoding, "application/json");
headers = httpClient.DefaultRequestHeaders;
headers.Add('x-api-version', apiVersion);
headers.Add('x-client-id', clientId);
headers.Add('x-client-secret', clientSecret);
headers.Add('x-idempotency-key', idempotencyKey);
headers.Add('x-request-id', requestId);
Do I have to create parm methods for all the fields ? How will the different nodes be defined in contract class (By nodes I mean - data, customer details,terminal, order_tags) ?
Please help.
Thanks,
Priya