import { C as ComponentErrorSeverity } from './Plaid-DxSkT8pY.js';
import { g as getErrorCode, a as getErrorMessage } from './utils-CVYvs2hZ.js';

const makeGetCheckout = ({ authToken, checkoutId, service }) => async ({ onSuccess, onError }) => {
    var _a;
    try {
        const response = await service.fetchCheckout(authToken, checkoutId);
        if (!response.error) {
            const checkout = response.data;
            onSuccess({ checkout });
        }
        else {
            const responseError = getErrorMessage(response.error);
            const code = getErrorCode((_a = response.error) === null || _a === void 0 ? void 0 : _a.code);
            return onError({
                error: responseError,
                code,
                severity: ComponentErrorSeverity.ERROR,
            });
        }
    }
    catch (error) {
        const code = getErrorCode(error === null || error === void 0 ? void 0 : error.code);
        return onError({
            error: error.message || error,
            code,
            severity: ComponentErrorSeverity.ERROR,
        });
    }
};
const makeCheckoutComplete = ({ authToken, checkoutId, service }) => async ({ payment, onSuccess, onError }) => {
    var _a;
    try {
        const response = await service.complete(authToken, checkoutId, payment);
        if (!response.error) {
            const checkout = response.data;
            onSuccess({ checkout });
        }
        else {
            const responseError = getErrorMessage(response.error);
            const code = getErrorCode((_a = response.error) === null || _a === void 0 ? void 0 : _a.code);
            return onError({
                error: responseError,
                code,
                severity: ComponentErrorSeverity.ERROR,
            });
        }
    }
    catch (error) {
        const code = getErrorCode(error === null || error === void 0 ? void 0 : error.code);
        return onError({
            error: error.message || error,
            code,
            severity: ComponentErrorSeverity.ERROR,
        });
    }
};

export { makeCheckoutComplete as a, makeGetCheckout as m };
