backend-manager 5.0.145 → 5.0.146

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "5.0.145",
3
+ "version": "5.0.146",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -10,7 +10,12 @@ module.exports = async function ({ before, after, order, uid, userDoc, assistant
10
10
  const brandName = assistant.Manager.config.brand?.name || '';
11
11
  const planName = after.product?.name || '';
12
12
 
13
- assistant.log(`Transition [subscription/new-subscription]: uid=${uid}, product=${after.product?.id}, frequency=${after.payment?.frequency}, trial=${isTrial}`);
13
+ // Pre-compute discount values for the email template
14
+ const price = parseFloat(order.unified?.payment?.price || 0);
15
+ const discount = order.discount;
16
+ const hasPromoDiscount = discount?.valid === true && discount?.percent > 0;
17
+
18
+ assistant.log(`Transition [subscription/new-subscription]: uid=${uid}, product=${after.product?.id}, frequency=${after.payment?.frequency}, trial=${isTrial}, discount=${hasPromoDiscount ? discount.code : 'none'}`);
14
19
 
15
20
  sendOrderEmail({
16
21
  template: 'main/order/confirmation',
@@ -26,6 +31,16 @@ module.exports = async function ({ before, after, order, uid, userDoc, assistant
26
31
  ...(isTrial && after.trial?.expires?.timestamp && {
27
32
  trialExpires: formatDate(after.trial.expires.timestamp),
28
33
  }),
34
+ ...(hasPromoDiscount && {
35
+ promoCode: discount.code,
36
+ promoPercent: discount.percent,
37
+ promoSavings: (price * discount.percent / 100).toFixed(2),
38
+ }),
39
+ totalToday: isTrial
40
+ ? '0.00'
41
+ : hasPromoDiscount
42
+ ? (price - (price * discount.percent / 100)).toFixed(2)
43
+ : price.toFixed(2),
29
44
  },
30
45
  },
31
46
  },