Jason
Jason

Reputation: 11

zoho books custom function with deluge

I'm creating a custom function in zoho books that will create a record in zoho creator using payment record information from zoho books. I've been able to successfully create a record in zoho creator but I'm unable to get the invoice_id from the customer_payment map.

Unfortunately, there's no error being thrown.

Below is the code:

paymentMap = Map();

//set order to payment invoice id - this is not working
paymentMap.put("Order",customer_payment.get("invoices[0].invoice_id"));

paymentMap.put("Description",customer_payment.get("card_type"));
paymentMap.put("Payment_ZB_ID",customer_payment.get("payment_id"));
response = zoho.creator.createRecord("XXXXX","XX","Payment",paymentMap);
info response;

Below is the map that is available:

customer_payment

{

 "payment_id": "11111111111111111",

 "payment_number": "1",

 "payment_number_prefix": "",

 "payment_number_suffix": "1",

 "documents": [],

 "customer_id": "11111111111111111",

 "customer_name": "John Doe",

 "payment_mode": "Stripe",

 "card_type": "visa",

 "card_type_formatted": "Visa",

 "date": "2019-03-04",

 "date_formatted": "03/04/2019",

 "account_id": "11111111111111111",

 "account_name": "Stripe Clearing",

 "account_type": "payment_clearing",

 "account_type_formatted": "Payment Clearing Account",

 "currency_id": "11111111111111111",

 "currency_code": "USD",

 "exchange_rate": 1,

 "exchange_rate_formatted": "$1.00",

 "amount": 1,

 "amount_formatted": "$1.00",

 "unused_amount": 0,

 "unused_amount_formatted": "$0.00",

 "bank_charges": 0.33,

 "bank_charges_formatted": "$0.33",

 "tax_account_id": "",

 "is_client_review_settings_enabled": false,

 "tax_account_name": "",

 "tax_amount_withheld": 0,

 "tax_amount_withheld_formatted": "$0.00",

 "discount_amount": 0,

 "discount_amount_formatted": "$0.00",

 "description": "Stripe processing fees : $0.33 ",

 "reference_number": "12345",

 "online_transaction_id": "12345",

 "settlement_status": "",

 "settlement_status_formatted": "",

 "invoices": [

  {

   "invoice_number": "11111111111111111",

   "invoice_payment_id": "11111111111111111",

   "invoice_id": "11111111111111111",

   "amount_applied": 1,

   "amount_applied_formatted": "$1.00",

   "tax_amount_withheld": 0,

   "tax_amount_withheld_formatted": "$0.00",

   "discount_amount": 0,

   "discount_amount_formatted": "$0.00",

   "total": 1,

   "total_formatted": "$1.00",

   "balance": 0,

   "balance_formatted": "$0.00",

   "date": "2019-03-04",

   "date_formatted": "03/04/2019",

   "due_date": "2019-03-04",

   "due_date_formatted": "03/04/2019",

   "price_precision": 2,

   "apply_date": "",

   "apply_date_formatted": ""

  }

 ],

 "payment_refunds": [],

 "last_four_digits": "1234",

 "template_id": "11111111111111111",

 "template_name": "Elite Template",

 "page_width": "8.27in",

 "page_height": "11.69in",

 "orientation": "portrait",

 "template_type": "elite",

 "template_type_formatted": "Elite",

 "attachment_name": "",

 "can_send_in_mail": true,

 "can_send_payment_sms": false,

 "is_payment_details_required": true,

 "custom_fields": [],

 "custom_field_hash": {},

 "imported_transactions": []

}

Upvotes: 1

Views: 1708

Answers (3)

Rakesh Kumar
Rakesh Kumar

Reputation: 41

Please use this standard way to define the deluge code: https://prnt.sc/RyI440seMS_o

