From fc5e75a7c0d4abdf88482d2893598376ef5c3a3c Mon Sep 17 00:00:00 2001 From: Matt Stover Date: Tue, 13 Feb 2024 13:03:49 -0800 Subject: [PATCH] chore: remove unused checkout status polling function --- src/util/checkoutUtils.js | 65 --------------------------------------- 1 file changed, 65 deletions(-) diff --git a/src/util/checkoutUtils.js b/src/util/checkoutUtils.js index 182369ddd9..6e97267287 100644 --- a/src/util/checkoutUtils.js +++ b/src/util/checkoutUtils.js @@ -121,68 +121,3 @@ export function removeCredit(apollo, creditType) { } }); } - -/** - * Poll the checkoutStatus endpoint until the checkout is complete - * Note: We only operate on the COMPLETED or results with errors - * - * Possible status values: - * - BASKET_MANIFEST - * - BASKET_VALID - * - CHECKOUT_FAILED - * - CHECKOUT_RECORDED - * - CHECKOUT_ROLLED_BACK - * - COMPLETED - * - CREDIT_ADDED - * - DEPOSIT_RECORDED - * - FAILED - * - MANIFEST_FAILED - * - RECORD_CHECKOUT_FAILED - * - REQUEST_RECEIVED - * - RESERVATIONS_COMPLETED - * - STARTED - * - TRANSIENT_PAYMENT_METHOD_CHARGED - * - * @param {Object} apollo Apollo Client instance - * @param {Number} transactionId - * @param {Number} interval How often to poll - * @param {Number} timeout How long to allow polling to continue - * @returns {Promise} - */ -export async function pollForCheckoutStatus( - apollo = null, - transactionSagaId = 0, - interval = 1000, - timeout = 60000 -) { - if (!apollo) { - throw new Error('Apollo instance missing'); - } - - // establish endtime based on timeout - const endTime = Date.now() + timeout; - - const checkStatus = async () => { - // check for timeout - if (Date.now() > endTime) { - throw new Error('Polling timed out'); - } - // query checkoutStatus - const result = await apollo.query({ - query: checkoutStatus, - variables: { - transactionId: transactionSagaId - } - }); - // extract fields to check for a completed status or errors - const { status, errorCode, errorMessage } = result?.data?.checkoutStatus; - // Check for completed status, or errors and return if present - if (status === 'COMPLETED' || errorCode || errorMessage) { - return result?.data?.checkoutStatus; - } - // Check again - setTimeout(checkStatus, interval); - }; - - return checkStatus(); -}