Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(api): keep Stripe expand paths within the four-level limit (#1707)

Hampus1922d5618828
diff --git a/fluxer_api/src/api/stripe/services/StripeCheckoutWebhookHandler.ts b/fluxer_api/src/api/stripe/services/StripeCheckoutWebhookHandler.ts
index 7a57a7c8f..1715c707b 100644
--- a/fluxer_api/src/api/stripe/services/StripeCheckoutWebhookHandler.ts
+++ b/fluxer_api/src/api/stripe/services/StripeCheckoutWebhookHandler.ts
@@ -21,7 +21,6 @@ import {mapUserToPrivateResponse} from '../../user/UserMappers';
import type {ProductInfo, ProductRegistry} from '../ProductRegistry';
import {
getFirstInvoicePaymentIntentId,
- getFirstInvoicePaymentIntentLatestChargeId,
getPrimarySubscriptionItem,
getSubscriptionItemPeriodEnd,
getSubscriptionPremiumPeriodEnd,
@@ -600,11 +599,16 @@ export class StripeCheckoutWebhookHandler {
if (!this.stripe) return null;
try {
const subscription = await this.stripe.subscriptions.retrieve(subscriptionId, {
- expand: ['latest_invoice.payments.data.payment.payment_intent.latest_charge'],
+ expand: ['latest_invoice.payments.data.payment'],
});
const latestInvoice =
typeof subscription.latest_invoice === 'string' ? null : (subscription.latest_invoice ?? null);
- return getFirstInvoicePaymentIntentLatestChargeId(latestInvoice);
+ const paymentIntentId = getFirstInvoicePaymentIntentId(latestInvoice);
+ if (!paymentIntentId) {
+ return null;
+ }
+ const paymentIntent = await this.stripe.paymentIntents.retrieve(paymentIntentId);
+ return extractId(paymentIntent.latest_charge);
} catch (err) {
Logger.warn({err, subscriptionId}, 'Failed to resolve latest charge for duplicate-subscription refund');
return null;
@@ -739,7 +743,7 @@ export class StripeCheckoutWebhookHandler {
};
try {
const subscription = (await this.stripe.subscriptions.retrieve(subscriptionId, {
- expand: ['default_payment_method', 'latest_invoice.payments.data.payment.payment_intent'],
+ expand: ['default_payment_method', 'latest_invoice.payments.data.payment'],
})) as StripeSubscriptionWithFallbackPaymentState;
const latestInvoice =
typeof subscription.latest_invoice === 'string' ? null : (subscription.latest_invoice ?? null);
diff --git a/fluxer_api/src/api/stripe/services/StripeRefundService.ts b/fluxer_api/src/api/stripe/services/StripeRefundService.ts
index bfb45b967..936ab3d3d 100644
--- a/fluxer_api/src/api/stripe/services/StripeRefundService.ts
+++ b/fluxer_api/src/api/stripe/services/StripeRefundService.ts
@@ -113,7 +113,7 @@ export class StripeRefundService {
const list = await this.stripe.invoices.list({
customer: user.stripeCustomerId,
limit: 5,
- expand: ['data.payments.data.payment.payment_intent'],
+ expand: ['data.payments.data.payment'],
});
for (const invoice of list.data) {
if (!invoice.id || invoice.status !== 'paid' || invoice.amount_paid <= 0) {