import { AuthedFetchType } from "../../api/fake-fetch"; import { ApplePaySessions } from "../models"; import { errorMessage } from "../../utils"; import { ApplePayTokens } from "../models"; import { MISSING_ACCOUNT_ID_ERROR_MESSAGE, MISSING_APPLE_PAY_SESSION_ERROR_MESSAGE, MISSING_APPLE_PAY_PAYMENT_TOKEN_ERROR_MESSAGE, } from "../../constants"; export const sessions = (authedFetch: AuthedFetchType): ApplePaySessions => ({ create: ({ accountID, applePaySessionConfig }) => { if (!accountID) { return errorMessage(MISSING_ACCOUNT_ID_ERROR_MESSAGE); } if (!applePaySessionConfig) { return errorMessage(MISSING_APPLE_PAY_SESSION_ERROR_MESSAGE); } return authedFetch(`/accounts/${accountID}/apple-pay/sessions`, { method: "POST", body: { ...applePaySessionConfig, domain: location.host }, }); } }); export const tokens = (authedFetch: AuthedFetchType): ApplePayTokens => ({ create: ({ accountID, applePayToken }) => { if (!accountID) { return errorMessage(MISSING_ACCOUNT_ID_ERROR_MESSAGE); } if (!applePayToken) { return errorMessage(MISSING_APPLE_PAY_PAYMENT_TOKEN_ERROR_MESSAGE); } return authedFetch(`/accounts/${accountID}/apple-pay/tokens`, { method: "POST", body: applePayToken, }); } });