UNPKG

@koempf/shopgate-utility

Version:

Shopgate WebCheckout utility for Kömpf

21 lines (15 loc) 581 B
'use strict' const { getExternalCheckoutUrlEndpoint } = require('../endpoints') const { get } = require('../client/apiClient') const { UnknownError } = require('./errors') const getCheckoutUrl = async ({ cartId }, config) => { const checkout = await get(getExternalCheckoutUrlEndpoint(cartId), config) .then(response => response.statusCode === 200 ? response.body : Promise.reject(response)) .then(response => response.data[0] || response.data) .catch(() => {}) if (!checkout) throw new UnknownError() return checkout } module.exports = { getCheckoutUrl }