From d0a274dabe16106098971cbddc56818e211d9bef Mon Sep 17 00:00:00 2001 From: vidhya Date: Sat, 20 Jun 2026 17:17:04 +0530 Subject: [PATCH 01/12] Contact Number - add in the invoice --- mailer.js | 9 +++++++++ pdfGenerator.js | 10 ++++++++++ server.js | 9 +++++++++ 3 files changed, 28 insertions(+) diff --git a/mailer.js b/mailer.js index af8f7f6..59cc28d 100644 --- a/mailer.js +++ b/mailer.js @@ -74,6 +74,12 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer, shippingLa // --- 3. Billing Address Details HTML --- const billing = orderData.billing_address || {}; + const contactNumber = orderData.note_attributes?.find?.((attr) => attr.name === 'Contact Number')?.value + || orderData.attributes?.['Contact Number']?.contact_phone + || orderData.attributes?.['Contact Number'] + || orderData.contact_phone + || orderData.attributes?.contact_phone; + let billingAddressHtml = ''; if (billing.first_name || billing.last_name) { billingAddressHtml += `${billing.first_name || ''} ${billing.last_name || ''}
`; @@ -87,6 +93,9 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer, shippingLa if (billing.phone || orderData.phone) { billingAddressHtml += `${billing.phone || orderData.phone}`; } + if (contactNumber) { + billingAddressHtml += `
Contact: ${contactNumber}`; + } const paymentMethod = orderData.gateway || 'Request Quote'; const shippingMethod = orderData.shipping_lines?.[0]?.title || 'Economy'; diff --git a/pdfGenerator.js b/pdfGenerator.js index 555838a..fe430a0 100644 --- a/pdfGenerator.js +++ b/pdfGenerator.js @@ -132,6 +132,12 @@ const generateInvoicePDF = async (orderData) => { // Bill To (Left) const billing = orderData.billing_address || {}; + const customContactNumber = orderData.note_attributes?.find?.((attr) => attr.name === 'Contact Number')?.value + || orderData.attributes?.['Contact Number']?.contact_phone + || orderData.attributes?.['Contact Number'] + || orderData.contact_phone + || orderData.attributes?.contact_phone; + doc.fontSize(11) .font('Helvetica-Bold') .fillColor(primaryColor) @@ -168,6 +174,10 @@ const generateInvoicePDF = async (orderData) => { } if (billing.phone || orderData.phone) { doc.text(billing.phone || orderData.phone, 40, billTextY); + billTextY += 13; + } + if (customContactNumber) { + doc.text(`Contact: ${customContactNumber}`, 40, billTextY); } // Order Details (Right) diff --git a/server.js b/server.js index 7646c54..6fee522 100644 --- a/server.js +++ b/server.js @@ -206,6 +206,15 @@ app.post('/create-order', async (req, res) => { } }; + if (customerData.contact_phone || customerData.contactNumber || customerData.contact_number) { + orderPayload.order.note_attributes = [ + { + name: 'Contact Number', + value: customerData.contact_phone || customerData.contactNumber || customerData.contact_number + } + ]; + } + const shopifyResponse = await fetch(`https://${process.env.SHOPIFY_STORE_DOMAIN}/admin/api/2024-01/orders.json`, { method: 'POST', headers: { From 79280eeee30a106a81c7b3f3a8c2deb314dcc7a5 Mon Sep 17 00:00:00 2001 From: selvi Date: Mon, 22 Jun 2026 16:21:03 +0530 Subject: [PATCH 02/12] update for contact number --- server.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/server.js b/server.js index 6fee522..01c99ef 100644 --- a/server.js +++ b/server.js @@ -206,14 +206,10 @@ app.post('/create-order', async (req, res) => { } }; - if (customerData.contact_phone || customerData.contactNumber || customerData.contact_number) { - orderPayload.order.note_attributes = [ - { - name: 'Contact Number', - value: customerData.contact_phone || customerData.contactNumber || customerData.contact_number - } - ]; - } + orderPayload.order.note_attributes = [ + { name: "Contact Number", value: customerData.contact_number || "" }, + { name: "Courier", value: customerData.courier || "" } + ]; const shopifyResponse = await fetch(`https://${process.env.SHOPIFY_STORE_DOMAIN}/admin/api/2024-01/orders.json`, { method: 'POST', From ca5b17901431e0e7b465e995394fe4d75b2844ca Mon Sep 17 00:00:00 2001 From: selvi Date: Mon, 22 Jun 2026 17:18:26 +0530 Subject: [PATCH 03/12] update for contact number --- server.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 01c99ef..270c24f 100644 --- a/server.js +++ b/server.js @@ -207,8 +207,14 @@ app.post('/create-order', async (req, res) => { }; orderPayload.order.note_attributes = [ - { name: "Contact Number", value: customerData.contact_number || "" }, - { name: "Courier", value: customerData.courier || "" } + { + key: "Contact Number", + value: customerData.contact_number || "" + }, + { + key: "Courier", + value: customerData.courier || "" + } ]; const shopifyResponse = await fetch(`https://${process.env.SHOPIFY_STORE_DOMAIN}/admin/api/2024-01/orders.json`, { From 5a781d9639ae2b7ef7a4e8a3dfd2567829fc50fd Mon Sep 17 00:00:00 2001 From: selvi Date: Mon, 22 Jun 2026 17:34:29 +0530 Subject: [PATCH 04/12] update for contact number --- server.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/server.js b/server.js index 270c24f..01c99ef 100644 --- a/server.js +++ b/server.js @@ -207,14 +207,8 @@ app.post('/create-order', async (req, res) => { }; orderPayload.order.note_attributes = [ - { - key: "Contact Number", - value: customerData.contact_number || "" - }, - { - key: "Courier", - value: customerData.courier || "" - } + { name: "Contact Number", value: customerData.contact_number || "" }, + { name: "Courier", value: customerData.courier || "" } ]; const shopifyResponse = await fetch(`https://${process.env.SHOPIFY_STORE_DOMAIN}/admin/api/2024-01/orders.json`, { From 95fd8fefa1aa914a1a9a48ef4c6b299064c68d77 Mon Sep 17 00:00:00 2001 From: selvi Date: Mon, 22 Jun 2026 19:25:58 +0530 Subject: [PATCH 05/12] mail number fixed --- mailer.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/mailer.js b/mailer.js index 59cc28d..a07a747 100644 --- a/mailer.js +++ b/mailer.js @@ -74,27 +74,39 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer, shippingLa // --- 3. Billing Address Details HTML --- const billing = orderData.billing_address || {}; - const contactNumber = orderData.note_attributes?.find?.((attr) => attr.name === 'Contact Number')?.value - || orderData.attributes?.['Contact Number']?.contact_phone - || orderData.attributes?.['Contact Number'] - || orderData.contact_phone - || orderData.attributes?.contact_phone; + + // Get separate numbers + const contactNumber = orderData.contact_number || orderData.phone; + + const whatsappNumber = + orderData.whatsapp_number || + orderData.attributes?.['Whatsapp Number']; let billingAddressHtml = ''; + if (billing.first_name || billing.last_name) { billingAddressHtml += `${billing.first_name || ''} ${billing.last_name || ''}
`; } + if (billing.address1) billingAddressHtml += `${billing.address1}
`; if (billing.address2) billingAddressHtml += `${billing.address2}
`; + if (billing.city || billing.province || billing.zip) { billingAddressHtml += `${billing.city || ''} ${billing.province || ''} ${billing.zip || ''}
`; } - if (billing.country) billingAddressHtml += `${billing.country}
`; - if (billing.phone || orderData.phone) { - billingAddressHtml += `${billing.phone || orderData.phone}`; + + if (billing.country) { + billingAddressHtml += `${billing.country}
`; } + + // Show contact number if (contactNumber) { - billingAddressHtml += `
Contact: ${contactNumber}`; + billingAddressHtml += `Contact: ${contactNumber}
`; + } + + // Show WhatsApp number separately + if (whatsappNumber) { + billingAddressHtml += `WhatsApp: ${whatsappNumber}`; } const paymentMethod = orderData.gateway || 'Request Quote'; From 000b1ce970c6ea720c5482411264fff4ae4bc6b1 Mon Sep 17 00:00:00 2001 From: selvi Date: Mon, 22 Jun 2026 19:37:04 +0530 Subject: [PATCH 06/12] mail number fixed --- mailer.js | 70 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/mailer.js b/mailer.js index a07a747..322a974 100644 --- a/mailer.js +++ b/mailer.js @@ -72,42 +72,58 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer, shippingLa `; } - // --- 3. Billing Address Details HTML --- - const billing = orderData.billing_address || {}; +// --- 3. Billing Address Details HTML --- +const billing = orderData.billing_address || {}; - // Get separate numbers - const contactNumber = orderData.contact_number || orderData.phone; +// Contact Number (from Contact field only) +const contactNumber = + orderData.note_attributes?.find?.( + (attr) => attr.name === 'Contact Number' + )?.value || + orderData.attributes?.['Contact Number']?.contact_phone || + orderData.attributes?.['Contact Number']; - const whatsappNumber = - orderData.whatsapp_number || - orderData.attributes?.['Whatsapp Number']; +// WhatsApp Number +const whatsappNumber = + orderData.note_attributes?.find?.( + (attr) => attr.name === 'Whatsapp Number' + )?.value || + orderData.attributes?.['Whatsapp Number'] || + billing.phone || + orderData.phone; - let billingAddressHtml = ''; - if (billing.first_name || billing.last_name) { - billingAddressHtml += `${billing.first_name || ''} ${billing.last_name || ''}
`; - } +let billingAddressHtml = ''; - if (billing.address1) billingAddressHtml += `${billing.address1}
`; - if (billing.address2) billingAddressHtml += `${billing.address2}
`; +if (billing.first_name || billing.last_name) { + billingAddressHtml += `${billing.first_name || ''} ${billing.last_name || ''}
`; +} - if (billing.city || billing.province || billing.zip) { - billingAddressHtml += `${billing.city || ''} ${billing.province || ''} ${billing.zip || ''}
`; - } +if (billing.address1) { + billingAddressHtml += `${billing.address1}
`; +} - if (billing.country) { - billingAddressHtml += `${billing.country}
`; - } +if (billing.address2) { + billingAddressHtml += `${billing.address2}
`; +} - // Show contact number - if (contactNumber) { - billingAddressHtml += `Contact: ${contactNumber}
`; - } +if (billing.city || billing.province || billing.zip) { + billingAddressHtml += `${billing.city || ''} ${billing.province || ''} ${billing.zip || ''}
`; +} - // Show WhatsApp number separately - if (whatsappNumber) { - billingAddressHtml += `WhatsApp: ${whatsappNumber}`; - } +if (billing.country) { + billingAddressHtml += `${billing.country}
`; +} + +// Show WhatsApp +if (whatsappNumber) { + billingAddressHtml += `WhatsApp: ${whatsappNumber}`; +} + +// Show Contact Number +if (contactNumber) { + billingAddressHtml += `
Contact Number: ${contactNumber}`; +} const paymentMethod = orderData.gateway || 'Request Quote'; const shippingMethod = orderData.shipping_lines?.[0]?.title || 'Economy'; From 80170407080dfa7220f186aca417688d4316c447 Mon Sep 17 00:00:00 2001 From: selvi Date: Mon, 22 Jun 2026 19:40:00 +0530 Subject: [PATCH 07/12] mail number fixed --- mailer.js | 74 +++++++++++++++++-------------------------------------- 1 file changed, 23 insertions(+), 51 deletions(-) diff --git a/mailer.js b/mailer.js index 322a974..59cc28d 100644 --- a/mailer.js +++ b/mailer.js @@ -72,58 +72,30 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer, shippingLa `; } -// --- 3. Billing Address Details HTML --- -const billing = orderData.billing_address || {}; + // --- 3. Billing Address Details HTML --- + const billing = orderData.billing_address || {}; + const contactNumber = orderData.note_attributes?.find?.((attr) => attr.name === 'Contact Number')?.value + || orderData.attributes?.['Contact Number']?.contact_phone + || orderData.attributes?.['Contact Number'] + || orderData.contact_phone + || orderData.attributes?.contact_phone; -// Contact Number (from Contact field only) -const contactNumber = - orderData.note_attributes?.find?.( - (attr) => attr.name === 'Contact Number' - )?.value || - orderData.attributes?.['Contact Number']?.contact_phone || - orderData.attributes?.['Contact Number']; - -// WhatsApp Number -const whatsappNumber = - orderData.note_attributes?.find?.( - (attr) => attr.name === 'Whatsapp Number' - )?.value || - orderData.attributes?.['Whatsapp Number'] || - billing.phone || - orderData.phone; - - -let billingAddressHtml = ''; - -if (billing.first_name || billing.last_name) { - billingAddressHtml += `${billing.first_name || ''} ${billing.last_name || ''}
`; -} - -if (billing.address1) { - billingAddressHtml += `${billing.address1}
`; -} - -if (billing.address2) { - billingAddressHtml += `${billing.address2}
`; -} - -if (billing.city || billing.province || billing.zip) { - billingAddressHtml += `${billing.city || ''} ${billing.province || ''} ${billing.zip || ''}
`; -} - -if (billing.country) { - billingAddressHtml += `${billing.country}
`; -} - -// Show WhatsApp -if (whatsappNumber) { - billingAddressHtml += `WhatsApp: ${whatsappNumber}`; -} - -// Show Contact Number -if (contactNumber) { - billingAddressHtml += `
Contact Number: ${contactNumber}`; -} + let billingAddressHtml = ''; + if (billing.first_name || billing.last_name) { + billingAddressHtml += `${billing.first_name || ''} ${billing.last_name || ''}
`; + } + if (billing.address1) billingAddressHtml += `${billing.address1}
`; + if (billing.address2) billingAddressHtml += `${billing.address2}
`; + if (billing.city || billing.province || billing.zip) { + billingAddressHtml += `${billing.city || ''} ${billing.province || ''} ${billing.zip || ''}
`; + } + if (billing.country) billingAddressHtml += `${billing.country}
`; + if (billing.phone || orderData.phone) { + billingAddressHtml += `${billing.phone || orderData.phone}`; + } + if (contactNumber) { + billingAddressHtml += `
Contact: ${contactNumber}`; + } const paymentMethod = orderData.gateway || 'Request Quote'; const shippingMethod = orderData.shipping_lines?.[0]?.title || 'Economy'; From a6b29d98eb56c6a4df92669c2547de7214d5071e Mon Sep 17 00:00:00 2001 From: selvi Date: Mon, 22 Jun 2026 19:44:59 +0530 Subject: [PATCH 08/12] undo server code --- server.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index 01c99ef..6fee522 100644 --- a/server.js +++ b/server.js @@ -206,10 +206,14 @@ app.post('/create-order', async (req, res) => { } }; - orderPayload.order.note_attributes = [ - { name: "Contact Number", value: customerData.contact_number || "" }, - { name: "Courier", value: customerData.courier || "" } - ]; + if (customerData.contact_phone || customerData.contactNumber || customerData.contact_number) { + orderPayload.order.note_attributes = [ + { + name: 'Contact Number', + value: customerData.contact_phone || customerData.contactNumber || customerData.contact_number + } + ]; + } const shopifyResponse = await fetch(`https://${process.env.SHOPIFY_STORE_DOMAIN}/admin/api/2024-01/orders.json`, { method: 'POST', From 8247fffe364be454a58cb2b7d8e9ec99053e1b97 Mon Sep 17 00:00:00 2001 From: selvi Date: Mon, 22 Jun 2026 19:58:19 +0530 Subject: [PATCH 09/12] cors fixes --- server.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 6fee522..ad3f866 100644 --- a/server.js +++ b/server.js @@ -7,7 +7,11 @@ const { generateShippingLabelPDF } = require('./shippingLabelGenerator'); const { sendEmailWithAttachment } = require('./mailer'); const app = express(); -app.use(cors()); // Allow frontend Shopify store to call this server +app.use(cors({ + origin: '*', // Allow all origins (you can restrict this to 'https://rayaarishop.com' in production) + methods: ['GET', 'POST', 'OPTIONS', 'PUT', 'PATCH', 'DELETE'], + allowedHeaders: ['Origin', 'X-Requested-With', 'Content-Type', 'Accept', 'Authorization', 'X-Shopify-Hmac-Sha256', 'X-Shopify-Access-Token'] +})); // Allow frontend Shopify store to call this server const PORT = process.env.PORT || 3000; // Middleware to capture raw body for Shopify webhook HMAC verification From a47974b536fa9a94372025be4ef6ddb6cd741eb4 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 22 Jun 2026 18:34:24 +0000 Subject: [PATCH 10/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 83efd4b..4ef9523 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This is a custom Node.js Express server that listens for Shopify `orders/create` - Node.js (v14 or higher) - A Shopify Store -- An Email Account (e.g., Gmail, SendGrid) to send emails via SMTP. +- An Email Account (e.g ., Gmail, SendGrid) to send emails via SMTP. ## Setup From 89218f5fb77be22d117ece2b86873d65e5632b91 Mon Sep 17 00:00:00 2001 From: selvi Date: Tue, 23 Jun 2026 10:33:39 +0530 Subject: [PATCH 11/12] both contact number display --- mailer.js | 9 +++++---- pdfGenerator.js | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/mailer.js b/mailer.js index 59cc28d..e0e9a0c 100644 --- a/mailer.js +++ b/mailer.js @@ -90,11 +90,12 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer, shippingLa billingAddressHtml += `${billing.city || ''} ${billing.province || ''} ${billing.zip || ''}
`; } if (billing.country) billingAddressHtml += `${billing.country}
`; - if (billing.phone || orderData.phone) { - billingAddressHtml += `${billing.phone || orderData.phone}`; - } if (contactNumber) { - billingAddressHtml += `
Contact: ${contactNumber}`; + billingAddressHtml += `WhatsApp: ${contactNumber}`; + } + if (billing.phone || orderData.phone) { + if (contactNumber) billingAddressHtml += `
`; + billingAddressHtml += `Contact Number: ${billing.phone || orderData.phone}`; } const paymentMethod = orderData.gateway || 'Request Quote'; diff --git a/pdfGenerator.js b/pdfGenerator.js index fe430a0..d0cda6f 100644 --- a/pdfGenerator.js +++ b/pdfGenerator.js @@ -172,12 +172,13 @@ const generateInvoicePDF = async (orderData) => { doc.text(orderData.email || orderData.contact_email, 40, billTextY); billTextY += 13; } - if (billing.phone || orderData.phone) { - doc.text(billing.phone || orderData.phone, 40, billTextY); + if (customContactNumber) { + doc.text(`WhatsApp: ${customContactNumber}`, 40, billTextY); billTextY += 13; } - if (customContactNumber) { - doc.text(`Contact: ${customContactNumber}`, 40, billTextY); + if (billing.phone || orderData.phone) { + doc.text(`Contact Number: ${billing.phone || orderData.phone}`, 40, billTextY); + billTextY += 13; } // Order Details (Right) From 4e1b3b89636d24997f8af42fb698074ac6105eef Mon Sep 17 00:00:00 2001 From: selvi Date: Tue, 23 Jun 2026 10:54:53 +0530 Subject: [PATCH 12/12] both contact number display --- mailer.js | 17 +++++++---------- pdfGenerator.js | 10 +++------- server.js | 7 ++++--- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/mailer.js b/mailer.js index e0e9a0c..85f1de9 100644 --- a/mailer.js +++ b/mailer.js @@ -74,11 +74,8 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer, shippingLa // --- 3. Billing Address Details HTML --- const billing = orderData.billing_address || {}; - const contactNumber = orderData.note_attributes?.find?.((attr) => attr.name === 'Contact Number')?.value - || orderData.attributes?.['Contact Number']?.contact_phone - || orderData.attributes?.['Contact Number'] - || orderData.contact_phone - || orderData.attributes?.contact_phone; + const whatsappNumber = orderData.note_attributes?.find?.((attr) => attr.name === 'WhatsApp Number')?.value; + const contactNumber = billing.phone || orderData.phone; let billingAddressHtml = ''; if (billing.first_name || billing.last_name) { @@ -90,12 +87,12 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer, shippingLa billingAddressHtml += `${billing.city || ''} ${billing.province || ''} ${billing.zip || ''}
`; } if (billing.country) billingAddressHtml += `${billing.country}
`; - if (contactNumber) { - billingAddressHtml += `WhatsApp: ${contactNumber}`; + if (whatsappNumber) { + billingAddressHtml += `WhatsApp: ${whatsappNumber}`; } - if (billing.phone || orderData.phone) { - if (contactNumber) billingAddressHtml += `
`; - billingAddressHtml += `Contact Number: ${billing.phone || orderData.phone}`; + if (contactNumber) { + if (whatsappNumber) billingAddressHtml += `
`; + billingAddressHtml += `Contact Number: ${contactNumber}`; } const paymentMethod = orderData.gateway || 'Request Quote'; diff --git a/pdfGenerator.js b/pdfGenerator.js index d0cda6f..69b9d7c 100644 --- a/pdfGenerator.js +++ b/pdfGenerator.js @@ -132,11 +132,7 @@ const generateInvoicePDF = async (orderData) => { // Bill To (Left) const billing = orderData.billing_address || {}; - const customContactNumber = orderData.note_attributes?.find?.((attr) => attr.name === 'Contact Number')?.value - || orderData.attributes?.['Contact Number']?.contact_phone - || orderData.attributes?.['Contact Number'] - || orderData.contact_phone - || orderData.attributes?.contact_phone; + const whatsappNumber = orderData.note_attributes?.find?.((attr) => attr.name === 'WhatsApp Number')?.value; doc.fontSize(11) .font('Helvetica-Bold') @@ -172,8 +168,8 @@ const generateInvoicePDF = async (orderData) => { doc.text(orderData.email || orderData.contact_email, 40, billTextY); billTextY += 13; } - if (customContactNumber) { - doc.text(`WhatsApp: ${customContactNumber}`, 40, billTextY); + if (whatsappNumber) { + doc.text(`WhatsApp: ${whatsappNumber}`, 40, billTextY); billTextY += 13; } if (billing.phone || orderData.phone) { diff --git a/server.js b/server.js index ad3f866..9a86668 100644 --- a/server.js +++ b/server.js @@ -210,11 +210,12 @@ app.post('/create-order', async (req, res) => { } }; - if (customerData.contact_phone || customerData.contactNumber || customerData.contact_number) { + const whatsappNumber = customerData.whatsapp_number || customerData.contact_phone || customerData.contactNumber; + if (whatsappNumber) { orderPayload.order.note_attributes = [ { - name: 'Contact Number', - value: customerData.contact_phone || customerData.contactNumber || customerData.contact_number + name: 'WhatsApp Number', + value: whatsappNumber } ]; }