From 1615f079745ce69569dca0d31e4d7278fd86f2cb Mon Sep 17 00:00:00 2001 From: NeilClack Date: Sun, 3 May 2026 21:01:08 -0500 Subject: [PATCH] Mock payment API --- src/lib/payments.ts | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/lib/payments.ts diff --git a/src/lib/payments.ts b/src/lib/payments.ts new file mode 100644 index 0000000..40f6bdb --- /dev/null +++ b/src/lib/payments.ts @@ -0,0 +1,71 @@ +// Contains all payment related functions such as making payments, +// issueing refunds, storing and deleting credit cards, and more. +// A full list of implementation requirements will be kept below. +// +// ---- Implementations ---- +// ✔ Make a payment... +// ✔ With a non-saved card +// ✔ With a saved card +// ✔ Add a card +// ✔ Delete a card +// ✔ Issue a refund + +import type { Decimal } from "@prisma/client/runtime/client"; + +export interface CreditDebitCard { + first_name: string, + last_name: string, + card_number: number, + expiration_month: number, + expiration_year: number, + security_code: number, +} + +export async function chargeCreditDebitCard (card: CreditDebitCard, amount: Decimal): Promise { + /** + * chargeCreditDebitCard attempts to request payment from a valid card, + * for the amount specified. + */ + console.log(`charged card ${card} for $${amount}`); + await new Promise(resolve => setTimeout(resolve, 1000)); + return null; +} + +export async function chargedStoredCard(cardNumber: number, profileID: string, amount: Decimal): Promise { + /** + * chargedStoredCard attempts to request payment from a valid card, + * for the amount specified. + * The card is identified by the last four digits of the card + * number, and the profile ID. + * NOTE: This should be enough to identify a saved card, but the + * function signature may change in the future. + */ + console.log(`charged ${profileID}'s card ${cardNumber} for ${cardNumber} $${amount}`); + return null; +} + +export async function deleteCardFromProfile(cardNumber: number, profileID: string): Promise { + /** + * deleteCardFromProfile deletes a stored card on a user's profile. + */ + console.log(`Deleted card ${cardNumber} from ${profileID}'s profile.`); + return null; +} + +export async function storeCardToProfile(card: CreditDebitCard, profileID: string): Promise { + /** + * storeCardToProfile stores a new card to a user's profile + * for easy re-use later. + */ + console.log(`Deleted card ${card.card_number} from ${profileID}'s profile.`); + return null; +} + +export async function requestRefund(card: CreditDebitCard, amount: Decimal): Promise { + /** + * requestRefund attempts to process a refund for the amount to the + * provided card. + */ + console.log(`Refunded ${amount} to ${card.card_number}`); + return null; +} \ No newline at end of file