backend-manager 5.0.139 → 5.0.141

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": "5.0.139",
3
+ "version": "5.0.141",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -82,12 +82,14 @@ module.exports = async ({ assistant, change, context }) => {
82
82
  // Chargebee hosted page checkouts don't forward subscription[meta_data] to the subscription,
83
83
  // but pass_thru_content is stored on the hosted page and contains our UID + orderId
84
84
  let resolvedFromPassThru = false;
85
+ let passThruOrderId = null;
85
86
  if (!uid && library.resolveUidFromHostedPage) {
86
87
  const passThruResult = await library.resolveUidFromHostedPage(resourceId, assistant);
87
88
  if (passThruResult) {
88
89
  uid = passThruResult.uid;
90
+ passThruOrderId = passThruResult.orderId || null;
89
91
  resolvedFromPassThru = true;
90
- assistant.log(`UID resolved from hosted page pass_thru_content: uid=${uid}, resourceId=${resourceId}`);
92
+ assistant.log(`UID resolved from hosted page pass_thru_content: uid=${uid}, orderId=${passThruOrderId}, resourceId=${resourceId}`);
91
93
 
92
94
  await webhookRef.set({ owner: uid }, { merge: true });
93
95
  }
@@ -101,8 +103,8 @@ module.exports = async ({ assistant, change, context }) => {
101
103
  // Backfill: if UID was resolved from pass_thru_content, set meta_data on the subscription
102
104
  // so future webhooks (renewals, cancellations) can resolve the UID directly
103
105
  if (resolvedFromPassThru && resourceType === 'subscription' && library.setMetaData) {
104
- library.setMetaData(resourceId, uid, assistant, resource)
105
- .then(() => assistant.log(`Backfilled meta_data on subscription ${resourceId} + customer: uid=${uid}`))
106
+ library.setMetaData(resource, { uid, orderId: passThruOrderId })
107
+ .then(() => assistant.log(`Backfilled meta_data on subscription ${resourceId} + customer: uid=${uid}, orderId=${passThruOrderId}`))
106
108
  .catch((e) => assistant.error(`Failed to backfill meta_data on ${resourceType} ${resourceId}: ${e.message}`));
107
109
  }
108
110
 
@@ -112,7 +114,8 @@ module.exports = async ({ assistant, change, context }) => {
112
114
  const webhookReceivedUNIX = dataAfter.metadata?.created?.timestampUNIX || nowUNIX;
113
115
 
114
116
  // Extract orderId from resource (processor-agnostic)
115
- orderId = library.getOrderId(resource);
117
+ // Falls back to pass_thru_content orderId when meta_data wasn't available on the resource
118
+ orderId = library.getOrderId(resource) || passThruOrderId;
116
119
 
117
120
  // Process the payment event (subscription or one-time)
118
121
  if (category !== 'subscription' && category !== 'one-time') {
@@ -181,25 +181,22 @@ const Chargebee = {
181
181
  * Used to backfill meta_data after resolving UID from pass_thru_content,
182
182
  * so future webhooks (renewals, cancellations) can resolve UID directly
183
183
  *
184
- * @param {string} subscriptionId - Chargebee subscription ID
185
- * @param {string} uid - User's Firebase UID
186
- * @param {object} assistant - Assistant instance for logging
187
- * @param {object} [resource] - Fetched subscription resource (to get customer_id)
184
+ * @param {object} resource - Fetched subscription resource (has .id and .customer_id)
185
+ * @param {object} meta - { uid, orderId } to backfill on the subscription + customer
188
186
  */
189
- async setMetaData(subscriptionId, uid, assistant, resource) {
187
+ async setMetaData(resource, meta = {}) {
190
188
  this.init();
191
- const metaBody = { meta_data: { uid } };
189
+ const metaBody = { meta_data: JSON.stringify(meta) };
192
190
 
193
191
  // Backfill subscription
194
- await this.request(`/subscriptions/${subscriptionId}`, {
192
+ await this.request(`/subscriptions/${resource.id}`, {
195
193
  method: 'POST',
196
194
  body: metaBody,
197
195
  });
198
196
 
199
197
  // Backfill customer
200
- const customerId = resource?.customer_id;
201
- if (customerId) {
202
- await this.request(`/customers/${customerId}`, {
198
+ if (resource.customer_id) {
199
+ await this.request(`/customers/${resource.customer_id}`, {
203
200
  method: 'POST',
204
201
  body: metaBody,
205
202
  });