mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 05:25:40 +09:00
fix(api): keep Stripe expand paths within the four-level limit (#1707)
This commit is contained in:
1 parent
cc105883a5
commit
1922d56188
2 files changed
+9
-5
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user