import Tagada from '@tagadapay/node-sdk';
const tagada = new Tagada('tgd_your_api_key');
const storeId = 'store_xxx';
// ── 1. Order confirmation ────────────────────────────────────────────
await tagada.emailTemplates.create({
storeId,
type: 'order_paid',
name: 'Order Confirmation',
subject: { en: 'Your order #{{ orderNumber }} is confirmed — {{ storeName }}' },
templateVariables: {
order_paid: {
body: {
en: `<p>Hi {{ customerFirstName }},</p>
<p>Thank you for your purchase! Your order has been confirmed.</p>
<p><strong>Order:</strong> #{{ orderNumber }}<br/>
<strong>Total:</strong> {{ orderTotal }}<br/>
<strong>Date:</strong> {{ orderDate }}</p>`,
},
},
},
active: true,
});
// ── 2. Refund notification ───────────────────────────────────────────
await tagada.emailTemplates.create({
storeId,
type: 'order_refunded',
name: 'Refund Confirmation',
subject: { en: 'Your refund for order #{{ orderNumber }} has been processed' },
templateVariables: {
order_refunded: {
body: {
en: '<p>Hi {{ customerFirstName }}, your refund of {{ refundAmount }} for order #{{ orderNumber }} has been processed. It may take 5–10 business days to appear on your statement.</p>',
},
},
},
active: true,
});
// ── 3. Subscription payment receipt ──────────────────────────────────
await tagada.emailTemplates.create({
storeId,
type: 'subscription_rebill_succeeded',
name: 'Subscription Receipt',
subject: { en: 'Payment of {{ subscriptionAmount }} confirmed — {{ storeName }}' },
templateVariables: {
subscription_rebill_succeeded: {
body: {
en: '<p>Hi {{ customerFirstName }}, your payment of {{ subscriptionAmount }} for {{ subscriptionName }} was successful. Next billing date: {{ nextBillingDate }}.</p>',
},
},
},
active: true,
});
// ── 4. Upcoming rebill notice ────────────────────────────────────────
await tagada.emailTemplates.create({
storeId,
type: 'subscription_rebill_upcoming',
name: 'Upcoming Payment Notice',
subject: { en: '{{ subscriptionAmount }} will be charged on {{ nextBillingDate }}' },
templateVariables: {
subscription_rebill_upcoming: {
body: {
en: '<p>Hi {{ customerFirstName }}, your next payment of {{ subscriptionAmount }} for {{ subscriptionName }} is scheduled for {{ nextBillingDate }}.</p>',
},
},
},
active: true,
});
// ── 5. Failed payment alert ──────────────────────────────────────────
await tagada.emailTemplates.create({
storeId,
type: 'subscription_past_due',
name: 'Payment Failed',
subject: { en: 'Action required: payment failed for {{ subscriptionName }}' },
templateVariables: {
subscription_past_due: {
body: {
en: '<p>Hi {{ customerFirstName }}, your payment of {{ subscriptionAmount }} for {{ subscriptionName }} could not be processed. Please update your payment method to avoid interruption.</p>',
},
},
},
active: true,
});
// ── 6. Cancellation confirmation ─────────────────────────────────────
await tagada.emailTemplates.create({
storeId,
type: 'subscription_canceled',
name: 'Subscription Canceled',
subject: { en: 'Your subscription to {{ subscriptionName }} has been canceled' },
templateVariables: {
subscription_canceled: {
body: {
en: '<p>Hi {{ customerFirstName }}, your subscription to {{ subscriptionName }} has been canceled. If this was a mistake, you can resubscribe at any time from your account.</p>',
},
},
},
active: true,
});
// ── 7. Abandoned checkout recovery ───────────────────────────────────
await tagada.emailTemplates.create({
storeId,
type: 'abandoned_checkout',
name: 'Cart Recovery',
subject: { en: 'You left items in your cart at {{ storeName }}' },
templateVariables: {
abandoned_checkout: {
body: {
en: '<p>Hi {{ customerFirstName }}, you left {{ cartTotal }} worth of items in your cart. Click below to complete your purchase.</p>',
},
},
},
params: { specific: { triggerDurationSinceLastActivity: '1h' } },
active: true,
});
console.log('All email templates created!');