backend-manager 2.5.40 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "2.5.40",
3
+ "version": "2.5.41",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -42,6 +42,10 @@ SubscriptionResolver.prototype.resolve = function (options) {
42
42
  // Process differently based on each provider
43
43
  if (profile.processor === 'paypal') {
44
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.
45
49
  if (['ACTIVE'].includes(resource.status)) {
46
50
  resolved.status = 'active';
47
51
  } else if (['SUSPENDED'].includes(resource.status)) {
@@ -62,9 +66,15 @@ SubscriptionResolver.prototype.resolve = function (options) {
62
66
  )
63
67
 
64
68
  // Set completed
65
- resolved.payment.completed = !['APPROVAL_PENDING', 'APPROVED'].includes(resource.status);
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
+ }
66
74
  } else if (profile.processor === 'chargebee') {
67
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.
68
78
  if (['in_trial', 'active'].includes(resource.status)) {
69
79
  resolved.status = 'active';
70
80
  } else if (['paused'].includes(resource.status)) {
@@ -85,8 +95,15 @@ SubscriptionResolver.prototype.resolve = function (options) {
85
95
  )
86
96
 
87
97
  // Set completed
88
- resolved.payment.completed = !['future'].includes(resource.status);
98
+ if (true) {
99
+ resolved.payment.completed = !['future'].includes(resource.status);
100
+ }
89
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
90
107
  // Set status
91
108
  if (['trialing', 'active'].includes(resource.status)) {
92
109
  resolved.status = 'active';
@@ -108,7 +125,11 @@ SubscriptionResolver.prototype.resolve = function (options) {
108
125
  );
109
126
 
110
127
  // Set completed
111
- resolved.payment.completed = !['incomplete', 'incomplete_expired'].includes(resource.status);
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
+ }
112
133
  } else if (profile.processor === 'coinbase') {
113
134
  // Set status
114
135
  resolved.status = 'cancelled';
@@ -125,7 +146,9 @@ SubscriptionResolver.prototype.resolve = function (options) {
125
146
  );
126
147
 
127
148
  // Set completed
128
- resolved.payment.completed = !!resource.payments.find(p => p.status === 'CONFIRMED');
149
+ if (true) {
150
+ resolved.payment.completed = !!resource.payments.find(p => p.status === 'CONFIRMED');
151
+ }
129
152
  }
130
153
 
131
154
  // If there was NEVER any payment sent