bitpay-sdk
Version:
Complete version of the NodeJS library for the new cryptographically secure BitPay API
117 lines • 4.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BillClient = void 0;
const Facade_1 = require("../Facade");
const BitPayExceptionProvider_1 = require("../Exceptions/BitPayExceptionProvider");
class BillClient {
constructor(bitPayClient, tokenContainer) {
this.bitPayClient = bitPayClient;
this.tokenContainer = tokenContainer;
}
/**
* Create a BitPay Bill.
*
* @param bill A Bill object with request parameters defined.
* @param facade The facade used to create it.
* @param signRequest Signed request.
* @returns Bill
* @throws BitPayGenericException BitPayGenericException
* @throws BitPayApiException BitPayApiException
*/
async create(bill, facade, signRequest) {
bill.token = this.tokenContainer.getToken(facade);
const result = await this.bitPayClient.post('bills', bill, signRequest);
try {
return JSON.parse(result);
}
catch (e) {
BitPayExceptionProvider_1.BitPayExceptionProvider.throwSerializeResourceException('Bill', e.message);
throw new Error();
}
}
/**
* Retrieve a BitPay bill by bill id using the specified facade.
*
* @param billId The id of the bill to retrieve
* @param facade The facade used to retrieve it.
* @param signRequest Signed request
* @returns Bill
* @throws BitPayGenericException BitPayGenericException class
* @throws BitPayApiException BitPayApiException class
*/
async get(billId, facade, signRequest) {
const params = { token: this.tokenContainer.getToken(facade) };
const result = await this.bitPayClient.get('bills/' + billId, params, signRequest);
try {
return JSON.parse(result);
}
catch (e) {
BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Bill', e.message);
throw new Error();
}
}
/**
* Retrieve a collection of BitPay bills.
*
* @param status
* @returns Bill[]
* @throws BitPayGenericException BitPayGenericException
* @throws BitPayApiException BitPayApiException
*/
async getBills(status) {
const params = { token: this.tokenContainer.getToken(Facade_1.Facade.Merchant) };
if (status) {
params['status'] = status;
}
const result = await this.bitPayClient.get('bills', params, true);
try {
return JSON.parse(result);
}
catch (e) {
BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Bill', e.message);
throw new Error();
}
}
/**
* Update a BitPay Bill.
*
* @param bill
* @param billId
* @returns Bill
* @throws BitPayApiException BitPayApiException class
* @throws BitPayGenericException BitPayGenericException class
*/
async update(bill, billId) {
const result = await this.bitPayClient.put('bills/' + billId, bill);
try {
return JSON.parse(result);
}
catch (e) {
BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Bill', e.message);
throw new Error();
}
}
/**
* Delivery a BitPay Bill.
*
* @param billId
* @param billToken
* @param signRequest
* @returns string
* @throws BitPayApiException BitPayApiException class
* @throws BitPayGenericException BitPayGenericException class
*/
async deliver(billId, billToken, signRequest) {
const params = { token: billToken };
const result = await this.bitPayClient.post('bills/' + billId + '/deliveries', params, signRequest);
try {
return JSON.parse(result) == 'Success';
}
catch (e) {
BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Bill', e.message);
throw new Error();
}
}
}
exports.BillClient = BillClient;
//# sourceMappingURL=BillClient.js.map