feat: implement billing system with credit tracking and RevenueCat integration

This commit is contained in:
2026-04-04 12:15:16 +02:00
parent 439f5a44c9
commit 363f5f60d1
3 changed files with 1051 additions and 883 deletions

View File

@@ -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 {