Mock payment API
This commit is contained in:
@@ -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<null> {
|
||||||
|
/**
|
||||||
|
* 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<null> {
|
||||||
|
/**
|
||||||
|
* 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<null> {
|
||||||
|
/**
|
||||||
|
* 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<null> {
|
||||||
|
/**
|
||||||
|
* 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<null> {
|
||||||
|
/**
|
||||||
|
* requestRefund attempts to process a refund for the amount to the
|
||||||
|
* provided card.
|
||||||
|
*/
|
||||||
|
console.log(`Refunded ${amount} to ${card.card_number}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user