Skip to content

Commit 05a723d

Browse files
authored
chore: add logs for active subscriptions that are missing payment methods (#6863)
1 parent 114e7bc commit 05a723d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/services/api/src/modules/commerce/resolvers/Organization.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ export const Organization: Pick<
6060
organizationId: billingRecord.organizationId,
6161
});
6262

63+
const logger = injector.get(Logger);
64+
6365
if (!subscriptionInfo) {
66+
logger.info('No active subscription for organization (id=%s)', org.id);
6467
return {
6568
hasActiveSubscription: false,
6669
canUpdateSubscription: true,
@@ -85,6 +88,10 @@ export const Organization: Pick<
8588
i => i.charge !== null && typeof i.charge === 'object' && i.charge?.failure_code !== null,
8689
);
8790

91+
if (!subscriptionInfo.paymentMethod) {
92+
logger.warn('Active subscription found but is missing a payment method (id=%s)', org.id);
93+
}
94+
8895
return {
8996
hasActiveSubscription: subscriptionInfo.subscription !== null,
9097
canUpdateSubscription: subscriptionInfo.subscription !== null,

packages/services/commerce/src/stripe-billing/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,13 @@ export const stripeBillingRouter = router({
9292

9393
const actualSubscription = subscriptions[0] || null;
9494

95-
const paymentMethod = await ctx.stripeBilling.stripe.paymentMethods.list({
96-
customer: customer.id,
97-
type: 'card',
98-
});
95+
const paymentMethod = await ctx.stripeBilling.stripe.customers.listPaymentMethods(
96+
customer.id,
97+
{
98+
type: 'card',
99+
limit: 1,
100+
},
101+
);
99102

100103
return {
101104
paymentMethod: paymentMethod.data[0] || null,

0 commit comments

Comments
 (0)