feat: add SwitchOffer component to promote switching from competitors for enhanced user engagement

This commit is contained in:
Dries Augustyns
2026-05-12 21:48:35 +02:00
parent 715961c007
commit 6195b39f3d
20 changed files with 186 additions and 17 deletions
+8
View File
@@ -230,6 +230,14 @@ export class Users {
client_reference_id: project.id, // Store project ID for webhook
line_items: lineItems,
...(checkoutCurrency && {currency: checkoutCurrency}),
custom_fields: [
{
key: 'promo_code',
label: {type: 'custom', custom: 'Promo code'},
type: 'text',
optional: true,
},
],
subscription_data: {
billing_cycle_anchor: billingCycleAnchor,
},
+15 -1
View File
@@ -530,10 +530,24 @@ export class Webhooks {
},
});
// Base onboarding credit: refund the 1-unit card-verification charge
let creditBalance = -100;
// Switching-offer promo: 2 extra units of credit if the customer typed SWITCH
// into the Promo code custom field on Stripe Checkout.
const promoField = session.custom_fields?.find((f) => f.key === 'promo_code');
const promoCode = promoField?.text?.value?.trim().toUpperCase();
if (promoCode === 'SWITCH') {
creditBalance -= 200;
signale.success(`[WEBHOOK] SWITCH promo applied for project ${projectId}`);
} else if (promoCode) {
signale.info(`[WEBHOOK] Unknown promo code "${promoCode}" entered for project ${projectId}`);
}
// Update Stripe customer name to match project name and add credit for onboarding fee
await stripe.customers.update(customerId, {
name: updatedProject.name,
balance: -100,
balance: creditBalance,
});
signale.success(`[WEBHOOK] Checkout completed for project ${projectId}`);