bitpay-sdk
Version:
Complete version of the NodeJS library for the new cryptographically secure BitPay API
44 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PayoutGroupClient = void 0;
const Facade_1 = require("../Facade");
const BitPayExceptionProvider_1 = require("../Exceptions/BitPayExceptionProvider");
const PayoutGroup_1 = require("../Model/Payout/PayoutGroup");
class PayoutGroupClient {
constructor(bitPayClient, tokenContainer, guidGenerator) {
/**
*
* @param payouts
* @throws BitPayApiException BitPayApiException class
* @throws BitPayGenericException BitPayGenericException class
*/
this.submitPayouts = async (payouts) => {
const params = { token: this.tokenContainer.getToken(Facade_1.Facade.Payout), instructions: payouts };
const result = await this.bitPayClient.post('payouts/group', params, true);
return PayoutGroupClient.getPayoutGroupResponse(result, 'created');
};
/**
*
* @param payoutGroupId
* @throws BitPayApiException BitPayApiException class
* @throws BitPayGenericException BitPayGenericException class
*/
this.cancelPayouts = async (payoutGroupId) => {
const params = { token: this.tokenContainer.getToken(Facade_1.Facade.Payout) };
const result = await this.bitPayClient.delete('payouts/group/' + payoutGroupId, params, true);
return PayoutGroupClient.getPayoutGroupResponse(result, 'cancelled');
};
this.bitPayClient = bitPayClient;
this.tokenContainer = tokenContainer;
this.guidGenerator = guidGenerator;
}
static getPayoutGroupResponse(json, responseType) {
const response = JSON.parse(json);
if (!(responseType in response)) {
BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Payout Group', response);
}
return new PayoutGroup_1.PayoutGroup(response[responseType], response['failed']);
}
}
exports.PayoutGroupClient = PayoutGroupClient;
//# sourceMappingURL=PayoutGroupClient.js.map