mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +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 type {ProductInfo, ProductRegistry} from '../ProductRegistry';
|
||||||
import {
|
import {
|
||||||
getFirstInvoicePaymentIntentId,
|
getFirstInvoicePaymentIntentId,
|
||||||
getFirstInvoicePaymentIntentLatestChargeId,
|
|
||||||
getPrimarySubscriptionItem,
|
getPrimarySubscriptionItem,
|
||||||
getSubscriptionItemPeriodEnd,
|
getSubscriptionItemPeriodEnd,
|
||||||
getSubscriptionPremiumPeriodEnd,
|
getSubscriptionPremiumPeriodEnd,
|
||||||
@@ -600,11 +599,16 @@ export class StripeCheckoutWebhookHandler {
|
|||||||
if (!this.stripe) return null;
|
if (!this.stripe) return null;
|
||||||
try {
|
try {
|
||||||
const subscription = await this.stripe.subscriptions.retrieve(subscriptionId, {
|
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 =
|
const latestInvoice =
|
||||||
typeof subscription.latest_invoice === 'string' ? null : (subscription.latest_invoice ?? null);
|
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) {
|
} catch (err) {
|
||||||
Logger.warn({err, subscriptionId}, 'Failed to resolve latest charge for duplicate-subscription refund');
|
Logger.warn({err, subscriptionId}, 'Failed to resolve latest charge for duplicate-subscription refund');
|
||||||
return null;
|
return null;
|
||||||
@@ -739,7 +743,7 @@ export class StripeCheckoutWebhookHandler {
|
|||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const subscription = (await this.stripe.subscriptions.retrieve(subscriptionId, {
|
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;
|
})) as StripeSubscriptionWithFallbackPaymentState;
|
||||||
const latestInvoice =
|
const latestInvoice =
|
||||||
typeof subscription.latest_invoice === 'string' ? null : (subscription.latest_invoice ?? null);
|
typeof subscription.latest_invoice === 'string' ? null : (subscription.latest_invoice ?? null);
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ export class StripeRefundService {
|
|||||||
const list = await this.stripe.invoices.list({
|
const list = await this.stripe.invoices.list({
|
||||||
customer: user.stripeCustomerId,
|
customer: user.stripeCustomerId,
|
||||||
limit: 5,
|
limit: 5,
|
||||||
expand: ['data.payments.data.payment.payment_intent'],
|
expand: ['data.payments.data.payment'],
|
||||||
});
|
});
|
||||||
for (const invoice of list.data) {
|
for (const invoice of list.data) {
|
||||||
if (!invoice.id || invoice.status !== 'paid' || invoice.amount_paid <= 0) {
|
if (!invoice.id || invoice.status !== 'paid' || invoice.amount_paid <= 0) {
|
||||||
|
|||||||
Reference in new issue
Block a user