UNPKG

@unchainedshop/plugins

Version:

Because of a Typescript issue with upstream "postfinancecheckout", the Postfinance plugin has been disabled from transpilation, import the source ts files from src and enable node_module tsc or copy over the src/payment/postfinance-checkout to your projec

43 lines 1.62 kB
import { createLogger } from '@unchainedshop/logger'; const { MOCK_APIS } = process.env; const logger = createLogger('unchained:datatrans'); export default (endpoint, merchantId, secret) => { if (MOCK_APIS) { return async (path) => { try { const { default: json } = await import(`${import.meta.dirname}/../../../../tests/mock/datatrans/${path}.json`, { with: { type: 'json' }, }); return { json: async () => json, status: json?.error ? 500 : 204, }; } catch (error) { logger.error('Mock: Error while trying reading and parsing file', { ...error, }); return { json: async () => ({ error: { code: 'MOCK', message: 'MOCK' } }), status: 500, }; } }; } const token = `${merchantId}:${secret}`; return async (path, body) => { logger.debug(`Fetch ${endpoint}${path}: ${JSON.stringify(body)}`); return fetch(`${endpoint}${path}`, { method: body ? 'POST' : 'GET', body: body ? JSON.stringify(body) : undefined, // eslint-disable-next-line // @ts-ignore duplex: body ? 'half' : undefined, headers: { 'Content-Type': 'application/json', Authorization: `Basic ${Buffer.from(token, 'utf-8').toString('base64')}`, }, }); }; }; //# sourceMappingURL=makeFetcher.js.map