merge: catch up with feature/helcim-plan-consolidation base
# Conflicts: # server/api/auth/member.get.js # server/api/members/update-contribution.post.js # tests/server/api/update-contribution.test.js
This commit is contained in:
commit
7704557f16
10 changed files with 160 additions and 9 deletions
|
|
@ -34,6 +34,7 @@ export default defineEventHandler(async (event) => {
|
|||
paymentMethod: 'none',
|
||||
subscriptionEndDate: new Date(),
|
||||
},
|
||||
$unset: { nextBillingDate: 1 },
|
||||
},
|
||||
{ runValidators: false }
|
||||
);
|
||||
|
|
|
|||
|
|
@ -98,6 +98,10 @@ export default defineEventHandler(async (event) => {
|
|||
throw new Error("No subscription returned in response");
|
||||
}
|
||||
|
||||
const nextBillingDate = subscription.nextBillingDate
|
||||
? new Date(subscription.nextBillingDate)
|
||||
: null;
|
||||
|
||||
// Update member record
|
||||
await Member.findByIdAndUpdate(
|
||||
member._id,
|
||||
|
|
@ -107,6 +111,9 @@ export default defineEventHandler(async (event) => {
|
|||
paymentMethod: "card",
|
||||
status: "active",
|
||||
billingCadence: cadence,
|
||||
...(nextBillingDate && !Number.isNaN(nextBillingDate.getTime())
|
||||
? { nextBillingDate }
|
||||
: {}),
|
||||
} },
|
||||
{ runValidators: false }
|
||||
);
|
||||
|
|
@ -148,7 +155,10 @@ export default defineEventHandler(async (event) => {
|
|||
// Update member to free tier
|
||||
await Member.findByIdAndUpdate(
|
||||
member._id,
|
||||
{ $set: { contributionAmount: newAmount, helcimSubscriptionId: null, paymentMethod: "none", billingCadence: "monthly" } },
|
||||
{
|
||||
$set: { contributionAmount: newAmount, helcimSubscriptionId: null, paymentMethod: "none", billingCadence: "monthly" },
|
||||
$unset: { nextBillingDate: 1 },
|
||||
},
|
||||
{ runValidators: false }
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue