UNPKG

bitpay-sdk

Version:

Complete version of the NodeJS library for the new cryptographically secure BitPay API

106 lines 4.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PayoutClient = void 0; const Facade_1 = require("../Facade"); const BitPayResponseParser_1 = require("../util/BitPayResponseParser"); const BitPayExceptionProvider_1 = require("../Exceptions/BitPayExceptionProvider"); class PayoutClient { constructor(bitPayClient, tokenContainer, guidGenerator) { /** * Notify BitPay Payout. * * @param payoutId The id of the Payout to notify. * @returns boolean * @throws PayoutNotificationException */ this.requestNotification = async (payoutId) => { const params = { token: this.tokenContainer.getToken(Facade_1.Facade.Payout) }; const result = await this.bitPayClient.post('payouts/' + payoutId + '/notifications', params, true); try { return BitPayResponseParser_1.BitPayResponseParser.jsonToBoolean(result); } catch (e) { BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Payout', e.message); throw new Error(); } }; /** * Cancel a BitPay Payout. * * @param payoutId * @returns boolean * @throws PayoutDeleteException */ this.cancel = async (payoutId) => { const params = { token: this.tokenContainer.getToken(Facade_1.Facade.Payout) }; const result = await this.bitPayClient.delete('payouts/' + payoutId, params, true); try { return BitPayResponseParser_1.BitPayResponseParser.jsonToBoolean(result); } catch (e) { BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Payout', e.message); throw new Error(); } }; this.bitPayClient = bitPayClient; this.tokenContainer = tokenContainer; this.guidGenerator = guidGenerator; } /** * Submit a BitPay Payout. * * @param payout Payout object with request parameters defined. * @returns Payout * @throws PayoutCreationException */ async submit(payout) { payout.token = this.tokenContainer.getToken(Facade_1.Facade.Payout); const result = await this.bitPayClient.post('payouts', payout, true); try { return JSON.parse(result); } catch (e) { BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Payout', e.message); throw new Error(); } } /** * Retrieve a BitPay payout by payout id using. The client must have been previously authorized * for the payout facade. * * @param payoutId The id of the payout to retrieve. * @returns Payout * @throws PayoutQueryException */ async get(payoutId) { const params = { token: this.tokenContainer.getToken(Facade_1.Facade.Payout) }; const result = await this.bitPayClient.get('payouts/' + payoutId, params, true); try { return JSON.parse(result); } catch (e) { BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Payout', e.message); throw new Error(); } } /** * Retrieve a collection of BitPay payouts. * * @param params * @returns Payout[] * @throws PayoutQueryException */ async getPayouts(params) { params['token'] = this.tokenContainer.getToken(Facade_1.Facade.Payout); const result = await this.bitPayClient.get('payouts', params, true); try { return JSON.parse(result); } catch (e) { BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Payout', e.message); throw new Error(); } } } exports.PayoutClient = PayoutClient; //# sourceMappingURL=PayoutClient.js.map