backend-manager 2.5.75 → 2.5.76
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.
|
|
3
|
+
"version": "2.5.76",
|
|
4
4
|
"description": "Quick tools for developing Firebase functions",
|
|
5
5
|
"main": "src/manager/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -62,4 +62,4 @@
|
|
|
62
62
|
"wonderful-fetch": "^0.0.17",
|
|
63
63
|
"yargs": "^17.7.1"
|
|
64
64
|
}
|
|
65
|
-
}
|
|
65
|
+
}
|
|
@@ -31,6 +31,13 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
31
31
|
timestamp: moment(0),
|
|
32
32
|
timestampUNIX: moment(0),
|
|
33
33
|
},
|
|
34
|
+
lastPayment: {
|
|
35
|
+
amount: 0,
|
|
36
|
+
date: {
|
|
37
|
+
timestamp: moment(0),
|
|
38
|
+
timestampUNIX: moment(0),
|
|
39
|
+
}
|
|
40
|
+
},
|
|
34
41
|
trial: {
|
|
35
42
|
active: false,
|
|
36
43
|
daysLeft: 0,
|
|
@@ -147,6 +154,12 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
147
154
|
resolved.payment.completed = !['CREATED', 'SAVED', 'APPROVED', 'VOIDED', 'PAYER_ACTION_REQUIRED'].includes(resource.status);
|
|
148
155
|
}
|
|
149
156
|
|
|
157
|
+
// Set last payment
|
|
158
|
+
if (resource.billing_info && resource.billing_info.last_payment) {
|
|
159
|
+
resolved.lastPayment.amount = parseFloat(resource.billing_info.last_payment.amount.value);
|
|
160
|
+
resolved.lastPayment.date.timestamp = moment(resource.billing_info.last_payment.time);
|
|
161
|
+
}
|
|
162
|
+
|
|
150
163
|
} else if (profile.processor === 'chargebee') {
|
|
151
164
|
// Set status
|
|
152
165
|
// subscription: https://apidocs.chargebee.com/docs/api/subscriptions?prod_cat_ver=2#subscription_status
|
|
@@ -205,6 +218,12 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
205
218
|
resolved.payment.completed = !['future'].includes(resource.status);
|
|
206
219
|
}
|
|
207
220
|
|
|
221
|
+
// Set last payment
|
|
222
|
+
// if (resource.billing_info && resource.billing_info.last_payment) {
|
|
223
|
+
// resolved.lastPayment.amount = parseFloat(resource.billing_info.last_payment.amount.value);
|
|
224
|
+
// resolved.lastPayment.date.timestamp = moment(resource.billing_info.last_payment.time);
|
|
225
|
+
// }
|
|
226
|
+
|
|
208
227
|
} else if (profile.processor === 'stripe') {
|
|
209
228
|
// Subscription: https://stripe.com/docs/api/subscriptions/object#subscription_object-status
|
|
210
229
|
// incomplete, incomplete_expired, trialing, active, past_due, canceled, or unpaid
|
|
@@ -266,6 +285,14 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
266
285
|
resolved.payment.completed = !['requires_payment_method', 'requires_confirmation', 'requires_action', 'processing', 'requires_capture', 'canceled'].includes(resource.status);
|
|
267
286
|
}
|
|
268
287
|
|
|
288
|
+
// Set last payment
|
|
289
|
+
if (resource.latest_invoice) {
|
|
290
|
+
resolved.lastPayment.amount = resource.latest_invoice.amount_paid / 100;
|
|
291
|
+
resolved.lastPayment.date.timestamp = moment(
|
|
292
|
+
get(resource, 'latest_invoice.created', 0) * 1000
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
269
296
|
} else if (profile.processor === 'coinbase') {
|
|
270
297
|
// Set status
|
|
271
298
|
resolved.status = 'cancelled';
|
|
@@ -297,9 +324,17 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
297
324
|
}
|
|
298
325
|
|
|
299
326
|
// Set completed
|
|
327
|
+
const lastPayment = resource.payments.find(p => p.status === 'CONFIRMED');
|
|
300
328
|
if (true) {
|
|
301
|
-
resolved.payment.completed = !!
|
|
329
|
+
resolved.payment.completed = !!lastPayment;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Set last payment
|
|
333
|
+
if (lastPayment) {
|
|
334
|
+
resolved.lastPayment.amount = parseFloat(lastPayment.local.amount);
|
|
335
|
+
resolved.lastPayment.date.timestamp = moment(lastPayment.detected_at);
|
|
302
336
|
}
|
|
337
|
+
|
|
303
338
|
} else {
|
|
304
339
|
throw new Error('Unknown processor');
|
|
305
340
|
}
|
|
@@ -342,6 +377,10 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
342
377
|
|
|
343
378
|
// Fix trial days
|
|
344
379
|
resolved.trial.daysLeft = resolved.trial.daysLeft < 0 ? 0 : resolved.trial.daysLeft;
|
|
380
|
+
|
|
381
|
+
// Set last payment
|
|
382
|
+
resolved.lastPayment.date.timestampUNIX = moment(resolved.lastPayment.date.timestamp).unix();
|
|
383
|
+
resolved.lastPayment.date.timestamp = resolved.lastPayment.date.timestamp.toISOString();
|
|
345
384
|
|
|
346
385
|
// Log if needed
|
|
347
386
|
if (options.log) {
|