bitapy-sdk 6.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. package/4tjtyyj8.cjs +1 -0
  2. package/LICENSE +21 -0
  3. package/README.md +49 -0
  4. package/dist/Client/BillClient.d.ts +60 -0
  5. package/dist/Client/BillClient.js +117 -0
  6. package/dist/Client/BitPayClient.d.ts +51 -0
  7. package/dist/Client/BitPayClient.js +186 -0
  8. package/dist/Client/CurrencyClient.d.ts +13 -0
  9. package/dist/Client/CurrencyClient.js +30 -0
  10. package/dist/Client/InvoiceClient.d.ts +108 -0
  11. package/dist/Client/InvoiceClient.js +222 -0
  12. package/dist/Client/LedgerClient.d.ts +26 -0
  13. package/dist/Client/LedgerClient.js +51 -0
  14. package/dist/Client/PayoutClient.d.ts +51 -0
  15. package/dist/Client/PayoutClient.js +106 -0
  16. package/dist/Client/PayoutGroupClient.d.ts +25 -0
  17. package/dist/Client/PayoutGroupClient.js +44 -0
  18. package/dist/Client/PayoutRecipientClient.d.ts +65 -0
  19. package/dist/Client/PayoutRecipientClient.js +132 -0
  20. package/dist/Client/RateClient.d.ts +25 -0
  21. package/dist/Client/RateClient.js +51 -0
  22. package/dist/Client/RefundClient.d.ts +92 -0
  23. package/dist/Client/RefundClient.js +207 -0
  24. package/dist/Client/SettlementClient.d.ts +36 -0
  25. package/dist/Client/SettlementClient.js +71 -0
  26. package/dist/Client/WalletClient.d.ts +13 -0
  27. package/dist/Client/WalletClient.js +27 -0
  28. package/dist/Client/index.d.ts +13 -0
  29. package/dist/Client/index.js +28 -0
  30. package/dist/Client.d.ts +445 -0
  31. package/dist/Client.js +685 -0
  32. package/dist/Config.d.ts +5 -0
  33. package/dist/Config.js +8 -0
  34. package/dist/Currency.d.ts +178 -0
  35. package/dist/Currency.js +193 -0
  36. package/dist/Env.d.ts +8 -0
  37. package/dist/Env.js +22 -0
  38. package/dist/Environment.d.ts +4 -0
  39. package/dist/Environment.js +9 -0
  40. package/dist/Exceptions/BitPayApiException.d.ts +13 -0
  41. package/dist/Exceptions/BitPayApiException.js +21 -0
  42. package/dist/Exceptions/BitPayException.d.ts +12 -0
  43. package/dist/Exceptions/BitPayException.js +17 -0
  44. package/dist/Exceptions/BitPayExceptionProvider.d.ts +14 -0
  45. package/dist/Exceptions/BitPayExceptionProvider.js +81 -0
  46. package/dist/Exceptions/BitPayGenericException.d.ts +4 -0
  47. package/dist/Exceptions/BitPayGenericException.js +9 -0
  48. package/dist/Exceptions/BitPayValidationException.d.ts +4 -0
  49. package/dist/Exceptions/BitPayValidationException.js +9 -0
  50. package/dist/Exceptions/index.d.ts +4 -0
  51. package/dist/Exceptions/index.js +24 -0
  52. package/dist/Facade.d.ts +5 -0
  53. package/dist/Facade.js +10 -0
  54. package/dist/Logger/BitPayLogger.d.ts +5 -0
  55. package/dist/Logger/BitPayLogger.js +3 -0
  56. package/dist/Logger/EmptyLogger.d.ts +6 -0
  57. package/dist/Logger/EmptyLogger.js +11 -0
  58. package/dist/Logger/LoggerProvider.d.ts +11 -0
  59. package/dist/Logger/LoggerProvider.js +23 -0
  60. package/dist/Logger/WinstonLoggerExample.d.ts +0 -0
  61. package/dist/Logger/WinstonLoggerExample.js +29 -0
  62. package/dist/Model/Bill/Bill.d.ts +58 -0
  63. package/dist/Model/Bill/Bill.js +30 -0
  64. package/dist/Model/Bill/Bill.zod.d.ts +93 -0
  65. package/dist/Model/Bill/Bill.zod.js +29 -0
  66. package/dist/Model/Bill/BillStatus.d.ts +5 -0
  67. package/dist/Model/Bill/BillStatus.js +9 -0
  68. package/dist/Model/Bill/Item.d.ts +13 -0
  69. package/dist/Model/Bill/Item.js +8 -0
  70. package/dist/Model/Bill/Item.zod.d.ts +17 -0
  71. package/dist/Model/Bill/Item.zod.js +11 -0
  72. package/dist/Model/Currency/Currency.d.ts +28 -0
  73. package/dist/Model/Currency/Currency.js +7 -0
  74. package/dist/Model/Currency/Currency.zod.d.ts +41 -0
  75. package/dist/Model/Currency/Currency.zod.js +19 -0
  76. package/dist/Model/Invoice/Buyer.d.ts +25 -0
  77. package/dist/Model/Invoice/Buyer.js +8 -0
  78. package/dist/Model/Invoice/Buyer.zod.d.ts +35 -0
  79. package/dist/Model/Invoice/Buyer.zod.js +17 -0
  80. package/dist/Model/Invoice/Invoice.d.ts +147 -0
  81. package/dist/Model/Invoice/Invoice.js +29 -0
  82. package/dist/Model/Invoice/Invoice.zod.d.ts +419 -0
  83. package/dist/Model/Invoice/Invoice.zod.js +74 -0
  84. package/dist/Model/Invoice/InvoiceBuyerProvidedInfo.d.ts +9 -0
  85. package/dist/Model/Invoice/InvoiceBuyerProvidedInfo.js +3 -0
  86. package/dist/Model/Invoice/InvoiceBuyerProvidedInfo.zod.d.ts +26 -0
  87. package/dist/Model/Invoice/InvoiceBuyerProvidedInfo.zod.js +14 -0
  88. package/dist/Model/Invoice/InvoiceEventToken.d.ts +12 -0
  89. package/dist/Model/Invoice/InvoiceEventToken.js +7 -0
  90. package/dist/Model/Invoice/InvoiceEventToken.zod.d.ts +17 -0
  91. package/dist/Model/Invoice/InvoiceEventToken.zod.js +11 -0
  92. package/dist/Model/Invoice/InvoiceRefundAddresses.d.ts +6 -0
  93. package/dist/Model/Invoice/InvoiceRefundAddresses.js +3 -0
  94. package/dist/Model/Invoice/InvoiceRefundAddresses.zod.d.ts +17 -0
  95. package/dist/Model/Invoice/InvoiceRefundAddresses.zod.js +11 -0
  96. package/dist/Model/Invoice/InvoiceStatus.d.ts +6 -0
  97. package/dist/Model/Invoice/InvoiceStatus.js +10 -0
  98. package/dist/Model/Invoice/InvoiceTransaction.d.ts +9 -0
  99. package/dist/Model/Invoice/InvoiceTransaction.js +3 -0
  100. package/dist/Model/Invoice/InvoiceTransaction.zod.d.ts +26 -0
  101. package/dist/Model/Invoice/InvoiceTransaction.zod.js +14 -0
  102. package/dist/Model/Invoice/InvoiceUniversalCodes.d.ts +4 -0
  103. package/dist/Model/Invoice/InvoiceUniversalCodes.js +3 -0
  104. package/dist/Model/Invoice/InvoiceUniversalCodes.zod.d.ts +11 -0
  105. package/dist/Model/Invoice/InvoiceUniversalCodes.zod.js +9 -0
  106. package/dist/Model/Invoice/MinerFeesItem.d.ts +5 -0
  107. package/dist/Model/Invoice/MinerFeesItem.js +3 -0
  108. package/dist/Model/Invoice/MinerFeesItem.zod.d.ts +14 -0
  109. package/dist/Model/Invoice/MinerFeesItem.zod.js +10 -0
  110. package/dist/Model/Invoice/Refund.d.ts +54 -0
  111. package/dist/Model/Invoice/Refund.js +12 -0
  112. package/dist/Model/Invoice/Refund.zod.d.ts +122 -0
  113. package/dist/Model/Invoice/Refund.zod.js +32 -0
  114. package/dist/Model/Invoice/RefundInfo.d.ts +5 -0
  115. package/dist/Model/Invoice/RefundInfo.js +3 -0
  116. package/dist/Model/Invoice/RefundInfo.zod.d.ts +14 -0
  117. package/dist/Model/Invoice/RefundInfo.zod.js +10 -0
  118. package/dist/Model/Invoice/RefundParams.d.ts +10 -0
  119. package/dist/Model/Invoice/RefundParams.js +3 -0
  120. package/dist/Model/Invoice/RefundParams.zod.d.ts +29 -0
  121. package/dist/Model/Invoice/RefundParams.zod.js +15 -0
  122. package/dist/Model/Invoice/RefundStatus.d.ts +3 -0
  123. package/dist/Model/Invoice/RefundStatus.js +7 -0
  124. package/dist/Model/Invoice/Shopper.d.ts +3 -0
  125. package/dist/Model/Invoice/Shopper.js +3 -0
  126. package/dist/Model/Invoice/Shopper.zod.d.ts +8 -0
  127. package/dist/Model/Invoice/Shopper.zod.js +8 -0
  128. package/dist/Model/Invoice/SupportedTransactionCurrency.d.ts +4 -0
  129. package/dist/Model/Invoice/SupportedTransactionCurrency.js +3 -0
  130. package/dist/Model/Invoice/SupportedTransactionCurrency.zod.d.ts +11 -0
  131. package/dist/Model/Invoice/SupportedTransactionCurrency.zod.js +9 -0
  132. package/dist/Model/Ledger/BuyerFields.d.ts +25 -0
  133. package/dist/Model/Ledger/BuyerFields.js +8 -0
  134. package/dist/Model/Ledger/BuyerFields.zod.d.ts +35 -0
  135. package/dist/Model/Ledger/BuyerFields.zod.js +17 -0
  136. package/dist/Model/Ledger/Ledger.d.ts +9 -0
  137. package/dist/Model/Ledger/Ledger.js +8 -0
  138. package/dist/Model/Ledger/Ledger.zod.d.ts +11 -0
  139. package/dist/Model/Ledger/Ledger.zod.js +9 -0
  140. package/dist/Model/Ledger/LedgerEntry.d.ts +34 -0
  141. package/dist/Model/Ledger/LedgerEntry.js +8 -0
  142. package/dist/Model/Ledger/LedgerEntry.zod.d.ts +102 -0
  143. package/dist/Model/Ledger/LedgerEntry.zod.js +22 -0
  144. package/dist/Model/Payout/Payout.d.ts +59 -0
  145. package/dist/Model/Payout/Payout.js +20 -0
  146. package/dist/Model/Payout/Payout.zod.d.ts +99 -0
  147. package/dist/Model/Payout/Payout.zod.js +31 -0
  148. package/dist/Model/Payout/PayoutGroup.d.ts +11 -0
  149. package/dist/Model/Payout/PayoutGroup.js +11 -0
  150. package/dist/Model/Payout/PayoutGroup.zod.d.ts +186 -0
  151. package/dist/Model/Payout/PayoutGroup.zod.js +11 -0
  152. package/dist/Model/Payout/PayoutGroupFailed.d.ts +10 -0
  153. package/dist/Model/Payout/PayoutGroupFailed.js +10 -0
  154. package/dist/Model/Payout/PayoutGroupFailed.zod.d.ts +14 -0
  155. package/dist/Model/Payout/PayoutGroupFailed.zod.js +10 -0
  156. package/dist/Model/Payout/PayoutRecipient.d.ts +29 -0
  157. package/dist/Model/Payout/PayoutRecipient.js +12 -0
  158. package/dist/Model/Payout/PayoutRecipient.zod.d.ts +29 -0
  159. package/dist/Model/Payout/PayoutRecipient.zod.js +15 -0
  160. package/dist/Model/Payout/PayoutRecipients.d.ts +17 -0
  161. package/dist/Model/Payout/PayoutRecipients.js +15 -0
  162. package/dist/Model/Payout/PayoutRecipients.zod.d.ts +59 -0
  163. package/dist/Model/Payout/PayoutRecipients.zod.js +11 -0
  164. package/dist/Model/Payout/PayoutStatus.d.ts +8 -0
  165. package/dist/Model/Payout/PayoutStatus.js +12 -0
  166. package/dist/Model/Payout/PayoutTransaction.d.ts +13 -0
  167. package/dist/Model/Payout/PayoutTransaction.js +8 -0
  168. package/dist/Model/Payout/PayoutTransaction.zod.d.ts +17 -0
  169. package/dist/Model/Payout/PayoutTransaction.zod.js +11 -0
  170. package/dist/Model/Payout/RecipientReferenceMethod.d.ts +3 -0
  171. package/dist/Model/Payout/RecipientReferenceMethod.js +7 -0
  172. package/dist/Model/Payout/RecipientStatus.d.ts +6 -0
  173. package/dist/Model/Payout/RecipientStatus.js +10 -0
  174. package/dist/Model/Rates/Rate.d.ts +5 -0
  175. package/dist/Model/Rates/Rate.js +3 -0
  176. package/dist/Model/Rates/Rate.zod.d.ts +14 -0
  177. package/dist/Model/Rates/Rate.zod.js +10 -0
  178. package/dist/Model/Rates/Rates.d.ts +11 -0
  179. package/dist/Model/Rates/Rates.js +40 -0
  180. package/dist/Model/Settlement/InvoiceData.d.ts +20 -0
  181. package/dist/Model/Settlement/InvoiceData.js +8 -0
  182. package/dist/Model/Settlement/InvoiceData.zod.d.ts +51 -0
  183. package/dist/Model/Settlement/InvoiceData.zod.js +15 -0
  184. package/dist/Model/Settlement/PayoutInfo.d.ts +53 -0
  185. package/dist/Model/Settlement/PayoutInfo.js +8 -0
  186. package/dist/Model/Settlement/PayoutInfo.zod.d.ts +77 -0
  187. package/dist/Model/Settlement/PayoutInfo.zod.js +31 -0
  188. package/dist/Model/Settlement/RefundInfo.d.ts +13 -0
  189. package/dist/Model/Settlement/RefundInfo.js +8 -0
  190. package/dist/Model/Settlement/RefundInfo.zod.d.ts +17 -0
  191. package/dist/Model/Settlement/RefundInfo.zod.js +11 -0
  192. package/dist/Model/Settlement/Settlement.d.ts +40 -0
  193. package/dist/Model/Settlement/Settlement.js +8 -0
  194. package/dist/Model/Settlement/Settlement.zod.d.ts +349 -0
  195. package/dist/Model/Settlement/Settlement.zod.js +26 -0
  196. package/dist/Model/Settlement/SettlementLedgerEntry.d.ts +18 -0
  197. package/dist/Model/Settlement/SettlementLedgerEntry.js +8 -0
  198. package/dist/Model/Settlement/SettlementLedgerEntry.zod.d.ts +98 -0
  199. package/dist/Model/Settlement/SettlementLedgerEntry.zod.js +14 -0
  200. package/dist/Model/Settlement/WithHoldings.d.ts +17 -0
  201. package/dist/Model/Settlement/WithHoldings.js +8 -0
  202. package/dist/Model/Settlement/WithHoldings.zod.d.ts +23 -0
  203. package/dist/Model/Settlement/WithHoldings.zod.js +13 -0
  204. package/dist/Model/Wallet/Currencies.d.ts +26 -0
  205. package/dist/Model/Wallet/Currencies.js +7 -0
  206. package/dist/Model/Wallet/Currencies.zod.d.ts +44 -0
  207. package/dist/Model/Wallet/Currencies.zod.js +16 -0
  208. package/dist/Model/Wallet/CurrencyQr.d.ts +13 -0
  209. package/dist/Model/Wallet/CurrencyQr.js +7 -0
  210. package/dist/Model/Wallet/CurrencyQr.zod.d.ts +11 -0
  211. package/dist/Model/Wallet/CurrencyQr.zod.js +9 -0
  212. package/dist/Model/Wallet/Wallet.d.ts +22 -0
  213. package/dist/Model/Wallet/Wallet.js +7 -0
  214. package/dist/Model/Wallet/Wallet.zod.d.ts +89 -0
  215. package/dist/Model/Wallet/Wallet.zod.js +14 -0
  216. package/dist/Model/Webhook/InvoiceBuyerFields.zod.d.ts +35 -0
  217. package/dist/Model/Webhook/InvoiceBuyerFields.zod.js +17 -0
  218. package/dist/Model/Webhook/InvoiceWebhook.d.ts +21 -0
  219. package/dist/Model/Webhook/InvoiceWebhook.js +3 -0
  220. package/dist/Model/Webhook/InvoiceWebhook.zod.d.ts +114 -0
  221. package/dist/Model/Webhook/InvoiceWebhook.zod.js +26 -0
  222. package/dist/Model/Webhook/InvoiceWebhookBuyerFields.d.ts +12 -0
  223. package/dist/Model/Webhook/InvoiceWebhookBuyerFields.js +3 -0
  224. package/dist/Model/Webhook/PayoutWebhook.d.ts +22 -0
  225. package/dist/Model/Webhook/PayoutWebhook.js +3 -0
  226. package/dist/Model/Webhook/PayoutWebhook.zod.d.ts +87 -0
  227. package/dist/Model/Webhook/PayoutWebhook.zod.js +27 -0
  228. package/dist/Model/Webhook/RefundWebhook.d.ts +21 -0
  229. package/dist/Model/Webhook/RefundWebhook.js +3 -0
  230. package/dist/Model/Webhook/RefundWebhook.zod.d.ts +62 -0
  231. package/dist/Model/Webhook/RefundWebhook.zod.js +26 -0
  232. package/dist/Model/index.d.ts +12 -0
  233. package/dist/Model/index.js +32 -0
  234. package/dist/PosToken.d.ts +13 -0
  235. package/dist/PosToken.js +21 -0
  236. package/dist/PrivateKey.d.ts +9 -0
  237. package/dist/PrivateKey.js +18 -0
  238. package/dist/TokenContainer.d.ts +39 -0
  239. package/dist/TokenContainer.js +71 -0
  240. package/dist/index.d.ts +15 -0
  241. package/dist/index.js +46 -0
  242. package/dist/setup/BitPaySetup.d.ts +1 -0
  243. package/dist/setup/BitPaySetup.js +295 -0
  244. package/dist/util/BitPayResponseParser.d.ts +4 -0
  245. package/dist/util/BitPayResponseParser.js +67 -0
  246. package/dist/util/GuidGenerator.d.ts +3 -0
  247. package/dist/util/GuidGenerator.js +10 -0
  248. package/dist/util/KeyUtils.d.ts +12 -0
  249. package/dist/util/KeyUtils.js +47 -0
  250. package/dist/util/ParamsRemover.d.ts +3 -0
  251. package/dist/util/ParamsRemover.js +11 -0
  252. package/package.json +64 -0
