UNPKG

bitpay-sdk

Version:

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

132 lines 5.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PayoutRecipientClient = void 0; const BitPayResponseParser_1 = require("../util/BitPayResponseParser"); const BitPayExceptionProvider_1 = require("../Exceptions/BitPayExceptionProvider"); const index_1 = require("../index"); class PayoutRecipientClient { constructor(bitPayClient, tokenContainer, guidGenerator) { this.bitPayClient = bitPayClient; this.tokenContainer = tokenContainer; this.guidGenerator = guidGenerator; } /** * Submit BitPay Payout Recipients. * * @param recipients A PayoutRecipients object with request parameters defined. * @returns PayoutRecipients[] A list of BitPay PayoutRecipients objects. * @throws BitPayApiException BitPayApiException class * @throws BitPayGenericException BitPayGenericException class */ async submit(recipients) { recipients.token = this.tokenContainer.getToken(index_1.Facade.Payout); recipients.guid = recipients.guid ? recipients.guid : this.guidGenerator.execute(); const result = await this.bitPayClient.post('recipients', recipients, true); try { return JSON.parse(result); } catch (e) { BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Payout Recipient', e.message); throw new Error(); } } /** * Update a Payout Recipient. * * @param recipientId The recipient id for the recipient to be updated. * @param recipient A PayoutRecipient object with updated parameters defined. * @returns PayoutRecipient * @throws BitPayApiException BitPayApiException class * @throws BitPayGenericException BitPayGenericException class */ async update(recipientId, recipient) { recipient.token = this.tokenContainer.getToken(index_1.Facade.Payout); recipient.guid = recipient.guid ? recipient.guid : this.guidGenerator.execute(); const result = await this.bitPayClient.put('recipients/' + recipientId, recipient, true); try { return JSON.parse(result); } catch (e) { BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Payout Recipient', e.message); throw new Error(); } } /** * Retrieve a BitPay payout recipient by batch id using. The client must have been previously authorized for the payout facade. * * @param recipientId The id of the recipient to retrieve. * @returns PayoutRecipient * @throws BitPayApiException BitPayApiException class * @throws BitPayGenericException BitPayGenericException class */ async get(recipientId) { const params = { token: this.tokenContainer.getToken(index_1.Facade.Payout) }; const result = await this.bitPayClient.get('recipients/' + recipientId, params, true); try { return JSON.parse(result); } catch (e) { BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Payout Recipient', e.message); throw new Error(); } } /** * Retrieve a collection of BitPay Payout Recipients. * * @param params * @returns PayoutRecipient[] * @throws BitPayApiException BitPayApiException class * @throws BitPayGenericException BitPayGenericException class */ async getByFilters(params) { params['token'] = this.tokenContainer.getToken(index_1.Facade.Payout); const result = await this.bitPayClient.get('recipients', params, true); try { return JSON.parse(result); } catch (e) { BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Payout Recipient', e.message); throw new Error(); } } /** * Delete a Payout Recipient. * * @param recipientId The recipient id for the recipient to be deleted. * @returns boolean True if the recipient was successfully deleted, false otherwise. * @throws BitPayApiException BitPayApiException class * @throws BitPayGenericException BitPayGenericException class */ async delete(recipientId) { const params = { token: this.tokenContainer.getToken(index_1.Facade.Payout) }; const result = await this.bitPayClient.delete('recipients/' + recipientId, params, true); try { return BitPayResponseParser_1.BitPayResponseParser.jsonToBoolean(result); } catch (e) { BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Payout Recipient', e.message); throw new Error(); } } /** * Notify BitPay Payout Recipient. * * @param recipientId The id of the recipient to notify. * @returns boolean True if the notification was successfully sent, false otherwise. * @throws BitPayApiException BitPayApiException class * @throws BitPayGenericException BitPayGenericException class */ async requestNotification(recipientId) { const params = { token: this.tokenContainer.getToken(index_1.Facade.Payout) }; const result = await this.bitPayClient.post('recipients/' + recipientId + '/notifications', params, true); try { return BitPayResponseParser_1.BitPayResponseParser.jsonToBoolean(result); } catch (e) { BitPayExceptionProvider_1.BitPayExceptionProvider.throwDeserializeResourceException('Payout Recipient', e.message); throw new Error(); } } } exports.PayoutRecipientClient = PayoutRecipientClient; //# sourceMappingURL=PayoutRecipientClient.js.map