backend-manager 2.5.64 → 2.5.66
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
|
@@ -162,6 +162,8 @@ Module.prototype.resolveCommand = function (command) {
|
|
|
162
162
|
const self = this;
|
|
163
163
|
const originalCommand = command;
|
|
164
164
|
|
|
165
|
+
command = command || '';
|
|
166
|
+
|
|
165
167
|
// Start
|
|
166
168
|
if (false) {
|
|
167
169
|
|
|
@@ -218,8 +220,6 @@ Module.prototype.resolveCommand = function (command) {
|
|
|
218
220
|
// command = 'error:error';
|
|
219
221
|
}
|
|
220
222
|
|
|
221
|
-
command = command || '';
|
|
222
|
-
|
|
223
223
|
// Check local path
|
|
224
224
|
const resolvedPath = resolveApiPath(command);
|
|
225
225
|
|
|
@@ -27,6 +27,9 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
27
27
|
timestamp: moment(0),
|
|
28
28
|
timestampUNIX: moment(0),
|
|
29
29
|
},
|
|
30
|
+
trial: {
|
|
31
|
+
active: false,
|
|
32
|
+
}
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
const profile = self.profile;
|
|
@@ -42,10 +45,22 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
42
45
|
// Process differently based on each provider
|
|
43
46
|
if (profile.processor === 'paypal') {
|
|
44
47
|
// Set status
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
/*
|
|
49
|
+
subscription: https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get
|
|
50
|
+
APPROVAL_PENDING. The subscription is created but not yet approved by the buyer.
|
|
51
|
+
APPROVED. The buyer has approved the subscription.
|
|
52
|
+
ACTIVE. The subscription is active.
|
|
53
|
+
SUSPENDED. The subscription is suspended.
|
|
54
|
+
CANCELLED. The subscription is cancelled.
|
|
55
|
+
EXPIRED. The subscription is expired.
|
|
56
|
+
|
|
57
|
+
order: https://developer.paypal.com/docs/api/orders/v2/#orders_get
|
|
58
|
+
CREATED. The order was created with the specified context.
|
|
59
|
+
SAVED. The order was saved and persisted. The order status continues to be in progress until a capture is made with final_capture = true for all purchase units within the order.
|
|
60
|
+
APPROVED. The customer approved the payment through the PayPal wallet or another form of guest or unbranded payment. For example, a card, bank account, or so on.
|
|
61
|
+
VOIDED. All purchase units in the order are voided. COMPLETED. The payment was authorized or the authorized payment was captured for the order.
|
|
62
|
+
PAYER_ACTION_REQUIRED. The order requires an action from the payer (e.g. 3DS authentication). Redirect the payer to the "rel":"payer-action" HATEOAS link returned as part of the response prior to authorizing or capturing the order.
|
|
63
|
+
*/
|
|
49
64
|
if (['ACTIVE'].includes(resource.status)) {
|
|
50
65
|
resolved.status = 'active';
|
|
51
66
|
} else if (['SUSPENDED'].includes(resource.status)) {
|
|
@@ -57,10 +72,25 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
57
72
|
// Set resource ID
|
|
58
73
|
resolved.resource.id = resource.id;
|
|
59
74
|
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
75
|
+
// Get trial
|
|
76
|
+
const trialTenure = get(resource, 'billing_info.cycle_executions', []).find((cycle) => cycle.tenure_type === 'TRIAL');
|
|
77
|
+
const regularTenure = get(resource, 'billing_info.cycle_executions', []).find((cycle) => cycle.tenure_type === 'REGULAR');
|
|
78
|
+
|
|
79
|
+
// Resolve trial
|
|
80
|
+
if (trialTenure && regularTenure && regularTenure.cycles_completed === 0) {
|
|
81
|
+
resolved.trial.active = true;
|
|
82
|
+
|
|
83
|
+
// Set expiration and start
|
|
84
|
+
resolved.expires.timestamp = moment(
|
|
85
|
+
get(resource, 'billing_info.next_billing_time', 0)
|
|
86
|
+
)
|
|
87
|
+
} else {
|
|
88
|
+
// Set expiration and start
|
|
89
|
+
resolved.expires.timestamp = moment(
|
|
90
|
+
get(resource, 'billing_info.last_payment.time', 0)
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
64
94
|
resolved.start.timestamp = moment(
|
|
65
95
|
get(resource, 'start_time', 0)
|
|
66
96
|
)
|
|
@@ -71,6 +101,7 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
71
101
|
} else {
|
|
72
102
|
resolved.payment.completed = !['CREATED', 'SAVED', 'APPROVED', 'VOIDED', 'PAYER_ACTION_REQUIRED'].includes(resource.status);
|
|
73
103
|
}
|
|
104
|
+
|
|
74
105
|
} else if (profile.processor === 'chargebee') {
|
|
75
106
|
// Set status
|
|
76
107
|
// subscription: https://apidocs.chargebee.com/docs/api/subscriptions?prod_cat_ver=2#subscription_status
|
|
@@ -86,18 +117,34 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
86
117
|
// Set resource ID
|
|
87
118
|
resolved.resource.id = resource.id;
|
|
88
119
|
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
120
|
+
// Get trial
|
|
121
|
+
if (resource.status === 'in_trial') {
|
|
122
|
+
resolved.trial.active = true;
|
|
123
|
+
|
|
124
|
+
// Set expiration and start
|
|
125
|
+
resolved.expires.timestamp = moment(
|
|
126
|
+
(
|
|
127
|
+
get(resource, 'trial_end', 0)
|
|
128
|
+
) * 1000
|
|
129
|
+
)
|
|
130
|
+
} else {
|
|
131
|
+
// Set expiration and start
|
|
132
|
+
resolved.expires.timestamp = moment(
|
|
133
|
+
(
|
|
134
|
+
get(resource, 'current_term_start', 0)
|
|
135
|
+
) * 1000
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
93
139
|
resolved.start.timestamp = moment(
|
|
94
140
|
get(resource, 'created_at', 0) * 1000
|
|
95
|
-
)
|
|
141
|
+
)
|
|
96
142
|
|
|
97
143
|
// Set completed
|
|
98
144
|
if (true) {
|
|
99
145
|
resolved.payment.completed = !['future'].includes(resource.status);
|
|
100
146
|
}
|
|
147
|
+
|
|
101
148
|
} else if (profile.processor === 'stripe') {
|
|
102
149
|
// Subscription: https://stripe.com/docs/api/subscriptions/object#subscription_object-status
|
|
103
150
|
// incomplete, incomplete_expired, trialing, active, past_due, canceled, or unpaid
|
|
@@ -116,10 +163,23 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
116
163
|
// Set resource ID
|
|
117
164
|
resolved.resource.id = resource.id;
|
|
118
165
|
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
166
|
+
// Get trial
|
|
167
|
+
if (resource.status === 'trialing') {
|
|
168
|
+
resolved.trial.active = true;
|
|
169
|
+
|
|
170
|
+
// Set expiration and start
|
|
171
|
+
resolved.expires.timestamp = moment(
|
|
172
|
+
(
|
|
173
|
+
get(resource, 'trial_end', 0)
|
|
174
|
+
) * 1000
|
|
175
|
+
)
|
|
176
|
+
} else {
|
|
177
|
+
// Set expiration and start
|
|
178
|
+
resolved.expires.timestamp = moment(
|
|
179
|
+
get(resource, 'current_period_start', 0) * 1000
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
123
183
|
resolved.start.timestamp = moment(
|
|
124
184
|
get(resource, 'start_date', 0) * 1000
|
|
125
185
|
);
|
|
@@ -130,6 +190,7 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
130
190
|
} else if (resource.object === 'payment_intent') {
|
|
131
191
|
resolved.payment.completed = !['requires_payment_method', 'requires_confirmation', 'requires_action', 'processing', 'requires_capture', 'canceled'].includes(resource.status);
|
|
132
192
|
}
|
|
193
|
+
|
|
133
194
|
} else if (profile.processor === 'coinbase') {
|
|
134
195
|
// Set status
|
|
135
196
|
resolved.status = 'cancelled';
|
|
@@ -137,6 +198,11 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
137
198
|
// Set resource ID
|
|
138
199
|
resolved.resource.id = resource.id;
|
|
139
200
|
|
|
201
|
+
// Get trial
|
|
202
|
+
if (true) {
|
|
203
|
+
resolved.trial.active = false;
|
|
204
|
+
}
|
|
205
|
+
|
|
140
206
|
// Set expiration and start
|
|
141
207
|
resolved.expires.timestamp = moment(
|
|
142
208
|
get(resource, 'created_at', 0)
|
|
@@ -151,25 +217,28 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
151
217
|
}
|
|
152
218
|
}
|
|
153
219
|
|
|
154
|
-
//
|
|
155
|
-
if (!resolved.payment.completed) {
|
|
156
|
-
resolved.expires.timestamp = moment(0);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Fix expires by adding time to the date of last payment
|
|
220
|
+
// Fix expiry by adding time to the date of last payment
|
|
160
221
|
if (resolved.status === 'active') {
|
|
161
222
|
resolved.expires.timestamp.add(1, 'year').add(30, 'days');
|
|
162
223
|
} else {
|
|
163
|
-
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
224
|
+
// If trial, it's already set to the trial end above
|
|
225
|
+
if (!resolved.trial.active) {
|
|
226
|
+
const freq = profile.details.planFrequency || 'monthly';
|
|
227
|
+
if (freq === 'annually') {
|
|
228
|
+
resolved.expires.timestamp.add(1, 'year');
|
|
229
|
+
} else if (freq === 'monthly') {
|
|
230
|
+
resolved.expires.timestamp.add(1, 'month');
|
|
231
|
+
} else if (freq === 'daily') {
|
|
232
|
+
resolved.expires.timestamp.add(1, 'day');
|
|
233
|
+
}
|
|
170
234
|
}
|
|
171
235
|
}
|
|
172
236
|
|
|
237
|
+
// If there was NEVER any payment sent AND they are not trialing
|
|
238
|
+
if (!resolved.payment.completed && !resolved.trial.active) {
|
|
239
|
+
resolved.expires.timestamp = moment(0);
|
|
240
|
+
}
|
|
241
|
+
|
|
173
242
|
// Fix timestamps
|
|
174
243
|
resolved.expires.timestampUNIX = resolved.expires.timestamp.unix()
|
|
175
244
|
resolved.expires.timestamp = resolved.expires.timestamp.toISOString()
|
|
@@ -177,8 +246,6 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
177
246
|
resolved.start.timestampUNIX = resolved.start.timestamp.unix()
|
|
178
247
|
resolved.start.timestamp = resolved.start.timestamp.toISOString()
|
|
179
248
|
|
|
180
|
-
// console.log('---resolved', resolved);
|
|
181
|
-
|
|
182
249
|
if (options.log) {
|
|
183
250
|
console.log('resolved', resolved);
|
|
184
251
|
}
|
package/src/manager/index.js
CHANGED
|
@@ -7,9 +7,11 @@ const JSON5 = require('json5');
|
|
|
7
7
|
// const { debug, log, error, warn } = require('firebase-functions/lib/logger');
|
|
8
8
|
// let User;
|
|
9
9
|
// let Analytics;
|
|
10
|
+
// Paths
|
|
11
|
+
const core = './functions/core';
|
|
12
|
+
const wrappers = './functions/wrappers';
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
function Manager(exporter, options) {
|
|
14
|
+
function Manager(exporter, options) {
|
|
13
15
|
const self = this;
|
|
14
16
|
// Constants
|
|
15
17
|
self.SERVER_UUID = '11111111-1111-1111-1111-111111111111';
|
|
@@ -30,10 +32,6 @@ const JSON5 = require('json5');
|
|
|
30
32
|
Manager.prototype.init = function (exporter, options) {
|
|
31
33
|
const self = this;
|
|
32
34
|
|
|
33
|
-
// Paths
|
|
34
|
-
const core = './functions/core';
|
|
35
|
-
const wrappers = './functions/wrappers';
|
|
36
|
-
|
|
37
35
|
// Set options defaults
|
|
38
36
|
options = options || {};
|
|
39
37
|
options.initialize = typeof options.initialize === 'undefined' ? true : options.initialize;
|
|
@@ -583,6 +581,18 @@ Manager.prototype.SubscriptionResolver = function () {
|
|
|
583
581
|
return new self.libraries.SubscriptionResolver(...arguments);
|
|
584
582
|
};
|
|
585
583
|
|
|
584
|
+
// For importing API libraries
|
|
585
|
+
Manager.prototype.Api = function () {
|
|
586
|
+
const self = this;
|
|
587
|
+
// self.libraries.Api = self.libraries.Api || require('./helpers/subscription-resolver.js');
|
|
588
|
+
// return new self.libraries.Api(...arguments);
|
|
589
|
+
// return self._process((new (require(`${core}/actions/api.js`))()).init(self, { req: req, res: res, }))
|
|
590
|
+
|
|
591
|
+
const Api = (new (require(`${core}/actions/api.js`))()).init(self, { req: {}, res: {}, });
|
|
592
|
+
|
|
593
|
+
return Api;
|
|
594
|
+
};
|
|
595
|
+
|
|
586
596
|
// Manager.prototype.Utilities = function () {
|
|
587
597
|
// const self = this;
|
|
588
598
|
// self.libraries.Utilities = self.libraries.Utilities || require('./helpers/utilities.js');
|