feat: implement billing system with credit tracking and RevenueCat integration
This commit is contained in:
@@ -403,6 +403,19 @@ const syncRevenueCatCustomerInfo = async (db, userId, customerInfo, options = {}
|
||||
);
|
||||
}
|
||||
|
||||
// Fallback: also check active entitlements for topup products.
|
||||
// This handles cases where a topup product is misconfigured in RevenueCat
|
||||
// to grant an entitlement instead of being treated as a consumable.
|
||||
const rawActiveEntitlements = Object.values(customerInfo?.entitlements?.active || {});
|
||||
for (const entitlement of rawActiveEntitlements) {
|
||||
const productId = entitlement?.productIdentifier;
|
||||
if (isSupportedTopupProduct(productId)) {
|
||||
const purchaseDate = entitlement?.latestPurchaseDate || entitlement?.originalPurchaseDate;
|
||||
const txId = purchaseDate ? `entitlement:${productId}:${purchaseDate}` : null;
|
||||
await grantRevenueCatTopupIfNeeded(tx, account, txId, productId);
|
||||
}
|
||||
}
|
||||
|
||||
account.updatedAt = nowIso();
|
||||
await upsertAccount(tx, account);
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user