WhatsApp API Integration in Merciglobal Cloud ERP
Enhance your customer engagement by automatically sending order confirmations over WhatsApp through Merciglobal Cloud ERP using an unofficial WhatsApp API. This guide outlines how to implement the integration and provides a sample function for immediate use.
📌 Purpose
To notify customers about their sales orders instantly via WhatsApp once a transaction is saved in the system.
🔧 Use Case: Sending Sales Order Confirmation
This script should be used in the after-save event of a sales order form (trn_fac_sorder
).
✅ Key Functionalities:
- Automatically fetch order and customer details
- Compose a formatted WhatsApp message
- Send the message via a third-party WhatsApp API
- Log the response and audit the operation
🧩 PHP Function: After Save Hook
function <tablename>_edit_aftersave($id){
$q = "SELECT a.*, b.mobile, b.account
FROM #trn_fac_sorder a
LEFT JOIN #fasmast b ON b.id=a.partyid
WHERE a.id=$id";
$res = myExecute($q);
$row = getrow($res);
$res->close();
$cr = PHP_EOL; // Line break for WhatsApp formatting
$msg = "*SALES ORDER* $cr$cr Thanks for dealing with us $cr$cr";
$msg .= "Date: {$row['date']} $cr";
$msg .= "Order No: {$row['order_num']} $cr";
$msg .= "Party: {$row['account']} $cr";
$msg .= "Agent: {$row['agent']} $cr";
$msg .= "Quality: {$row['itemname']} $cr";
$msg .= "Meter: {$row['mtrs']} $cr";
$msg .= "Rate: {$row['rate']} $cr";
$msg .= "Terms & Conditions: {$row['terms']}";
$mobile = $row['mobile'];
$url = "https://wa.click2surat.com/api/send?number=91$mobile&type=text&message=".urlencode($msg)."&instance_id=686658056001D&access_token=685cee17b4250";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$response = $response ? "$mobile, Result: Success!" : "$mobile, Result: Failed!";
auditlog( 'trn_fac_sorder', $id, 'Whatsapp', $response );
}
⚠️ Notes:
- Replace
instance_id
andaccess_token
with credentials provided by your WhatsApp API vendor. - Ensure the
mobile
number is in proper international format (e.g., without+
but with91
prefix). - Format messages using WhatsApp text styles:
*bold*
,_italic_
,~strikethrough~
, etc.
📞 Support
For any issues, reach out to Merciglobal Cloud ERP support team or your WhatsApp API vendor.
Happy Messaging! 📲