feat(server): support team workspace subscription (#8919)

close AF-1724, AF-1722
This commit is contained in:
forehalo
2024-12-05 08:31:01 +00:00
parent 4055e3aa67
commit 5bf8ed1095
26 changed files with 2208 additions and 785 deletions
@@ -101,7 +101,7 @@ export class ScheduleManager {
items: [
{
price: this.currentPhase.items[0].price as string,
quantity: 1,
quantity: this.currentPhase.items[0].quantity,
},
],
coupon: (this.currentPhase.coupon as string | null) ?? undefined,
@@ -143,10 +143,9 @@ export class ScheduleManager {
items: [
{
price: this.currentPhase.items[0].price as string,
quantity: 1,
quantity: this.currentPhase.items[0].quantity,
},
],
coupon: (this.currentPhase.coupon as string | null) ?? undefined,
start_date: this.currentPhase.start_date,
end_date: this.currentPhase.end_date,
metadata: {
@@ -161,7 +160,7 @@ export class ScheduleManager {
items: [
{
price: this.currentPhase.metadata.next_price,
quantity: 1,
quantity: this.currentPhase.items[0].quantity,
},
],
coupon: this.currentPhase.metadata.next_coupon || undefined,
@@ -212,6 +211,7 @@ export class ScheduleManager {
items: [
{
price: this.currentPhase.items[0].price as string,
quantity: this.currentPhase.items[0].quantity,
},
],
start_date: this.currentPhase.start_date,
@@ -221,6 +221,7 @@ export class ScheduleManager {
items: [
{
price: price,
quantity: this.currentPhase.items[0].quantity,
},
],
},
@@ -230,4 +231,31 @@ export class ScheduleManager {
);
}
}
async updateQuantity(quantity: number, idempotencyKey?: string) {
if (!this._schedule) {
throw new Error('No schedule');
}
if (!this.isActive || !this.currentPhase) {
throw new Error('Unexpected subscription schedule status');
}
await this.stripe.subscriptionSchedules.update(
this._schedule.id,
{
phases: this._schedule.phases.map(phase => ({
items: [
{
price: phase.items[0].price as string,
quantity,
},
],
start_date: phase.start_date,
end_date: phase.end_date,
})),
},
{ idempotencyKey }
);
}
}