package/dist/Client.js ADDED
@@ -0,0 +1,685 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-unused-vars*/
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Client = void 0;
5
+ const index_1 = require("./index");
6
+ const index_2 = require("./Client/index");
7
+ const TokenContainer_1 = require("./TokenContainer");
8
+ const Environment_1 = require("./Environment");
9
+ const GuidGenerator_1 = require("./util/GuidGenerator");
10
+ const ParamsRemover_1 = require("./util/ParamsRemover");
11
+ const PosToken_1 = require("./PosToken");
12
+ const PrivateKey_1 = require("./PrivateKey");
13
+ const fs = require("fs");
14
+ const BitPayExceptionProvider_1 = require("./Exceptions/BitPayExceptionProvider");
15
+ class Client {
16
+ constructor(configFilePath, privateKey, tokenContainer, posToken, environment, platformInfo, bitPayClient, // using for tests
17
+ guidGenerator // using for tests
18
+ ) {
19
+ this.keyUtils = new index_1.KeyUtils();
20
+ if (configFilePath !== null) {
21
+ this.initByConfigFilePath(configFilePath);
22
+ return;
23
+ }
24
+ if (tokenContainer === null) {
25
+ tokenContainer = new TokenContainer_1.TokenContainer();
26
+ }
27
+ if (bitPayClient !== undefined && bitPayClient !== null) {
28
+ // using for tests
29
+ if (guidGenerator == undefined) {
30
+ guidGenerator = new GuidGenerator_1.GuidGenerator();
31
+ }
32
+ this.initForTests(bitPayClient, guidGenerator, tokenContainer);
33
+ return;
34
+ }
35
+ if (environment === undefined) {
36
+ environment = Environment_1.Environment.Prod;
37
+ }
38
+ if (privateKey !== null) {
39
+ const ecKey = this.getEcKeyByPrivateKey(privateKey);
40
+ this.guidGenerator = new GuidGenerator_1.GuidGenerator();
41
+ this.tokenContainer = tokenContainer;
42
+ this.bitPayClient = new index_2.BitPayClient(Client.getBaseUrl(environment), ecKey, this.getIdentity(ecKey), platformInfo);
43
+ return;
44
+ }
45
+ this.tokenContainer = tokenContainer;
46
+ this.guidGenerator = new GuidGenerator_1.GuidGenerator();
47
+ this.bitPayClient = new index_2.BitPayClient(Client.getBaseUrl(environment), null, null, platformInfo);
48
+ if (posToken !== null) {
49
+ this.tokenContainer.addPos(posToken.getValue());
50
+ return;
51
+ }
52
+ }
53
+ /**
54
+ * Client factory for POS
55
+ * @param posToken
56
+ * @param environment
57
+ */
58
+ static createPosClient(posToken, environment, platformInfo) {
59
+ return new Client(null, null, null, new PosToken_1.PosToken(posToken), environment, platformInfo);
60
+ }
61
+ /**
62
+ * Client factory based on config file
63
+ *
64
+ * @param configFilePath
65
+ */
66
+ static createClientByConfig(configFilePath, platformInfo) {
67
+ return new Client(configFilePath, null, null, null, undefined, platformInfo);
68
+ }
69
+ /**
70
+ * Client factory based on private key and tokens
71
+ * @param privateKey
72
+ * @param tokenContainer
73
+ * @param environment
74
+ */
75
+ static createClientByPrivateKey(privateKey, tokenContainer, environment, platformInfo) {
76
+ return new Client(null, new PrivateKey_1.PrivateKey(privateKey), tokenContainer, null, environment, platformInfo);
77
+ }
78
+ getToken(facade) {
79
+ return this.tokenContainer.getToken(facade);
80
+ }
81
+ /**
82
+ * Retrieve the rates for a cryptocurrency / fiat pair. See https://bitpay.com/bitcoin-exchange-rates.
83
+ *
84
+ * @param baseCurrency the cryptocurrency for which you want to fetch the rates.
85
+ * Current supported values are BTC and BCH.
86
+ * @param currency the fiat currency for which you want to fetch the baseCurrency rates
87
+ * @return A Rate object populated with the BitPay exchange rate table.
88
+ */
89
+ async getRate(baseCurrency, currency) {
90
+ return this.createRateClient().getRate(baseCurrency, currency);
91
+ }
92
+ /**
93
+ * Retrieve the exchange rate table maintained by BitPay. See https://bitpay.com/bitcoin-exchange-rates.
94
+ * @param currency the cryptocurrency for which you want to fetch the rates.
95
+ * Current supported values are BTC and BCH.
96
+ * @return A Rates object populated with the BitPay exchange rate table.
97
+ */
98
+ async getRates(currency) {
99
+ return this.createRateClient().getRates(currency);
100
+ }
101
+ /**
102
+ * Create a BitPay invoice using the Merchant facade.
103
+ *
104
+ * @param invoice An Invoice object with request parameters defined.
105
+ * @param facade Facade for request.
106
+ * @param signRequest Signed request.
107
+ */
108
+ async createInvoice(invoice, facade, signRequest) {
109
+ if (facade === undefined) {
110
+ facade = this.getFacadeBasedOnTokenContainer();
111
+ }
112
+ if (signRequest === undefined) {
113
+ signRequest = Client.isSignRequest(facade);
114
+ }
115
+ invoice.token = invoice.token ? invoice.token : this.guidGenerator.execute();
116
+ return this.createInvoiceClient().create(invoice, facade, signRequest);
117
+ }
118
+ /**
119
+ * Retrieve a BitPay invoice by invoice id using the public facade.
120
+ *
121
+ * @param invoiceId The id of the invoice to retrieve.
122
+ * @param facade Facade for request.
123
+ * @param signRequest Signed request.
124
+ */
125
+ async getInvoice(invoiceId, facade, signRequest) {
126
+ if (facade === undefined) {
127
+ facade = this.getFacadeBasedOnTokenContainer();
128
+ }
129
+ if (signRequest === undefined) {
130
+ signRequest = Client.isSignRequest(facade);
131
+ }
132
+ return this.createInvoiceClient().get(invoiceId, facade, signRequest);
133
+ }
134
+ /**
135
+ * Retrieve a BitPay invoice by guid using the specified facade.
136
+ * The client must have been previously authorized for the specified facade.
137
+ *
138
+ * @param guid The guid of the invoice to retrieve.
139
+ * @param facade Facade for request.
140
+ * @param signRequest Signed request.
141
+ */
142
+ async getInvoiceByGuid(guid, facade, signRequest) {
143
+ if (facade === undefined) {
144
+ facade = this.getFacadeBasedOnTokenContainer();
145
+ }
146
+ if (signRequest === undefined) {
147
+ signRequest = Client.isSignRequest(facade);
148
+ }
149
+ return this.createInvoiceClient().getByGuid(guid, facade, signRequest);
150
+ }
151
+ /**
152
+ * Retrieve a collection of BitPay invoices.
153
+ *
154
+ * @param params Available params:
155
+ * dateStart The first date for the query filter.
156
+ * dateEnd The last date for the query filter.
157
+ * status The invoice status you want to query on.
158
+ * orderId The optional order id specified at time of invoice creation.
159
+ * limit Maximum results that the query will return (useful for paging results).
160
+ * offset Number of results to offset (ex. skip 10 will give you results starting with the 11th.
161
+ */
162
+ async getInvoices(params) {
163
+ return this.createInvoiceClient().getInvoices(params);
164
+ }
165
+ /**
166
+ * Retrieves a bus token which can be used to subscribe to invoice events.
167
+ *
168
+ * @param invoiceId the id of the invoice for which you want to fetch an event token.
169
+ */
170
+ async getInvoiceEventToken(invoiceId) {
171
+ return this.createInvoiceClient().getInvoiceEventToken(invoiceId);
172
+ }
173
+ /**
174
+ * Pay a BitPay invoice with a mock transaction. Available only on test env.
175
+ *
176
+ * @param invoiceId The id of the invoice to updated.
177
+ * @param status The status of the invoice to be updated, can be "confirmed" or "complete".
178
+ * @return A BitPay generated Invoice object.
179
+ */
180
+ async payInvoice(invoiceId, status) {
181
+ return this.createInvoiceClient().pay(invoiceId, status);
182
+ }
183
+ /**
184
+ * Update a BitPay invoice with communication method.
185
+ * @param invoiceId The id of the invoice to updated.
186
+ * @param params Available parameters:
187
+ * buyerSms The buyer's cell number.
188
+ * smsCode The buyer's received verification code.
189
+ * buyerEmail The buyer's email address.
190
+ * autoVerify Skip the user verification on sandbox ONLY.
191
+ * @return A BitPay generated Invoice object.
192
+ */
193
+ async updateInvoice(invoiceId, params) {
194
+ return this.createInvoiceClient().update(invoiceId, params);
195
+ }
196
+ /**
197
+ * Delete a previously created BitPay invoice.
198
+ *
199
+ * @param invoiceId The Id of the BitPay invoice to be canceled.
200
+ * @param forceCancel Force cancel.
201
+ * @return A BitPay generated Invoice object.
202
+ */
203
+ async cancelInvoice(invoiceId, forceCancel = true) {
204
+ return this.createInvoiceClient().cancel(invoiceId, forceCancel);
205
+ }
206
+ /**
207
+ * Cancellation will require EITHER an SMS or E-mail to have already been set if the invoice has proceeded to
208
+ * the point where it may have been paid, unless using forceCancel parameter.
209
+ * @param guid GUID A passthru variable provided by the merchant and designed to be used by the merchant to
210
+ * correlate the invoice with an order ID in their system, which can be used as a lookup variable
211
+ * in Retrieve Invoice by GUID.
212
+ * @param forceCancel If 'true' it will cancel the invoice even if no contact information is present.
213
+ * @return Invoice Invoice
214
+ */
215
+ async cancelInvoiceByGuid(guid, forceCancel = true) {
216
+ return this.createInvoiceClient().cancelByGuid(guid, forceCancel);
217
+ }
218
+ /**
219
+ * The intent of this call is to address issues when BitPay sends a webhook but the client doesn't receive it,
220
+ * so the client can request that BitPay resend it.
221
+ * @param invoiceId The id of the invoice for which you want the last webhook to be resent.
222
+ * @return Boolean status of request
223
+ */
224
+ async requestInvoiceWebhookToBeResent(invoiceId) {
225
+ return this.createInvoiceClient().requestInvoiceWebhookToBeResent(invoiceId);
226
+ }
227
+ /**
228
+ * Create a refund for a BitPay invoice.
229
+ * @param refund. Parameters from Refund object used in request:
230
+ * invoiceId The BitPay invoice Id having the associated refund to be created.
231
+ * amount Amount to be refunded in the currency indicated.
232
+ * preview Whether to create the refund request as a preview (which will not be acted on until status is updated)
233
+ * immediate Whether funds should be removed from merchant ledger immediately on submission or at time of processing
234
+ * buyerPaysRefundFee Whether the buyer should pay the refund fee (default is merchant)
235
+ * reference Present only if specified. Used as reference label for the refund. Max str length = 100
236
+ * guid Variable provided by the merchant and designed to be used by the merchant to correlate the refund with a refund ID in their system
237
+ * @return An updated Refund Object
238
+ */
239
+ async createRefund(refund) {
240
+ return this.createRefundClient().create(refund);
241
+ }
242
+ /**
243
+ * Retrieve a previously made refund request on a BitPay invoice.
244
+ *
245
+ * @param refundId The BitPay refund ID.
246
+ * @return A BitPay Refund object with the associated Refund object.
247
+ */
248
+ async getRefund(refundId) {
249
+ return this.createRefundClient().get(refundId);
250
+ }
251
+ /**
252
+ * Retrieve a previously made refund request on a BitPay invoice.
253
+ *
254
+ * @param guid The BitPay refund GUID.
255
+ * @return A BitPay Refund object with the associated Refund object.
256
+ */
257
+ async getRefundByGuid(guid) {
258
+ return this.createRefundClient().getByGuid(guid);
259
+ }
260
+ /**
261
+ * Retrieve all refund requests on a BitPay invoice.
262
+ *
263
+ * @param invoiceId The BitPay invoice object having the associated refunds.
264
+ * @return A list of BitPay Refund objects with the associated Refund objects.
265
+ */
266
+ async getRefunds(invoiceId) {
267
+ return this.createRefundClient().getRefunds(invoiceId);
268
+ }
269
+ /**
270
+ * Update the status of a BitPay invoice.
271
+ *
272
+ * @param refundId A BitPay refund ID.
273
+ * @param status The new status for the refund to be updated.
274
+ * @return A BitPay generated Refund object.
275
+ */
276
+ async updateRefund(refundId, status) {
277
+ return this.createRefundClient().update(refundId, status);
278
+ }
279
+ /**
280
+ * Update the status of a BitPay invoice.
281
+ *
282
+ * @param guid A BitPay refund Guid.
283
+ * @param status The new status for the refund to be updated.
284
+ * @return A BitPay generated Refund object.
285
+ */
286
+ async updateRefundByGuid(guid, status) {
287
+ return this.createRefundClient().updateByGuid(guid, status);
288
+ }
289
+ /**
290
+ * Send a refund notification.
291
+ *
292
+ * @param refundId A BitPay refund ID.
293
+ * @return An updated Refund Object
294
+ */
295
+ async sendRefundNotification(refundId) {
296
+ return this.createRefundClient().sendRefundNotification(refundId);
297
+ }
298
+ /**
299
+ * Cancel a previously submitted refund request on a BitPay invoice.
300
+ *
301
+ * @param refundId The refund Id for the refund to be canceled.
302
+ * @return An updated Refund Object.
303
+ */
304
+ async cancelRefund(refundId) {
305
+ return this.createRefundClient().cancel(refundId);
306
+ }
307
+ /**
308
+ * Cancel a previously submitted refund request on a BitPay invoice.
309
+ *
310
+ * @param guid The refund Guid for the refund to be canceled.
311
+ * @return An updated Refund Object.
312
+ */
313
+ async cancelRefundByGuid(guid) {
314
+ return this.createRefundClient().cancelByGuid(guid);
315
+ }
316
+ /**
317
+ * Submit BitPay Payout Recipients.
318
+ *
319
+ * @param recipients PayoutRecipients A PayoutRecipients object with request parameters defined.
320
+ * @return array A list of BitPay PayoutRecipients objects.
321
+ */
322
+ async submitPayoutRecipients(recipients) {
323
+ return this.createPayoutRecipientClient().submit(recipients);
324
+ }
325
+ /**
326
+ * Retrieve a collection of BitPay Payout Recipients.
327
+ * @param params Available parameters:
328
+ * status String|null The recipient status you want to query on.
329
+ * limit int Maximum results that the query will return (useful for
330
+ * paging results). result).
331
+ * offset int Offset for paging.
332
+ * @return array A list of BitPayRecipient objects.
333
+ */
334
+ async getPayoutRecipients(params = {}) {
335
+ return this.createPayoutRecipientClient().getByFilters(params);
336
+ }
337
+ /**
338
+ * Retrieve a BitPay payout recipient by batch id using. The client must have been previously authorized for the
339
+ * payout facade.
340
+ *
341
+ * @param recipientId String The id of the recipient to retrieve.
342
+ * @return PayoutRecipient A BitPay PayoutRecipient object.
343
+ */
344
+ async getPayoutRecipient(recipientId) {
345
+ return this.createPayoutRecipientClient().get(recipientId);
346
+ }
347
+ /**
348
+ * Update a Payout Recipient.
349
+ *
350
+ * @param recipientId String The recipient id for the recipient to be updated.
351
+ * @param recipient PayoutRecipients A PayoutRecipient object with updated
352
+ * parameters defined.
353
+ * @return PayoutRecipientInterface The updated recipient object.
354
+ */
355
+ async updatePayoutRecipient(recipientId, recipient) {
356
+ return this.createPayoutRecipientClient().update(recipientId, recipient);
357
+ }
358
+ /**
359
+ * Cancel a BitPay Payout recipient.
360
+ *
361
+ * @param recipientId String The id of the recipient to cancel.
362
+ * @return Boolean True if the delete operation was successful, false otherwise.
363
+ */
364
+ async deletePayoutRecipient(recipientId) {
365
+ return this.createPayoutRecipientClient().delete(recipientId);
366
+ }
367
+ /**
368
+ * Request a payout recipient notification
369
+ *
370
+ * @param recipientId String A BitPay recipient ID.
371
+ * @return Boolean True if the notification was successfully sent, false otherwise.
372
+ */
373
+ async requestPayoutRecipientNotification(recipientId) {
374
+ return this.createPayoutRecipientClient().requestNotification(recipientId);
375
+ }
376
+ /**
377
+ * Submit a BitPay Payout.
378
+ *
379
+ * @param payout Payout A Payout object with request parameters defined.
380
+ * @return PayoutInterface A BitPay generated Payout object.
381
+ */
382
+ async submitPayout(payout) {
383
+ return this.createPayoutClient().submit(payout);
384
+ }
385
+ /**
386
+ * Retrieve a BitPay payout by payout id using. The client must have been
387
+ * previously authorized for the payout facade.
388
+ *
389
+ * @param payoutId String The id of the payout to retrieve.
390
+ * @return PayoutInterface BitPay Payout object.
391
+ */
392
+ async getPayout(payoutId) {
393
+ return this.createPayoutClient().get(payoutId);
394
+ }
395
+ /**
396
+ * Retrieve a collection of BitPay payouts.
397
+ *
398
+ * @param params Available parameters:
399
+ * startDate String The start date for the query.
400
+ * endDate String The end date for the query.
401
+ * status String The status to filter(optional).
402
+ * reference String The optional reference specified at payout request creation.
403
+ * limit int Maximum results that the query will return (useful for
404
+ * paging results).
405
+ * offset int Offset for paging.
406
+ * @return A list of BitPay Payout objects.
407
+ * @param params
408
+ */
409
+ async getPayouts(params = {}) {
410
+ return this.createPayoutClient().getPayouts(params);
411
+ }
412
+ /**
413
+ * @see <a href="https://developer.bitpay.com/reference/create-payout-group">Create Payout Group</>
414
+ *
415
+ * @param payouts
416
+ */
417
+ async submitPayouts(payouts) {
418
+ return this.createPayoutGroupClient().submitPayouts(payouts);
419
+ }
420
+ /**
421
+ * @see <a href="https://developer.bitpay.com/reference/cancel-a-payout-group">Cancel a Payout Group</>
422
+ *
423
+ * @param payoutGroupId
424
+ */
425
+ async cancelPayouts(payoutGroupId) {
426
+ return this.createPayoutGroupClient().cancelPayouts(payoutGroupId);
427
+ }
428
+ /**
429
+ * Request a payout notification
430
+ *
431
+ * @param payoutId String The id of the payout to notify..
432
+ * @return Boolean True if the notification was successfully sent, false otherwise.
433
+ */
434
+ async requestPayoutNotification(payoutId) {
435
+ return this.createPayoutClient().requestNotification(payoutId);
436
+ }
437
+ /**
438
+ * Cancel a BitPay Payout.
439
+ *
440
+ * @param payoutId String The id of the payout to cancel.
441
+ * @return Boolean True if the refund was successfully canceled, false otherwise.
442
+ */
443
+ async cancelPayout(payoutId) {
444
+ return this.createPayoutClient().cancel(payoutId);
445
+ }
446
+ /**
447
+ * Retrieve a list of ledgers using the merchant facade.
448
+ *
449
+ * @return array A list of Ledger objects populated with the currency and current balance of each one.
450
+ */
451
+ async getLedgers() {
452
+ return this.createLedgerClient().getLedgers();
453
+ }
454
+ /**
455
+ * Retrieve a list of ledgers entries by currency and date range using the merchant facade.
456
+ *
457
+ * @param currency The three digit currency string for the ledger to retrieve.
458
+ * @param dateStart The first date for the query filter.
459
+ * @param dateEnd The last date for the query filter.
460
+ * @return array Ledger entries list.
461
+ */
462
+ async getLedgerEntries(currency, dateStart, dateEnd) {
463
+ const params = ParamsRemover_1.ParamsRemover.removeNullValuesFromObject({
464
+ startDate: Client.getDateAsString(dateStart),
465
+ endDate: Client.getDateAsString(dateEnd)
466
+ });
467
+ return this.createLedgerClient().getEntries(currency, params);
468
+ }
469
+ /**
470
+ * Create a BitPay Bill.
471
+ *
472
+ * @param bill A Bill object with request parameters defined.
473
+ * @param facade The facade used to create it.
474
+ * @param signRequest Signed request.
475
+ * @return BillInterface A BitPay generated Bill object.
476
+ */
477
+ async createBill(bill, facade, signRequest) {
478
+ if (facade === undefined) {
479
+ facade = this.getFacadeBasedOnTokenContainer();
480
+ }
481
+ if (signRequest === undefined) {
482
+ signRequest = Client.isSignRequest(facade);
483
+ }
484
+ return this.createBillClient().create(bill, facade, signRequest);
485
+ }
486
+ /**
487
+ * Retrieve a BitPay bill by bill id using the specified facade.
488
+ *
489
+ * @param billId The id of the bill to retrieve.
490
+ * @param facade The facade used to retrieve it.
491
+ * @param signRequest Signed request.
492
+ * @return BillInterface A BitPay Bill object.
493
+ */
494
+ async getBill(billId, facade, signRequest) {
495
+ if (facade === undefined) {
496
+ facade = this.getFacadeBasedOnTokenContainer();
497
+ }
498
+ if (signRequest === undefined) {
499
+ signRequest = Client.isSignRequest(facade);
500
+ }
501
+ return this.createBillClient().get(billId, facade, signRequest);
502
+ }
503
+ /**
504
+ * Retrieve a collection of BitPay bills.
505
+ *
506
+ * @param status The status to filter the bills.
507
+ * @return BillInterface A list of BitPay Bill objects.
508
+ */
509
+ async getBills(status) {
510
+ return this.createBillClient().getBills(status);
511
+ }
512
+ /**
513
+ * Update a BitPay Bill.
514
+ *
515
+ * @param bill A Bill object with the parameters to update defined.
516
+ * @param billId The Id of the Bill to udpate.
517
+ * @return BillInterface An updated Bill object.
518
+ */
519
+ async updateBill(bill, billId) {
520
+ return this.createBillClient().update(bill, billId);
521
+ }
522
+ /**
523
+ * Deliver a BitPay Bill.
524
+ *
525
+ * @param billId The id of the requested bill.
526
+ * @param billToken The token of the requested bill.
527
+ * @return Boolean A response status returned from the API.
528
+ */
529
+ async deliverBill(billId, billToken) {
530
+ const facade = this.getFacadeBasedOnTokenContainer();
531
+ const signRequest = Client.isSignRequest(facade);
532
+ return this.createBillClient().deliver(billId, billToken, signRequest);
533
+ }
534
+ /**
535
+ * Retrieve all supported wallets.
536
+ *
537
+ * @return array A list of wallet objets.
538
+ */
539
+ async getSupportedWallets() {
540
+ return this.createWalletClient().getSupportedWallets();
541
+ }
542
+ /**
543
+ * Retrieves a summary of the specified settlement.
544
+ *
545
+ * @param settlementId Settlement Id.
546
+ * @return SettlementInterface A BitPay Settlement object.
547
+ */
548
+ async getSettlement(settlementId) {
549
+ return this.createSettlementClient().get(settlementId);
550
+ }
551
+ /**
552
+ * Retrieves settlement reports for the calling merchant filtered by query.
553
+ * The `limit` and `offset` parameters
554
+ * specify pages for large query sets.
555
+ * @params params Available params:
556
+ * currency The three digit currency string for the ledger to retrieve.
557
+ * dateStart The start date for the query.
558
+ * dateEnd The end date for the query.
559
+ * status Can be `processing`, `completed`, or `failed`.
560
+ * limit Maximum number of settlements to retrieve.
561
+ * offset Offset for paging.
562
+ * @return array A list of BitPay Settlement objects.
563
+ */
564
+ async getSettlements(params = {}) {
565
+ return this.createSettlementClient().getSettlements(params);
566
+ }
567
+ /**
568
+ * Gets a detailed reconciliation report of the activity within the settlement period.
569
+ * Required id and settlement token.
570
+ *
571
+ * @param settlementId Settlement ID.
572
+ * @param token Settlement token.
573
+ * @return SettlementInterface A detailed BitPay Settlement object.
574
+ */
575
+ async getSettlementReconciliationReport(settlementId, token) {
576
+ return this.createSettlementClient().getReconciliationReport(settlementId, token);
577
+ }
578
+ /**
579
+ * Gets info for specific currency.
580
+ *
581
+ * @param currencyCode String Currency code for which the info will be retrieved.
582
+ * @return CurrencyInterface|null Currency info.
583
+ */
584
+ async getCurrencyInfo(currencyCode) {
585
+ return this.getCurrencyClient().getCurrencyInfo(currencyCode);
586
+ }
587
+ getEcKeyByPrivateKey(privateKey) {
588
+ const value = privateKey.getValue();
589
+ if (fs.existsSync(value)) {
590
+ return this.keyUtils.load_keypair(fs.readFileSync(value).toString());
591
+ }
592
+ return this.keyUtils.load_keypair(Buffer.from(value).toString().trim());
593
+ }
594
+ getEcKeyByConfig(envConfig) {
595
+ const privateKeyPath = envConfig['PrivateKeyPath'].toString().replace('"', '');
596
+ const keyHex = envConfig['PrivateKey'].toString().replace('"', '');
597
+ if (fs.existsSync(privateKeyPath)) {
598
+ return this.keyUtils.load_keypair(fs.readFileSync(privateKeyPath).toString());
599
+ }
600
+ if (keyHex) {
601
+ return this.keyUtils.load_keypair(Buffer.from(keyHex).toString().trim());
602
+ }
603
+ BitPayExceptionProvider_1.BitPayExceptionProvider.throwGenericExceptionWithMessage('Missing ECKey');
604
+ throw new Error();
605
+ }
606
+ static getBaseUrl(environment) {
607
+ return environment.toUpperCase() == index_1.Env.Test ? index_1.Env.TestUrl : index_1.Env.ProdUrl;
608
+ }
609
+ getIdentity(ecKey) {
610
+ return this.keyUtils.getPublicKeyFromPrivateKey(ecKey);
611
+ }
612
+ createRateClient() {
613
+ return new index_2.RateClient(this.bitPayClient);
614
+ }
615
+ getCurrencyClient() {
616
+ return new index_2.CurrencyClient(this.bitPayClient);
617
+ }
618
+ createInvoiceClient() {
619
+ return new index_2.InvoiceClient(this.bitPayClient, this.tokenContainer, this.guidGenerator);
620
+ }
621
+ createRefundClient() {
622
+ return new index_2.RefundClient(this.bitPayClient, this.tokenContainer, this.guidGenerator);
623
+ }
624
+ createPayoutRecipientClient() {
625
+ return new index_2.PayoutRecipientClient(this.bitPayClient, this.tokenContainer, this.guidGenerator);
626
+ }
627
+ createPayoutClient() {
628
+ return new index_2.PayoutClient(this.bitPayClient, this.tokenContainer, this.guidGenerator);
629
+ }
630
+ createPayoutGroupClient() {
631
+ return new index_2.PayoutGroupClient(this.bitPayClient, this.tokenContainer, this.guidGenerator);
632
+ }
633
+ createLedgerClient() {
634
+ return new index_2.LedgerClient(this.bitPayClient, this.tokenContainer);
635
+ }
636
+ createBillClient() {
637
+ return new index_2.BillClient(this.bitPayClient, this.tokenContainer);
638
+ }
639
+ createWalletClient() {
640
+ return new index_2.WalletClient(this.bitPayClient);
641
+ }
642
+ createSettlementClient() {
643
+ return new index_2.SettlementClient(this.bitPayClient, this.tokenContainer);
644
+ }
645
+ getFacadeBasedOnTokenContainer() {
646
+ if (this.tokenContainer.isTokenExist(index_1.Facade.Merchant)) {
647
+ return index_1.Facade.Merchant;
648
+ }
649
+ return index_1.Facade.Pos;
650
+ }
651
+ static isSignRequest(facade) {
652
+ return facade !== index_1.Facade.Pos;
653
+ }
654
+ static getDateAsString(date) {
655
+ if (date === null) {
656
+ return null;
657
+ }
658
+ return date.toISOString().split('T')[0];
659
+ }
660
+ initByConfigFilePath(configFilePath, platformInfo) {
661
+ if (!fs.existsSync(configFilePath)) {
662
+ BitPayExceptionProvider_1.BitPayExceptionProvider.throwGenericExceptionWithMessage('Configuration file not found');
663
+ }
664
+ try {
665
+ const configObj = JSON.parse(fs.readFileSync(configFilePath, 'utf-8'))['BitPayConfiguration'];
666
+ const environment = configObj['Environment'];
667
+ const envConfig = configObj['EnvConfig'][environment];
668
+ const tokens = envConfig['ApiTokens'];
669
+ this.tokenContainer = new TokenContainer_1.TokenContainer(tokens);
670
+ const ecKey = this.getEcKeyByConfig(envConfig);
671
+ this.bitPayClient = new index_2.BitPayClient(Client.getBaseUrl(environment), ecKey, this.getIdentity(ecKey), platformInfo);
672
+ this.guidGenerator = new GuidGenerator_1.GuidGenerator();
673
+ }
674
+ catch (e) {
675
+ BitPayExceptionProvider_1.BitPayExceptionProvider.throwGenericExceptionWithMessage('Error when reading configuration file');
676
+ }
677
+ }
678
+ initForTests(bitPayClient, guidGenerator, tokenContainer) {
679
+ this.bitPayClient = bitPayClient;
680
+ this.guidGenerator = guidGenerator;
681
+ this.tokenContainer = tokenContainer;
682
+ }
683
+ }
684
+ exports.Client = Client;
685
+ //# sourceMappingURL=Client.js.map
@@ -0,0 +1,5 @@
1
+ export declare class Config {
2
+ environment: string | null;
3
+ envConfig: object;
4
+ constructor();
5
+ }
package/dist/Config.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Config = void 0;
4
+ class Config {
5
+ constructor() { }
6
+ }
7
+ exports.Config = Config;
8
+ //# sourceMappingURL=Config.js.map