UNPKG

@malga-checkout/core

Version:
27 lines (26 loc) 784 B
import { Api } from '../api'; import { formatPayload } from './customers.utils'; import settings from '../../stores/settings'; export class Customers { constructor() { this.api = new Api(); this.customer = settings.transactionConfig.customer; } async create() { const response = await this.api.create({ endpoint: settings.sessionId ? '/sessions/customers?force=true' : '/customers?force=true', data: formatPayload(this.customer), }); const customerId = response.data.id; if (!customerId) { return; } return response.data.id; } async find(customerId) { const endpoint = settings.sessionId ? '/sessions/customers' : '/customers'; return this.api.fetch({ endpoint: `${endpoint}/${customerId}` }); } }