backend-manager 3.0.7 → 3.0.9
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
|
@@ -154,7 +154,7 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
154
154
|
// Resolve
|
|
155
155
|
const processor = self[`resolve_${profile.processor}`];
|
|
156
156
|
if (processor) {
|
|
157
|
-
processor(profile, resource, resolved);
|
|
157
|
+
processor(profile, resource, resolved, options);
|
|
158
158
|
} else {
|
|
159
159
|
throw new Error('Unknown processor');
|
|
160
160
|
}
|
|
@@ -171,7 +171,7 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
171
171
|
if (resolved.status === 'active') {
|
|
172
172
|
// Set days left
|
|
173
173
|
if (resolved.trial.active) {
|
|
174
|
-
resolved.trial.daysLeft = resolved.expires.timestamp.diff(options.today, 'days');
|
|
174
|
+
resolved.trial.daysLeft = Math.abs(resolved.expires.timestamp.diff(options.today, 'days'));
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
// Set expiration
|
|
@@ -241,7 +241,7 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
241
241
|
return resolved;
|
|
242
242
|
};
|
|
243
243
|
|
|
244
|
-
SubscriptionResolver.prototype.resolve_paypal = function (profile, resource, resolved) {
|
|
244
|
+
SubscriptionResolver.prototype.resolve_paypal = function (profile, resource, resolved, options) {
|
|
245
245
|
const self = this;
|
|
246
246
|
|
|
247
247
|
// Set status
|
|
@@ -362,6 +362,22 @@ SubscriptionResolver.prototype.resolve_paypal = function (profile, resource, res
|
|
|
362
362
|
resolved.expires.timestamp = moment(
|
|
363
363
|
get(resource, 'billing_info.next_billing_time', 0)
|
|
364
364
|
)
|
|
365
|
+
|
|
366
|
+
/*
|
|
367
|
+
Special condition for PayPal #2
|
|
368
|
+
I want to put the subscription in a suspended state if it's even one day past due
|
|
369
|
+
*/
|
|
370
|
+
const trialLength = get(trialTenure, 'frequency.interval_count', 0);
|
|
371
|
+
const daysSinceStart = Math.abs(moment(options.today).diff(moment(resolved.start.timestamp), 'days'));
|
|
372
|
+
if (daysSinceStart > trialLength) {
|
|
373
|
+
resolved.status = 'suspended';
|
|
374
|
+
resolved.trial.active = false;
|
|
375
|
+
}
|
|
376
|
+
console.log('----resolved.resource.id', resolved.resource.id);
|
|
377
|
+
console.log('----resolved.start.timestamp', resolved.start.timestamp);
|
|
378
|
+
console.log('----options.today', options.today);
|
|
379
|
+
console.log('======daysSinceStart', daysSinceStart);
|
|
380
|
+
console.log('======trialLength', trialLength);
|
|
365
381
|
}
|
|
366
382
|
resolved.trial.claimed = trialClaimed;
|
|
367
383
|
|
|
@@ -396,7 +412,7 @@ SubscriptionResolver.prototype.resolve_paypal = function (profile, resource, res
|
|
|
396
412
|
return resolved;
|
|
397
413
|
}
|
|
398
414
|
|
|
399
|
-
SubscriptionResolver.prototype.resolve_chargebee = function (profile, resource, resolved) {
|
|
415
|
+
SubscriptionResolver.prototype.resolve_chargebee = function (profile, resource, resolved, options) {
|
|
400
416
|
const self = this;
|
|
401
417
|
|
|
402
418
|
// Set status
|
|
@@ -575,7 +591,7 @@ SubscriptionResolver.prototype.resolve_chargebee = function (profile, resource,
|
|
|
575
591
|
const trialStart = get(resource, 'trial_start', 0) * 1000;
|
|
576
592
|
const trialEnd = get(resource, 'trial_end', 0) * 1000;
|
|
577
593
|
const cancelledAt = get(resource, 'cancelled_at', 0) * 1000;
|
|
578
|
-
const trialDaysDifference = moment(trialEnd).diff(moment(trialStart), 'days');
|
|
594
|
+
const trialDaysDifference = Math.abs(moment(trialEnd).diff(moment(trialStart), 'days'));
|
|
579
595
|
const trialClaimed = !!trialStart && !!trialEnd && trialDaysDifference > 1;
|
|
580
596
|
if (
|
|
581
597
|
resolved.trial.active
|
|
@@ -589,7 +605,7 @@ SubscriptionResolver.prototype.resolve_chargebee = function (profile, resource,
|
|
|
589
605
|
return resolved;
|
|
590
606
|
}
|
|
591
607
|
|
|
592
|
-
SubscriptionResolver.prototype.resolve_stripe = function (profile, resource, resolved) {
|
|
608
|
+
SubscriptionResolver.prototype.resolve_stripe = function (profile, resource, resolved, options) {
|
|
593
609
|
const self = this;
|
|
594
610
|
|
|
595
611
|
// Subscription: https://stripe.com/docs/api/subscriptions/object#subscription_object-status
|
|
@@ -681,7 +697,7 @@ SubscriptionResolver.prototype.resolve_stripe = function (profile, resource, res
|
|
|
681
697
|
// Get trial
|
|
682
698
|
const trialStart = get(resource, 'trial_start', 0) * 1000;
|
|
683
699
|
const trialEnd = get(resource, 'trial_end', 0) * 1000;
|
|
684
|
-
const trialDaysDifference = moment(trialEnd).diff(moment(trialStart), 'days');
|
|
700
|
+
const trialDaysDifference = Math.abs(moment(trialEnd).diff(moment(trialStart), 'days'));
|
|
685
701
|
const trialClaimed = !!trialStart && !!trialEnd && trialDaysDifference > 1;
|
|
686
702
|
if (resource.status === 'trialing') {
|
|
687
703
|
resolved.trial.active = true;
|
|
@@ -724,7 +740,7 @@ SubscriptionResolver.prototype.resolve_stripe = function (profile, resource, res
|
|
|
724
740
|
return resolved;
|
|
725
741
|
}
|
|
726
742
|
|
|
727
|
-
SubscriptionResolver.prototype.resolve_coinbase = function (profile, resource, resolved) {
|
|
743
|
+
SubscriptionResolver.prototype.resolve_coinbase = function (profile, resource, resolved, options) {
|
|
728
744
|
const self = this;
|
|
729
745
|
|
|
730
746
|
// Setup preliminary variables
|