UNPKG

node-beamcheckout

Version:
37 lines (36 loc) 1.21 kB
export class BeamCheckout { constructor(merchantId, apiKey) { this.merchantId = merchantId; this.apiKey = apiKey; } merchantId; apiKey; getHeaders() { return { 'Authorization': `Basic ${Buffer.from(`${this.merchantId}:${this.apiKey}`).toString('base64')}`, 'Content-Type': 'application/json' }; } async createPayment(args) { const res = await fetch(`https://api.beamcheckout.com/purchases/${this.merchantId}`, { method: 'POST', headers: this.getHeaders(), body: JSON.stringify(args), }); return await res.json(); } async getPayment(purchaseId) { const res = await fetch(`https://api.beamcheckout.com/purchases/${this.merchantId}/${purchaseId}/detail`, { method: 'GET', headers: this.getHeaders(), }); return await res.json(); } async disablePayment(purchaseId) { const res = await fetch(`https://api.beamcheckout.com/purchases/${this.merchantId}/${purchaseId}/disable`, { method: 'POST', headers: this.getHeaders(), }); return await res.json(); } }