Alaguraj0361 2026-06-30 18:36:43 +05:30
commit 6435a014c3
4 changed files with 33 additions and 5 deletions

View File

@ -74,6 +74,9 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer, shippingLa
// --- 3. Billing Address Details HTML ---
const billing = orderData.billing_address || {};
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) {
billingAddressHtml += `${billing.first_name || ''} ${billing.last_name || ''}<br/>`;
@ -84,8 +87,12 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer, shippingLa
billingAddressHtml += `${billing.city || ''} ${billing.province || ''} ${billing.zip || ''}<br/>`;
}
if (billing.country) billingAddressHtml += `${billing.country}<br/>`;
if (billing.phone || orderData.phone) {
billingAddressHtml += `${billing.phone || orderData.phone}`;
if (whatsappNumber) {
billingAddressHtml += `WhatsApp: ${whatsappNumber}`;
}
if (contactNumber) {
if (whatsappNumber) billingAddressHtml += `<br/>`;
billingAddressHtml += `Contact Number: ${contactNumber}`;
}
const paymentMethod = orderData.gateway || 'Request Quote';

View File

@ -132,6 +132,8 @@ const generateInvoicePDF = async (orderData) => {
// Bill To (Left)
const billing = orderData.billing_address || {};
const whatsappNumber = orderData.note_attributes?.find?.((attr) => attr.name === 'WhatsApp Number')?.value;
doc.fontSize(11)
.font('Helvetica-Bold')
.fillColor(primaryColor)
@ -166,8 +168,13 @@ const generateInvoicePDF = async (orderData) => {
doc.text(orderData.email || orderData.contact_email, 40, billTextY);
billTextY += 13;
}
if (whatsappNumber) {
doc.text(`WhatsApp: ${whatsappNumber}`, 40, billTextY);
billTextY += 13;
}
if (billing.phone || orderData.phone) {
doc.text(billing.phone || orderData.phone, 40, billTextY);
doc.text(`Contact Number: ${billing.phone || orderData.phone}`, 40, billTextY);
billTextY += 13;
}
// Order Details (Right)

View File

@ -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
@ -208,6 +212,16 @@ app.post('/create-order', async (req, res) => {
}
};
const whatsappNumber = customerData.whatsapp_number || customerData.contact_phone || customerData.contactNumber;
if (whatsappNumber) {
orderPayload.order.note_attributes = [
{
name: 'WhatsApp Number',
value: whatsappNumber
}
];
}
const shopifyResponse = await fetch(`https://${process.env.SHOPIFY_STORE_DOMAIN}/admin/api/2024-01/orders.json`, {
method: 'POST',
headers: {