Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Membership setting doesn't change after payment #57

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 });
}
}
Loading