backend-manager 2.5.39 → 2.5.41
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
|
@@ -8,7 +8,7 @@ function SubscriptionResolver(profile, resource) {
|
|
|
8
8
|
self.resource = resource;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
SubscriptionResolver.prototype.resolve = function () {
|
|
11
|
+
SubscriptionResolver.prototype.resolve = function (options) {
|
|
12
12
|
const self = this;
|
|
13
13
|
|
|
14
14
|
const resolved = {
|
|
@@ -32,9 +32,20 @@ SubscriptionResolver.prototype.resolve = function () {
|
|
|
32
32
|
const profile = self.profile;
|
|
33
33
|
const resource = self.resource;
|
|
34
34
|
|
|
35
|
+
options = options || {};
|
|
36
|
+
|
|
37
|
+
if (options.log) {
|
|
38
|
+
console.log('profile', profile);
|
|
39
|
+
console.log('resource', resource);
|
|
40
|
+
}
|
|
41
|
+
|
|
35
42
|
// Process differently based on each provider
|
|
36
43
|
if (profile.processor === 'paypal') {
|
|
37
44
|
// Set status
|
|
45
|
+
// subscription: https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get
|
|
46
|
+
// APPROVAL_PENDING. The subscription is created but not yet approved by the buyer. APPROVED. The buyer has approved the subscription. ACTIVE. The subscription is active. SUSPENDED. The subscription is suspended. CANCELLED. The subscription is cancelled. EXPIRED. The subscription is expired.
|
|
47
|
+
// order: https://developer.paypal.com/docs/api/orders/v2/#orders_get
|
|
48
|
+
// CREATED. The order was created with the specified context. 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. 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. VOIDED. All purchase units in the order are voided. COMPLETED. The payment was authorized or the authorized payment was captured for the order. 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.
|
|
38
49
|
if (['ACTIVE'].includes(resource.status)) {
|
|
39
50
|
resolved.status = 'active';
|
|
40
51
|
} else if (['SUSPENDED'].includes(resource.status)) {
|
|
@@ -55,9 +66,15 @@ SubscriptionResolver.prototype.resolve = function () {
|
|
|
55
66
|
)
|
|
56
67
|
|
|
57
68
|
// Set completed
|
|
58
|
-
|
|
69
|
+
if (resource.plan_id) {
|
|
70
|
+
resolved.payment.completed = !['APPROVAL_PENDING', 'APPROVED'].includes(resource.status);
|
|
71
|
+
} else {
|
|
72
|
+
resolved.payment.completed = !['CREATED', 'SAVED', 'APPROVED', 'VOIDED', 'PAYER_ACTION_REQUIRED'].includes(resource.status);
|
|
73
|
+
}
|
|
59
74
|
} else if (profile.processor === 'chargebee') {
|
|
60
75
|
// Set status
|
|
76
|
+
// subscription: https://apidocs.chargebee.com/docs/api/subscriptions?prod_cat_ver=2#subscription_status
|
|
77
|
+
// 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.
|
|
61
78
|
if (['in_trial', 'active'].includes(resource.status)) {
|
|
62
79
|
resolved.status = 'active';
|
|
63
80
|
} else if (['paused'].includes(resource.status)) {
|
|
@@ -78,8 +95,15 @@ SubscriptionResolver.prototype.resolve = function () {
|
|
|
78
95
|
)
|
|
79
96
|
|
|
80
97
|
// Set completed
|
|
81
|
-
|
|
98
|
+
if (true) {
|
|
99
|
+
resolved.payment.completed = !['future'].includes(resource.status);
|
|
100
|
+
}
|
|
82
101
|
} else if (profile.processor === 'stripe') {
|
|
102
|
+
// Subscription: https://stripe.com/docs/api/subscriptions/object#subscription_object-status
|
|
103
|
+
// incomplete, incomplete_expired, trialing, active, past_due, canceled, or unpaid
|
|
104
|
+
|
|
105
|
+
// Charge: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-status
|
|
106
|
+
// requires_payment_method, requires_confirmation, requires_action, processing, requires_capture, canceled, or succeeded
|
|
83
107
|
// Set status
|
|
84
108
|
if (['trialing', 'active'].includes(resource.status)) {
|
|
85
109
|
resolved.status = 'active';
|
|
@@ -101,7 +125,11 @@ SubscriptionResolver.prototype.resolve = function () {
|
|
|
101
125
|
);
|
|
102
126
|
|
|
103
127
|
// Set completed
|
|
104
|
-
|
|
128
|
+
if (resource.object === 'subscription') {
|
|
129
|
+
resolved.payment.completed = !['incomplete', 'incomplete_expired'].includes(resource.status);
|
|
130
|
+
} else if (resource.object === 'payment_intent') {
|
|
131
|
+
resolved.payment.completed = !['requires_payment_method', 'requires_confirmation', 'requires_action', 'processing', 'requires_capture', 'canceled'].includes(resource.status);
|
|
132
|
+
}
|
|
105
133
|
} else if (profile.processor === 'coinbase') {
|
|
106
134
|
// Set status
|
|
107
135
|
resolved.status = 'cancelled';
|
|
@@ -118,7 +146,9 @@ SubscriptionResolver.prototype.resolve = function () {
|
|
|
118
146
|
);
|
|
119
147
|
|
|
120
148
|
// Set completed
|
|
121
|
-
|
|
149
|
+
if (true) {
|
|
150
|
+
resolved.payment.completed = !!resource.payments.find(p => p.status === 'CONFIRMED');
|
|
151
|
+
}
|
|
122
152
|
}
|
|
123
153
|
|
|
124
154
|
// If there was NEVER any payment sent
|
|
@@ -149,6 +179,10 @@ SubscriptionResolver.prototype.resolve = function () {
|
|
|
149
179
|
|
|
150
180
|
// console.log('---resolved', resolved);
|
|
151
181
|
|
|
182
|
+
if (options.log) {
|
|
183
|
+
console.log('resolved', resolved);
|
|
184
|
+
}
|
|
185
|
+
|
|
152
186
|
self.resolved = resolved;
|
|
153
187
|
|
|
154
188
|
return resolved;
|