backend-manager 2.5.84 → 2.5.86

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": "2.5.84",
3
+ "version": "2.5.86",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -190,9 +190,19 @@ SubscriptionResolver.prototype.resolve = function (options) {
190
190
  } else if (profile.processor === 'chargebee') {
191
191
  // Set status
192
192
  // subscription: https://apidocs.chargebee.com/docs/api/subscriptions?prod_cat_ver=2#subscription_status
193
- // future The subscription is scheduled to start at a future date. in_trial The subscription is in trial. active The subscription is active and will be charged for automatically based on the items in it. non_renewing The subscription will be canceled at the end of the current term. paused The subscription is paused. The subscription will not renew while in this state. cancelled The subscription has been canceled and is no longer in service.
193
+ // future The subscription is scheduled to start at a future date.
194
+ // in_trial The subscription is in trial.
195
+ // active The subscription is active and will be charged for automatically based on the items in it.
196
+ // non_renewing The subscription will be canceled at the end of the current term.
197
+ // paused The subscription is paused. The subscription will not renew while in this state.
198
+ // cancelled The subscription has been canceled and is no longer in service.
194
199
  if (['in_trial', 'active'].includes(resource.status)) {
195
200
  resolved.status = 'active';
201
+
202
+ // If there's a due invoice, it's suspended
203
+ if (resource.total_dues > 0) {
204
+ resolved.status = 'suspended';
205
+ }
196
206
  } else if (['paused'].includes(resource.status)) {
197
207
  resolved.status = 'suspended';
198
208
  } else {
@@ -212,7 +222,16 @@ SubscriptionResolver.prototype.resolve = function (options) {
212
222
  (
213
223
  get(resource, 'current_term_start', 0)
214
224
  ) * 1000
215
- )
225
+ )
226
+ // if (resource.total_dues > 0) {
227
+ // resolved.expires.timestamp = moment(0);
228
+ // } else {
229
+ // resolved.expires.timestamp = moment(
230
+ // (
231
+ // get(resource, 'current_term_start', 0)
232
+ // ) * 1000
233
+ // )
234
+ // }
216
235
 
217
236
  // Set cancelled
218
237
  if (resolved.status === 'cancelled') {
@@ -222,11 +241,16 @@ SubscriptionResolver.prototype.resolve = function (options) {
222
241
  }
223
242
 
224
243
  // Set last payment
225
- if (resource.total_dues) {
226
- resolved.lastPayment.amount = resource.total_dues / 100;
244
+ if (resource.total_dues > 0) {
245
+ resolved.lastPayment.amount = 0;
227
246
  resolved.lastPayment.date.timestamp = moment(
228
247
  (resource.due_since || 0) * 1000
229
248
  );
249
+ } else {
250
+ resolved.lastPayment.amount = resource.plan_amount / 100;
251
+ resolved.lastPayment.date.timestamp = moment(
252
+ (resource.current_term_start || 0) * 1000
253
+ );
230
254
  }
231
255
 
232
256
  // Get trial
@@ -296,6 +320,7 @@ SubscriptionResolver.prototype.resolve = function (options) {
296
320
  }
297
321
 
298
322
  // Set last payment
323
+ // TODO: check if suspended payments are handled correctly when using resource.latest_invoice.amount_paid
299
324
  if (resource.latest_invoice) {
300
325
  resolved.lastPayment.amount = resource.latest_invoice.amount_paid / 100;
301
326
  resolved.lastPayment.date.timestamp = moment(
@@ -413,8 +438,11 @@ SubscriptionResolver.prototype.resolve = function (options) {
413
438
  }
414
439
  }
415
440
 
416
- // If there was NEVER any payment sent AND they are not trialing
417
- if (!resolved.payment.completed && !resolved.trial.active) {
441
+ // If they are not trialing AND there was NEVER any payment sent OR the last payment failed, then set the expiration to 0
442
+ if (
443
+ !resolved.trial.active
444
+ && (!resolved.payment.completed || resolved.lastPayment.amount === 0)
445
+ ) {
418
446
  resolved.expires.timestamp = moment(0);
419
447
  }
420
448