customer_payment = '{"payment_id":"11111111111111111","payment_number":"1","payment_number_prefix":"","payment_number_suffix":"1","documents":[],"customer_id":"11111111111111111","customer_name":"John Doe","payment_mode":"Stripe","card_type":"visa","card_type_formatted":"Visa","date":"2019-03-04","date_formatted":"03/04/2019","account_id":"11111111111111111","account_name":"Stripe Clearing","account_type":"payment_clearing","account_type_formatted":"Payment Clearing Account","currency_id":"11111111111111111","currency_code":"USD","exchange_rate":1,"exchange_rate_formatted":"$1.00","amount":1,"amount_formatted":"$1.00","unused_amount":0,"unused_amount_formatted":"$0.00","bank_charges":0.33,"bank_charges_formatted":"$0.33","tax_account_id":"","is_client_review_settings_enabled":false,"tax_account_name":"","tax_amount_withheld":0,"tax_amount_withheld_formatted":"$0.00","discount_amount":0,"discount_amount_formatted":"$0.00","description":"Stripe processing fees : $0.33 ","reference_number":"12345","online_transaction_id":"12345","settlement_status":"","settlement_status_formatted":"","invoices":[{"invoice_number":"11111111111111111","invoice_payment_id":"11111111111111111","invoice_id":"11111111111111111","amount_applied":1,"amount_applied_formatted":"$1.00","tax_amount_withheld":0,"tax_amount_withheld_formatted":"$0.00","discount_amount":0,"discount_amount_formatted":"$0.00","total":1,"total_formatted":"$1.00","balance":0,"balance_formatted":"$0.00","date":"2019-03-04","date_formatted":"03/04/2019","due_date":"2019-03-04","due_date_formatted":"03/04/2019","price_precision":2,"apply_date":"","apply_date_formatted":""}],"payment_refunds":[],"last_four_digits":"1234","template_id":"11111111111111111","template_name":"Elite Template","page_width":"8.27in","page_height":"11.69in","orientation":"portrait","template_type":"elite","template_type_formatted":"Elite","attachment_name":"","can_send_in_mail":true,"can_send_payment_sms":false,"is_payment_details_required":true,"custom_fields":[],"custom_field_hash":{},"imported_transactions":[]}';
invoicesData= customer_payment.getJSON("invoices");
if(invoicesData !=null)
{
    invoice_id=invoicesData.getJSON("invoice_number");
    paymentMap=map();   
    paymentMap.put("Order",invoice_id);
    info paymentMap;
}

Upvotes: 0

Prakash - Zoho Deluge
Prakash - Zoho Deluge

Reputation: 58

paymentMap.put("Order",customer_payment.get("invoices[0].invoice_id"));

Deluge does not throw an error here. Instead, when an element whose key is not available is being fetched, it throws a null.

The key used in ur code snippet invoices[0].invoice_id is not a valid key in the customer_payment map. So, this has been throwing a null value which would have populated as an empty (or no) value in Zoho Creator.

If you notice the customer_payment clearly, all invoices are available under the key "invoices".

invoices = customer_payment.get("invoices");// now invoices will have the list of invoices in customer_payment map

Assuming that the payment has only one invoice, the invoice ID can be extracted as below:

invoiceId = invoices.getJson("invoice_id");

It is also possible to extract the invoice ID as you have tried, like the below:

info customer_payment.get("invoices").get(0).get("invoice_id");

Upvotes: 1

Rishabh Kushwaha
Rishabh Kushwaha

Reputation: 439

You can fetch invoice_id like this :

 customer_payment = {"payment_id":"11111111111111111","payment_number":"1","payment_number_prefix":"","payment_number_suffix":"1","documents":{},"customer_id":"11111111111111111","customer_name":"John Doe","payment_mode":"Stripe","card_type":"visa","card_type_formatted":"Visa","date":"2019-03-04","date_formatted":"03/04/2019","account_id":"11111111111111111","account_name":"Stripe Clearing","account_type":"payment_clearing","account_type_formatted":"Payment Clearing Account","currency_id":"11111111111111111","currency_code":"USD","exchange_rate":1,"exchange_rate_formatted":"$1.00","amount":1,"amount_formatted":"$1.00","unused_amount":0,"unused_amount_formatted":"$0.00","bank_charges":0.33,"bank_charges_formatted":"$0.33","tax_account_id":"","is_client_review_settings_enabled":false,"tax_account_name":"","tax_amount_withheld":0,"tax_amount_withheld_formatted":"$0.00","discount_amount":0,"discount_amount_formatted":"$0.00","description":"Stripe processing fees : $0.33 ","reference_number":"12345","online_transaction_id":"12345","settlement_status":"","settlement_status_formatted":"","invoices":{{"invoice_number":"11111111111111111","invoice_payment_id":"11111111111111111","invoice_id":"11111111111111111","amount_applied":1,"amount_applied_formatted":"$1.00","tax_amount_withheld":0,"tax_amount_withheld_formatted":"$0.00","discount_amount":0,"discount_amount_formatted":"$0.00","total":1,"total_formatted":"$1.00","balance":0,"balance_formatted":"$0.00","date":"2019-03-04","date_formatted":"03/04/2019","due_date":"2019-03-04","due_date_formatted":"03/04/2019","price_precision":2,"apply_date":"","apply_date_formatted":""}},"payment_refunds":{},"last_four_digits":"1234","template_id":"11111111111111111","template_name":"Elite Template","page_width":"8.27in","page_height":"11.69in","orientation":"portrait","template_type":"elite","template_type_formatted":"Elite","attachment_name":"","can_send_in_mail":true,"can_send_payment_sms":false,"is_payment_details_required":true,"custom_fields":{},"custom_field_hash":{},"imported_transactions":{}};



    invoices = customer_payment.getJson("invoices");
    //info invoices;
    invoiceId = invoices.getJSON("invoice_id");
    info invoiceId;

Upvotes: 0

Related Questions