Skip to content

Commit

Permalink
Merge pull request #57 from compsci-adl/fix/payment-not-change
Browse files Browse the repository at this point in the history
fix: Membership setting doesn't change after payment
  • Loading branch information
rayokamoto authored Feb 17, 2024
2 parents e334eeb + 85e5a6a commit 3f800ab
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/app/(account)/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const verifyMembershipPayment = async (clerkId: string) => {
// Get user's membership expiry date from the database
const [{ membershipExpiresAt }] = await db
.select({
id: memberTable.id,
membershipExpiresAt: memberTable.membershipExpiresAt,
})
.from(memberTable)
Expand Down Expand Up @@ -43,7 +44,7 @@ const verifyMembershipPayment = async (clerkId: string) => {
await db
.update(memberTable)
.set({ membershipExpiresAt: expiryDate })
.where(eq(memberTable.id, clerkId));
.where(eq(memberTable.clerkId, clerkId));

// Delete key from Redis since it is no longer needed
await redisClient.del(`payment:membership:${clerkId}`);
Expand Down
22 changes: 0 additions & 22 deletions src/app/api/payment/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { env } from '@/env.mjs';
import { redisClient } from '@/lib/redis';
import { squareClient } from '@/lib/square';
import { currentUser } from '@clerk/nextjs';
import type { NextRequest } from 'next/server';
import type { CreatePaymentLinkRequest } from 'square';
import { ApiError } from 'square';
import { z } from 'zod';
Expand Down Expand Up @@ -85,24 +84,3 @@ export async function POST(request: Request) {
return new Response(null, { status: 500 });
}
}

// Get a Square payment
// See: https://developer.squareup.com/reference/square/payments-api/get-payment
export async function GET(request: NextRequest) {
const params = request.nextUrl.searchParams;
const paymentId = params.get('paymentId');

if (!paymentId) {
return new Response('Square payment ID must be provided', { status: 400 });
}

try {
const resp = await squareClient.paymentsApi.getPayment(paymentId);
return Response.json(resp.result.payment);
} catch (e) {
if (e instanceof ApiError) {
return new Response(JSON.stringify(e.errors), { status: e.statusCode });
}
return new Response(null, { status: 500 });
}
}

0 comments on commit 3f800ab

Please sign in to comment.