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(payment): use paymentId to determine if payment complete #79

Merged
merged 1 commit into from
Feb 19, 2024
Merged
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
26 changes: 16 additions & 10 deletions src/server/verify-membership-payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,26 @@ export const verifyMembershipPayment = async (clerkId: string) => {
}

try {
// Get order details
const orderRes = await squareClient.ordersApi.retrieveOrder(orderId);
if (orderRes.result.order?.state !== 'COMPLETED') {
return { paid: false as const };

// Get payment ID from the order
const paymentId = orderRes.result.order?.tenders?.[0]?.paymentId;

// If payment ID exists, payment was successful
if (paymentId) {
// Set expiry date to be the January 1st of the following year
const expiryDate = await updateMemberExpiryDate(clerkId, 'clerkId');

// Delete key from Redis since it is no longer needed
await redisClient.del(`payment:membership:${clerkId}`);

return { paid: true as const, membershipExpiresAt: expiryDate };
}

return { paid: false as const };
} catch {
return { paid: false as const };
}

// Set expiry date to be the January 1st of the following year
const expiryDate = await updateMemberExpiryDate(clerkId, 'clerkId');

// Delete key from Redis since it is no longer needed
await redisClient.del(`payment:membership:${clerkId}`);

return { paid: true as const, membershipExpiresAt: expiryDate };
};
export type MembershipPayment = Awaited<ReturnType<typeof verifyMembershipPayment>>;
Loading