node-beamcheckout
Version:
Package for Beam Checkout
37 lines (36 loc) • 1.21 kB
JavaScript
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();
}
}