backend-manager 2.5.37 → 2.5.38
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
|
@@ -12,10 +12,13 @@ SubscriptionResolver.prototype.resolve = function () {
|
|
|
12
12
|
const self = this;
|
|
13
13
|
|
|
14
14
|
const resolved = {
|
|
15
|
-
status: '',
|
|
15
|
+
status: 'cancelled',
|
|
16
16
|
resource: {
|
|
17
17
|
id: '',
|
|
18
18
|
},
|
|
19
|
+
payment: {
|
|
20
|
+
completed: false,
|
|
21
|
+
},
|
|
19
22
|
expires: {
|
|
20
23
|
timestamp: moment(0),
|
|
21
24
|
timestampUNIX: moment(0),
|
|
@@ -29,77 +32,105 @@ SubscriptionResolver.prototype.resolve = function () {
|
|
|
29
32
|
const profile = self.profile;
|
|
30
33
|
const resource = self.resource;
|
|
31
34
|
|
|
35
|
+
// Process differently based on each provider
|
|
32
36
|
if (profile.processor === 'paypal') {
|
|
33
|
-
|
|
37
|
+
// Set status
|
|
38
|
+
if (['ACTIVE'].includes(resource.status)) {
|
|
34
39
|
resolved.status = 'active';
|
|
35
|
-
} else if (resource.status
|
|
40
|
+
} else if (['SUSPENDED'].includes(resource.status)) {
|
|
36
41
|
resolved.status = 'suspended';
|
|
37
42
|
} else {
|
|
38
43
|
resolved.status = 'cancelled';
|
|
39
44
|
}
|
|
40
|
-
|
|
45
|
+
|
|
46
|
+
// Set resource ID
|
|
47
|
+
resolved.resource.id = resource.id;
|
|
48
|
+
|
|
49
|
+
// Set expiration and start
|
|
41
50
|
resolved.expires.timestamp = moment(
|
|
42
51
|
get(resource, 'billing_info.last_payment.time', 0)
|
|
43
52
|
)
|
|
44
53
|
resolved.start.timestamp = moment(
|
|
45
54
|
get(resource, 'start_time', 0)
|
|
46
|
-
)
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
// Set completed
|
|
58
|
+
resolved.payment.completed = !['APPROVAL_PENDING', 'APPROVED'].includes(resource.status);
|
|
47
59
|
} else if (profile.processor === 'chargebee') {
|
|
48
|
-
|
|
60
|
+
// Set status
|
|
61
|
+
if (['in_trial', 'active'].includes(resource.status)) {
|
|
49
62
|
resolved.status = 'active';
|
|
50
|
-
} else if (resource.status
|
|
63
|
+
} else if (['paused'].includes(resource.status)) {
|
|
51
64
|
resolved.status = 'suspended';
|
|
52
65
|
} else {
|
|
53
66
|
resolved.status = 'cancelled';
|
|
54
67
|
}
|
|
55
|
-
|
|
68
|
+
|
|
69
|
+
// Set resource ID
|
|
70
|
+
resolved.resource.id = resource.id;
|
|
71
|
+
|
|
72
|
+
// Set expiration and start
|
|
56
73
|
resolved.expires.timestamp = moment(
|
|
57
74
|
get(resource, 'current_term_start', 0) * 1000
|
|
58
75
|
)
|
|
59
76
|
resolved.start.timestamp = moment(
|
|
60
77
|
get(resource, 'created_at', 0) * 1000
|
|
61
78
|
)
|
|
79
|
+
|
|
80
|
+
// Set completed
|
|
81
|
+
resolved.payment.completed = !['future'].includes(resource.status);
|
|
62
82
|
} else if (profile.processor === 'stripe') {
|
|
63
|
-
|
|
83
|
+
// Set status
|
|
84
|
+
if (['trialing', 'active'].includes(resource.status)) {
|
|
64
85
|
resolved.status = 'active';
|
|
65
|
-
}
|
|
86
|
+
} if (['past_due', 'unpaid'].includes(resource.status)) {
|
|
66
87
|
resolved.status = 'suspended';
|
|
67
88
|
} else {
|
|
68
89
|
resolved.status = 'cancelled';
|
|
69
90
|
}
|
|
70
|
-
|
|
91
|
+
|
|
92
|
+
// Set resource ID
|
|
93
|
+
resolved.resource.id = resource.id;
|
|
94
|
+
|
|
95
|
+
// Set expiration and start
|
|
71
96
|
resolved.expires.timestamp = moment(
|
|
72
97
|
get(resource, 'current_period_start', 0) * 1000
|
|
73
|
-
)
|
|
98
|
+
);
|
|
74
99
|
resolved.start.timestamp = moment(
|
|
75
100
|
get(resource, 'start_date', 0) * 1000
|
|
76
|
-
)
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// Set completed
|
|
104
|
+
resolved.payment.completed = !['incomplete', 'incomplete_expired'].includes(resource.status);
|
|
77
105
|
} else if (profile.processor === 'coinbase') {
|
|
78
|
-
//
|
|
79
|
-
// const completed = resource.confirmed_at;
|
|
80
|
-
const completed = resource.payments.find(p => p.status === 'CONFIRMED');
|
|
106
|
+
// Set status
|
|
81
107
|
resolved.status = 'cancelled';
|
|
82
108
|
|
|
83
|
-
|
|
109
|
+
// Set resource ID
|
|
110
|
+
resolved.resource.id = resource.id;
|
|
111
|
+
|
|
112
|
+
// Set expiration and start
|
|
84
113
|
resolved.expires.timestamp = moment(
|
|
85
114
|
get(resource, 'created_at', 0)
|
|
86
|
-
)
|
|
115
|
+
);
|
|
87
116
|
resolved.start.timestamp = moment(
|
|
88
117
|
get(resource, 'created_at', 0)
|
|
89
118
|
);
|
|
90
119
|
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
if (!completed) {
|
|
94
|
-
resolved.expires.timestamp = moment(0);
|
|
95
|
-
}
|
|
120
|
+
// Set completed
|
|
121
|
+
resolved.payment.completed = resource.payments.find(p => p.status === 'CONFIRMED');
|
|
96
122
|
}
|
|
97
123
|
|
|
124
|
+
// If there was NEVER any payment sent
|
|
125
|
+
if (!resolved.payment.completed) {
|
|
126
|
+
resolved.expires.timestamp = moment(0);
|
|
127
|
+
}
|
|
128
|
+
|
|
98
129
|
// Fix expires by adding time to the date of last payment
|
|
99
130
|
if (resolved.status === 'active') {
|
|
100
131
|
resolved.expires.timestamp.add(1, 'year').add(30, 'days');
|
|
101
132
|
} else {
|
|
102
|
-
const freq = profile.details.planFrequency;
|
|
133
|
+
const freq = profile.details.planFrequency || 'monthly';
|
|
103
134
|
if (freq === 'annually') {
|
|
104
135
|
resolved.expires.timestamp.add(1, 'year');
|
|
105
136
|
} else if (freq === 'monthly') {
|