import { AuthedFetchType } from "../../api/fake-fetch"; import { MISSING_ACCOUNT_ID_ERROR_MESSAGE, MISSING_PAYMENT_METHOD_ID_ERROR_MESSAGE } from "../../constants"; import { errorMessage } from "../../utils"; import { PaymentMethods } from "../models"; export default function paymentMethods(authedFetch: AuthedFetchType): PaymentMethods { return { get: ({ accountID, paymentMethodID }) => { if (!accountID) { return errorMessage(MISSING_ACCOUNT_ID_ERROR_MESSAGE); } if (!paymentMethodID) { return errorMessage(MISSING_PAYMENT_METHOD_ID_ERROR_MESSAGE); } return authedFetch(`/accounts/${accountID}/payment-methods/${paymentMethodID}`, { method: "GET" }) }, list: ({ accountID }) => { if (!accountID) { return errorMessage(MISSING_ACCOUNT_ID_ERROR_MESSAGE); } return authedFetch(`/accounts/${accountID}/payment-methods`, { method: "GET" }) } } }