mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-04 19:11:57 +08:00
fix(server): selfhost subscription customer portal creation (#10149)
This commit is contained in:
@@ -222,11 +222,8 @@ export class LicenseService implements OnModuleInit {
|
|||||||
await this.fetchAffinePro(`/api/team/licenses/${license.key}/seats`, {
|
await this.fetchAffinePro(`/api/team/licenses/${license.key}/seats`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
quantity: count,
|
seats: count,
|
||||||
}),
|
}),
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// stripe payment is async, we can't directly the charge result in update calling
|
// stripe payment is async, we can't directly the charge result in update calling
|
||||||
|
|||||||
@@ -228,24 +228,24 @@ export class LicenseController {
|
|||||||
|
|
||||||
@Post('/:license/create-customer-portal')
|
@Post('/:license/create-customer-portal')
|
||||||
async createCustomerPortal(@Param('license') key: string) {
|
async createCustomerPortal(@Param('license') key: string) {
|
||||||
const invoice = await this.db.invoice.findFirst({
|
const subscription = await this.db.subscription.findFirst({
|
||||||
where: {
|
where: {
|
||||||
targetId: key,
|
targetId: key,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!invoice) {
|
if (!subscription || !subscription.stripeSubscriptionId) {
|
||||||
throw new LicenseNotFound();
|
throw new LicenseNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const invoiceData = await this.stripe.invoices.retrieve(
|
const subscriptionData = await this.stripe.subscriptions.retrieve(
|
||||||
invoice.stripeInvoiceId,
|
subscription.stripeSubscriptionId,
|
||||||
{
|
{
|
||||||
expand: ['customer'],
|
expand: ['customer'],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const customer = invoiceData.customer as Stripe.Customer;
|
const customer = subscriptionData.customer as Stripe.Customer;
|
||||||
try {
|
try {
|
||||||
const portal = await this.stripe.billingPortal.sessions.create({
|
const portal = await this.stripe.billingPortal.sessions.create({
|
||||||
customer: customer.id,
|
customer: customer.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user