node-beamcheckout
Version:
Package for Beam Checkout
133 lines (132 loc) • 4.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BeamCheckout = void 0;
class BeamCheckout {
constructor(merchantId, apiKey, sandbox = false) {
this.merchantId = merchantId;
this.apiKey = apiKey;
this.baseUrl = sandbox
? 'https://playground.api.beamcheckout.com/api/v1'
: 'https://api.beamcheckout.com/api/v1';
}
merchantId;
apiKey;
baseUrl;
getHeaders() {
return {
Authorization: `Basic ${Buffer.from(`${this.merchantId}:${this.apiKey}`).toString('base64')}`,
'Content-Type': 'application/json',
};
}
async createPayment(args) {
console.log(`${this.baseUrl}/payment-links`, JSON.stringify(args));
const res = await fetch(`${this.baseUrl}/payment-links`, {
method: 'POST',
headers: this.getHeaders(),
body: JSON.stringify(args),
});
return await res.json();
}
async getPayment(paymentLinkId) {
const res = await fetch(`${this.baseUrl}/payment-links/${paymentLinkId}`, {
method: 'GET',
headers: this.getHeaders(),
});
return await res.json();
}
async disablePayment(paymentLinkId) {
const res = await fetch(`${this.baseUrl}/payment-links/${paymentLinkId}/disable`, {
method: 'PATCH',
headers: this.getHeaders(),
});
return await res.json();
}
async refundPayment(chargeId, amount, reason) {
const res = await fetch(`${this.baseUrl}/refunds`, {
method: 'POST',
headers: this.getHeaders(),
body: JSON.stringify({
amount: amount,
chargeId: chargeId,
reason: reason,
}),
});
return await res.json();
}
async getRefund(refundId) {
const res = await fetch(`${this.baseUrl}/refunds/${refundId}`, {
method: 'GET',
headers: this.getHeaders(),
});
return await res.json();
}
async listTransactions(referenceId, limit = 10, offset = 0) {
const res = await fetch(`${this.baseUrl}/transactions?limit=${limit}&offset=${offset}&referenceId=${referenceId}`, {
method: 'GET',
headers: this.getHeaders(),
});
return await res.json();
}
async getSuccessfulTransactions(transactionId) {
const res = await fetch(`${this.baseUrl}/transactions/${transactionId}`, {
method: 'GET',
headers: this.getHeaders(),
});
return await res.json();
}
async createChargePayment(args) {
const res = await fetch(`${this.baseUrl}/charges`, {
method: 'POST',
headers: this.getHeaders(),
body: JSON.stringify(args),
});
return await res.json();
}
async getChargePayment(chargeId) {
const res = await fetch(`${this.baseUrl}/charges/${chargeId}`, {
method: 'GET',
headers: this.getHeaders(),
});
return await res.json();
}
async createBoltConnection(pairingCode) {
const res = await fetch(`${this.baseUrl}/bolt-connections`, {
method: 'POST',
headers: this.getHeaders(),
body: JSON.stringify({
pairingCode: pairingCode,
}),
});
return await res.json();
}
async deleteBoltConnection(boltConnectionId) {
const res = await fetch(`${this.baseUrl}/bolt-connections/${boltConnectionId}`, {
method: 'DELETE',
headers: this.getHeaders(),
});
return await res.json();
}
async getBoltConnection(boltConnectionId) {
const res = await fetch(`${this.baseUrl}/bolt-connections/${boltConnectionId}`, {
method: 'GET',
headers: this.getHeaders(),
});
return await res.json();
}
async createBoltIntent(args) {
const res = await fetch(`${this.baseUrl}/bolt-intents`, {
method: 'POST',
headers: this.getHeaders(),
body: JSON.stringify(args),
});
return await res.json();
}
async cancelBoltIntent(boltIntentId) {
const res = await fetch(`${this.baseUrl}/bolt-intents/${boltIntentId}/cancel`, {
method: 'PATCH',
headers: this.getHeaders(),
});
return await res.json();
}
}
exports.BeamCheckout = BeamCheckout;