Skip to content

Commit

Permalink
Merge pull request #73 from tomridder/personal/tomridder/issue_fix_72
Browse files Browse the repository at this point in the history
修修复了付费后无论是monthly 还是quartly 还是yearly,截止日期都是一个月的时间的bug
  • Loading branch information
AprilNEA authored Jun 2, 2023
2 parents 31eb0c7 + a6df5aa commit d9b877d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/chat/src/app/(chat)/pricing/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface Price {
features: string[];
}

const prices: Price[] = [
export const prices: Price[] = [
{
name: "Free",
price: {
Expand Down
15 changes: 14 additions & 1 deletion apps/chat/src/app/api/callback/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NextRequest } from "next/server";
import { handleCallback } from "@/lib/pay/xunhu";
import { OrderLogic, SubscriptionLogic } from "database";
import { prices } from "../../(chat)/pricing/page"

/**
* This is the callback interface for processing payment platforms.
Expand All @@ -16,6 +17,18 @@ export async function POST(req: NextRequest) {
// Modify order status.
const order = await orderLogic.getOrder(orderId);

const totolMoney = order!.totalCents;

let numberOfDay= 1;

if (totolMoney == prices[1].price.monthly || totolMoney == prices[2].price.monthly) {
numberOfDay = 30;
} else if (totolMoney == prices[1].price.quarterly || totolMoney == prices[2].price.quarterly) {
numberOfDay = 90;
} else {
numberOfDay = 365;
}

if (order?.status === "pending") {
await orderLogic.updateStatus(orderId, "paid");
}
Expand All @@ -25,7 +38,7 @@ export async function POST(req: NextRequest) {
const subscriptionLogic = new SubscriptionLogic();
await subscriptionLogic.append(order!.email, {
startsAt: Date.now(),
endsAt: Date.now() + 1000 * 60 * 60 * 24 * 30,
endsAt: Date.now() + 1000 * 60 * 60 * 24 * numberOfDay,
plan: order!.plan,
tradeOrderId: orderId,
});
Expand Down

0 comments on commit d9b877d

Please sign in to comment.