Skip to content

Commit

Permalink
chore: remove unused checkout status polling function
Browse files Browse the repository at this point in the history
  • Loading branch information
mcstover committed Feb 13, 2024
1 parent ed96f9d commit fc5e75a
Showing 1 changed file with 0 additions and 65 deletions.
65 changes: 0 additions & 65 deletions src/util/checkoutUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit fc5e75a

Please sign in to comment.