@blockchyp/blockchyp-ts 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/.eslintrc.json +20 -0
  2. package/LICENSE +21 -0
  3. package/README.md +4314 -0
  4. package/index.js +24 -0
  5. package/index.ts +3 -0
  6. package/itest/ActivateTerminalITestSpec.js +87 -0
  7. package/itest/ActivateTerminalITestSpec.ts +58 -0
  8. package/itest/AddTestMerchantITestSpec.js +89 -0
  9. package/itest/AddTestMerchantITestSpec.ts +60 -0
  10. package/itest/BatchHistoryITestSpec.js +101 -0
  11. package/itest/BatchHistoryITestSpec.ts +73 -0
  12. package/itest/BooleanPromptITestSpec.js +104 -0
  13. package/itest/BooleanPromptITestSpec.ts +76 -0
  14. package/itest/CancelPaymentLinkITestSpec.js +116 -0
  15. package/itest/CancelPaymentLinkITestSpec.ts +93 -0
  16. package/itest/CaptureSignatureITestSpec.js +101 -0
  17. package/itest/CaptureSignatureITestSpec.ts +73 -0
  18. package/itest/DeactivateTerminalITestSpec.js +82 -0
  19. package/itest/DeactivateTerminalITestSpec.ts +52 -0
  20. package/itest/DeleteBrandingAssetITestSpec.js +96 -0
  21. package/itest/DeleteBrandingAssetITestSpec.ts +69 -0
  22. package/itest/DeleteCustomerITestSpec.js +102 -0
  23. package/itest/DeleteCustomerITestSpec.ts +75 -0
  24. package/itest/DeleteMediaAssetITestSpec.js +100 -0
  25. package/itest/DeleteMediaAssetITestSpec.ts +71 -0
  26. package/itest/DeleteQueuedTransactionITestSpec.js +117 -0
  27. package/itest/DeleteQueuedTransactionITestSpec.ts +89 -0
  28. package/itest/DeleteSlideShowITestSpec.js +96 -0
  29. package/itest/DeleteSlideShowITestSpec.ts +69 -0
  30. package/itest/DeleteSurveyQuestionITestSpec.js +97 -0
  31. package/itest/DeleteSurveyQuestionITestSpec.ts +70 -0
  32. package/itest/DeleteTestMerchantITestSpec.js +96 -0
  33. package/itest/DeleteTestMerchantITestSpec.ts +69 -0
  34. package/itest/DeleteTokenITestSpec.js +102 -0
  35. package/itest/DeleteTokenITestSpec.ts +75 -0
  36. package/itest/EmptyBrandingAssetITestSpec.js +85 -0
  37. package/itest/EmptyBrandingAssetITestSpec.ts +57 -0
  38. package/itest/EmptySlideShowITestSpec.js +87 -0
  39. package/itest/EmptySlideShowITestSpec.ts +58 -0
  40. package/itest/GatewayTimeoutITestSpec.js +103 -0
  41. package/itest/GatewayTimeoutITestSpec.ts +73 -0
  42. package/itest/GetCustomerITestSpec.js +102 -0
  43. package/itest/GetCustomerITestSpec.ts +75 -0
  44. package/itest/GetMerchantsITestSpec.js +84 -0
  45. package/itest/GetMerchantsITestSpec.ts +56 -0
  46. package/itest/InviteMerchantUserITestSpec.js +86 -0
  47. package/itest/InviteMerchantUserITestSpec.ts +58 -0
  48. package/itest/LinkTokenITestSpec.js +103 -0
  49. package/itest/LinkTokenITestSpec.ts +76 -0
  50. package/itest/ListQueuedTransactionsITestSpec.js +116 -0
  51. package/itest/ListQueuedTransactionsITestSpec.ts +88 -0
  52. package/itest/ListTerminalsITestSpec.js +83 -0
  53. package/itest/ListTerminalsITestSpec.ts +56 -0
  54. package/itest/MediaAssetITestSpec.js +105 -0
  55. package/itest/MediaAssetITestSpec.ts +75 -0
  56. package/itest/MediaITestSpec.js +83 -0
  57. package/itest/MediaITestSpec.ts +56 -0
  58. package/itest/MediaUploadITestSpec.js +94 -0
  59. package/itest/MediaUploadITestSpec.ts +63 -0
  60. package/itest/MerchantCredentialGenerationITestSpec.js +85 -0
  61. package/itest/MerchantCredentialGenerationITestSpec.ts +57 -0
  62. package/itest/MerchantInvoiceDetailITestSpec.js +84 -0
  63. package/itest/MerchantInvoiceDetailITestSpec.ts +56 -0
  64. package/itest/MerchantInvoicesITestSpec.js +84 -0
  65. package/itest/MerchantInvoicesITestSpec.ts +56 -0
  66. package/itest/MerchantPlatformsITestSpec.js +96 -0
  67. package/itest/MerchantPlatformsITestSpec.ts +69 -0
  68. package/itest/MerchantProfileITestSpec.js +84 -0
  69. package/itest/MerchantProfileITestSpec.ts +56 -0
  70. package/itest/MerchantUsersITestSpec.js +83 -0
  71. package/itest/MerchantUsersITestSpec.ts +56 -0
  72. package/itest/NewTransactionDisplayITestSpec.js +115 -0
  73. package/itest/NewTransactionDisplayITestSpec.ts +92 -0
  74. package/itest/PANChargeITestSpec.js +118 -0
  75. package/itest/PANChargeITestSpec.ts +88 -0
  76. package/itest/PANEnrollITestSpec.js +118 -0
  77. package/itest/PANEnrollITestSpec.ts +90 -0
  78. package/itest/PANPreauthITestSpec.js +116 -0
  79. package/itest/PANPreauthITestSpec.ts +87 -0
  80. package/itest/PartialRefundITestSpec.js +119 -0
  81. package/itest/PartialRefundITestSpec.ts +91 -0
  82. package/itest/PartnerCommissionBreakdownITestSpec.js +84 -0
  83. package/itest/PartnerCommissionBreakdownITestSpec.ts +56 -0
  84. package/itest/PartnerStatementDetailITestSpec.js +84 -0
  85. package/itest/PartnerStatementDetailITestSpec.ts +56 -0
  86. package/itest/PartnerStatementsITestSpec.js +84 -0
  87. package/itest/PartnerStatementsITestSpec.ts +56 -0
  88. package/itest/PaymentLinkStatusITestSpec.js +116 -0
  89. package/itest/PaymentLinkStatusITestSpec.ts +93 -0
  90. package/itest/PricingPolicyITestSpec.js +85 -0
  91. package/itest/PricingPolicyITestSpec.ts +57 -0
  92. package/itest/ResendPaymentLinkITestSpec.js +116 -0
  93. package/itest/ResendPaymentLinkITestSpec.ts +93 -0
  94. package/itest/SearchCustomerITestSpec.js +101 -0
  95. package/itest/SearchCustomerITestSpec.ts +75 -0
  96. package/itest/SendPaymentLinkITestSpec.js +107 -0
  97. package/itest/SendPaymentLinkITestSpec.ts +82 -0
  98. package/itest/SimpleBatchCloseITestSpec.js +101 -0
  99. package/itest/SimpleBatchCloseITestSpec.ts +73 -0
  100. package/itest/SimpleCaptureITestSpec.js +101 -0
  101. package/itest/SimpleCaptureITestSpec.ts +74 -0
  102. package/itest/SimpleGiftActivateITestSpec.js +104 -0
  103. package/itest/SimpleGiftActivateITestSpec.ts +75 -0
  104. package/itest/SimpleLocateITestSpec.js +85 -0
  105. package/itest/SimpleLocateITestSpec.ts +57 -0
  106. package/itest/SimpleMessageITestSpec.js +101 -0
  107. package/itest/SimpleMessageITestSpec.ts +73 -0
  108. package/itest/SimplePingITestSpec.js +100 -0
  109. package/itest/SimplePingITestSpec.ts +72 -0
  110. package/itest/SimpleRefundITestSpec.js +118 -0
  111. package/itest/SimpleRefundITestSpec.ts +90 -0
  112. package/itest/SimpleReversalITestSpec.js +103 -0
  113. package/itest/SimpleReversalITestSpec.ts +75 -0
  114. package/itest/SimpleVoidITestSpec.js +103 -0
  115. package/itest/SimpleVoidITestSpec.ts +75 -0
  116. package/itest/SlideShowITestSpec.js +98 -0
  117. package/itest/SlideShowITestSpec.ts +70 -0
  118. package/itest/SlideShowsITestSpec.js +95 -0
  119. package/itest/SlideShowsITestSpec.ts +69 -0
  120. package/itest/SurveyQuestionITestSpec.js +95 -0
  121. package/itest/SurveyQuestionITestSpec.ts +68 -0
  122. package/itest/SurveyQuestionsITestSpec.js +96 -0
  123. package/itest/SurveyQuestionsITestSpec.ts +70 -0
  124. package/itest/SurveyResultsITestSpec.js +95 -0
  125. package/itest/SurveyResultsITestSpec.ts +68 -0
  126. package/itest/TCDeleteTemplateITestSpec.js +98 -0
  127. package/itest/TCDeleteTemplateITestSpec.ts +70 -0
  128. package/itest/TCEntryITestSpec.js +103 -0
  129. package/itest/TCEntryITestSpec.ts +76 -0
  130. package/itest/TCLogITestSpec.js +83 -0
  131. package/itest/TCLogITestSpec.ts +56 -0
  132. package/itest/TCTemplateITestSpec.js +101 -0
  133. package/itest/TCTemplateITestSpec.ts +72 -0
  134. package/itest/TCTemplateUpdateITestSpec.js +91 -0
  135. package/itest/TCTemplateUpdateITestSpec.ts +61 -0
  136. package/itest/TCTemplatesITestSpec.js +83 -0
  137. package/itest/TCTemplatesITestSpec.ts +56 -0
  138. package/itest/TerminalBrandingITestSpec.js +83 -0
  139. package/itest/TerminalBrandingITestSpec.ts +56 -0
  140. package/itest/TerminalChargeITestSpec.js +113 -0
  141. package/itest/TerminalChargeITestSpec.ts +84 -0
  142. package/itest/TerminalClearITestSpec.js +100 -0
  143. package/itest/TerminalClearITestSpec.ts +72 -0
  144. package/itest/TerminalEBTBalanceITestSpec.js +103 -0
  145. package/itest/TerminalEBTBalanceITestSpec.ts +74 -0
  146. package/itest/TerminalEBTChargeITestSpec.js +115 -0
  147. package/itest/TerminalEBTChargeITestSpec.ts +86 -0
  148. package/itest/TerminalEnrollITestSpec.js +112 -0
  149. package/itest/TerminalEnrollITestSpec.ts +83 -0
  150. package/itest/TerminalGiftCardBalanceITestSpec.js +102 -0
  151. package/itest/TerminalGiftCardBalanceITestSpec.ts +73 -0
  152. package/itest/TerminalKeyedChargeITestSpec.js +114 -0
  153. package/itest/TerminalKeyedChargeITestSpec.ts +85 -0
  154. package/itest/TerminalManualEBTChargeITestSpec.js +116 -0
  155. package/itest/TerminalManualEBTChargeITestSpec.ts +87 -0
  156. package/itest/TerminalPreauthITestSpec.js +113 -0
  157. package/itest/TerminalPreauthITestSpec.ts +84 -0
  158. package/itest/TerminalQueuedTransactionITestSpec.js +108 -0
  159. package/itest/TerminalQueuedTransactionITestSpec.ts +78 -0
  160. package/itest/TerminalStatusITestSpec.js +100 -0
  161. package/itest/TerminalStatusITestSpec.ts +72 -0
  162. package/itest/TerminalTimeoutITestSpec.js +99 -0
  163. package/itest/TerminalTimeoutITestSpec.ts +70 -0
  164. package/itest/TermsAndConditionsITestSpec.js +105 -0
  165. package/itest/TermsAndConditionsITestSpec.ts +77 -0
  166. package/itest/TextPromptITestSpec.js +103 -0
  167. package/itest/TextPromptITestSpec.ts +74 -0
  168. package/itest/TokenMetadataITestSpec.js +102 -0
  169. package/itest/TokenMetadataITestSpec.ts +75 -0
  170. package/itest/TransactionHistoryITestSpec.js +101 -0
  171. package/itest/TransactionHistoryITestSpec.ts +73 -0
  172. package/itest/UnlinkTokenITestSpec.js +103 -0
  173. package/itest/UnlinkTokenITestSpec.ts +76 -0
  174. package/itest/UpdateBrandingAssetITestSpec.js +109 -0
  175. package/itest/UpdateBrandingAssetITestSpec.ts +80 -0
  176. package/itest/UpdateCustomerITestSpec.js +90 -0
  177. package/itest/UpdateCustomerITestSpec.ts +63 -0
  178. package/itest/UpdateMerchantITestSpec.js +92 -0
  179. package/itest/UpdateMerchantITestSpec.ts +65 -0
  180. package/itest/UpdateMerchantPlatformsITestSpec.js +98 -0
  181. package/itest/UpdateMerchantPlatformsITestSpec.ts +71 -0
  182. package/itest/UpdateSlideShowITestSpec.js +106 -0
  183. package/itest/UpdateSlideShowITestSpec.ts +78 -0
  184. package/itest/UpdateSurveyQuestionITestSpec.js +89 -0
  185. package/itest/UpdateSurveyQuestionITestSpec.ts +60 -0
  186. package/itest/UpdateTransactionDisplayITestSpec.js +115 -0
  187. package/itest/UpdateTransactionDisplayITestSpec.ts +92 -0
  188. package/itest/UploadStatusITestSpec.js +100 -0
  189. package/itest/UploadStatusITestSpec.ts +71 -0
  190. package/itest/support/aviato.png +0 -0
  191. package/itest/support/config.js +67 -0
  192. package/itest/support/config.ts +106 -0
  193. package/itest/support/jasmine.json +11 -0
  194. package/package.json +73 -0
  195. package/spec/CryptoSpec.js +35 -0
  196. package/spec/CryptoSpec.ts +35 -0
  197. package/spec/SanitySpec.js +26 -0
  198. package/spec/SanitySpec.ts +23 -0
  199. package/spec/support/jasmine.json +11 -0
  200. package/src/client.js +941 -0
  201. package/src/client.ts +1012 -0
  202. package/src/cryptoutils.js +89 -0
  203. package/src/cryptoutils.ts +80 -0
  204. package/src/global.js +9 -0
  205. package/src/global.ts +5 -0
  206. package/src/models.js +9382 -0
  207. package/src/models.ts +16509 -0
package/src/client.ts ADDED
@@ -0,0 +1,1012 @@
1
+ /**
2
+ * Copyright 2019-2024 BlockChyp, Inc. All rights reserved. Use of this code is governed
3
+ * by a license that can be found in the LICENSE file.
4
+ *
5
+ * This file was generated automatically by the BlockChyp SDK Generator. Changes to this
6
+ * file will be lost every time the code is regenerated.
7
+ */
8
+ import axios, {AxiosRequestConfig, AxiosResponse} from 'axios'
9
+ import CryptoUtils from './cryptoutils'
10
+ import * as Models from './models'
11
+ import * as nodeHttps from 'https'
12
+
13
+ /* eslint-disable no-unused-vars */
14
+ export const CardType = Object.freeze({
15
+ CREDIT: 0,
16
+ DEBIT: 1,
17
+ EBT: 2,
18
+ BLOCKCHAIN_GIFT: 3,
19
+ HEALTHCARE: 4,
20
+ })
21
+
22
+ export const SignatureFormat = Object.freeze({
23
+ NONE: '',
24
+ PNG: 'png',
25
+ JPG: 'jpg',
26
+ GIF: 'gif',
27
+ })
28
+
29
+ export const RoundingMode = Object.freeze({
30
+ UP: 'up',
31
+ NEAREST: 'nearest',
32
+ DOWN: 'down',
33
+ })
34
+
35
+ export const PromptType = Object.freeze({
36
+ AMOUNT: 'amount',
37
+ EMAIL: 'email',
38
+ PHONE_NUMBER: 'phone',
39
+ CUSTOMER_NUMBER: 'customer-number',
40
+ REWARDS_NUMBER: 'rewards-number',
41
+ FIRST_NAME: 'first-name',
42
+ LAST_NAME: 'last-name',
43
+ })
44
+
45
+ export const AVSResponse = Object.freeze({
46
+ NOT_APPLICABLE: '',
47
+ NOT_SUPPORTED: 'not_supported',
48
+ RETRY: 'retry',
49
+ NO_MATCH: 'no_match',
50
+ ADDRESS_MATCH: 'address_match',
51
+ POSTAL_CODE_MATCH: 'zip_match',
52
+ ADDRESS_AND_POSTAL_CODE_MATCH: 'match',
53
+ })
54
+
55
+ export const CVMType = Object.freeze({
56
+ SIGNATURE: 'Signature',
57
+ OFFLINE_PIN: 'Offline PIN',
58
+ ONLINE_PIN: 'Online PIN',
59
+ CDCVM: 'CDCVM',
60
+ NO_CVM: 'No CVM',
61
+ })
62
+
63
+ export const HealthcareType = Object.freeze({
64
+ HEALTHCARE: 'healthcare',
65
+ PRESCRIPTION: 'prescription',
66
+ VISION: 'vision',
67
+ CLINIC: 'clinic',
68
+ DENTAL: 'dental',
69
+ })
70
+ /* eslint-enable no-unused-vars */
71
+
72
+ const VERSION: string = require('../package.json').version;
73
+ const USER_AGENT: string = `BlockChyp-TypeScript/${VERSION}`;
74
+ // Some browsers do not allow setting the user-agent header, so we set
75
+ // an alternative if running from a browser.
76
+ const AGENT_HEADER: string = (typeof window === 'undefined') ? 'User-Agent' : 'X-Requested-With';
77
+
78
+ interface TerminalRoute {
79
+ terminalName: string;
80
+ ipAddress: string;
81
+ transientCredentials: {
82
+ apiKey: string;
83
+ bearerToken: string;
84
+ signingKey: string;
85
+ };
86
+ cloudRelayEnabled: boolean;
87
+ }
88
+
89
+ interface RouteCacheEntry {
90
+ ttl: number;
91
+ route: TerminalRoute;
92
+ }
93
+
94
+ export class BlockChypClient {
95
+ private gatewayHost: string;
96
+ private testGatewayHost: string;
97
+ private dashboardHost: string;
98
+ private credentials: BlockChypCredentials | undefined;
99
+ private https: boolean;
100
+ private cloudRelay: boolean;
101
+ private routeCacheTTL: number;
102
+ private gatewayTimeout: number;
103
+ private terminalTimeout: number;
104
+ private _routeCache: { [key: string]: RouteCacheEntry };
105
+
106
+ constructor(
107
+ gatewayHostOrCreds?: string | BlockChypCredentials,
108
+ testGatewayHostOrCreds?: string | BlockChypCredentials,
109
+ dashboardHostOrCreds?: string | BlockChypCredentials,
110
+ creds?: BlockChypCredentials
111
+ ) {
112
+ this.gatewayHost = 'https://api.blockchyp.com';
113
+ this.testGatewayHost = 'https://test.blockchyp.com';
114
+ this.dashboardHost = 'https://dashboard.blockchyp.com';
115
+
116
+ if (typeof gatewayHostOrCreds === 'string') {
117
+ this.gatewayHost = gatewayHostOrCreds;
118
+ } else if (typeof gatewayHostOrCreds === 'object') {
119
+ creds = gatewayHostOrCreds;
120
+ }
121
+
122
+ if (typeof testGatewayHostOrCreds === 'string') {
123
+ this.testGatewayHost = testGatewayHostOrCreds;
124
+ } else if (typeof testGatewayHostOrCreds === 'object') {
125
+ creds = testGatewayHostOrCreds;
126
+ }
127
+
128
+ if (typeof dashboardHostOrCreds === 'string') {
129
+ this.dashboardHost = dashboardHostOrCreds;
130
+ } else if (typeof dashboardHostOrCreds === 'object') {
131
+ creds = dashboardHostOrCreds;
132
+ }
133
+
134
+ this.credentials = creds;
135
+ this.https = true;
136
+ this.cloudRelay = false;
137
+ this.routeCacheTTL = 60;
138
+ this.gatewayTimeout = 20;
139
+ this.terminalTimeout = 120;
140
+ this._routeCache = {};
141
+ }
142
+
143
+ newClient(creds: BlockChypCredentials): BlockChypClient {
144
+ return new BlockChypClient(creds);
145
+ }
146
+
147
+ getGatewayHost(): string {
148
+ return this.gatewayHost;
149
+ }
150
+
151
+ getDashboardHost(): string {
152
+ return this.dashboardHost;
153
+ }
154
+
155
+ setGatewayHost(host: string): void {
156
+ this.gatewayHost = host;
157
+ }
158
+
159
+ setDashboardHost(host: string): void {
160
+ this.dashboardHost = host;
161
+ }
162
+
163
+ setTestGatewayHost(host: string): void {
164
+ this.testGatewayHost = host;
165
+ }
166
+
167
+ heartbeat() {
168
+ return this._gatewayRequest('get', '/api/heartbeat');
169
+ }
170
+
171
+ /**
172
+ * Tests connectivity with a payment terminal.
173
+ */
174
+ async ping(request: Models.PingRequest): Promise<AxiosResponse<Models.PingResponse>> {
175
+ return this.routeTerminalRequest('post', request, '/api/test', '/api/terminal-test');
176
+ }
177
+
178
+ /**
179
+ * Executes a standard direct preauth and capture.
180
+ */
181
+ async charge(request: Models.AuthorizationRequest): Promise<AxiosResponse<Models.AuthorizationResponse>> {
182
+ return this.routeTerminalRequest('post', request, '/api/charge', '/api/charge');
183
+ }
184
+
185
+ /**
186
+ * Executes a preauthorization intended to be captured later.
187
+ */
188
+ async preauth(request: Models.AuthorizationRequest): Promise<AxiosResponse<Models.AuthorizationResponse>> {
189
+ return this.routeTerminalRequest('post', request, '/api/preauth', '/api/preauth');
190
+ }
191
+
192
+ /**
193
+ * Executes a refund.
194
+ */
195
+ async refund(request: Models.RefundRequest): Promise<AxiosResponse<Models.AuthorizationResponse>> {
196
+ return this.routeTerminalRequest('post', request, '/api/refund', '/api/refund');
197
+ }
198
+
199
+ /**
200
+ * Adds a new payment method to the token vault.
201
+ */
202
+ async enroll(request: Models.EnrollRequest): Promise<AxiosResponse<Models.EnrollResponse>> {
203
+ return this.routeTerminalRequest('post', request, '/api/enroll', '/api/enroll');
204
+ }
205
+
206
+ /**
207
+ * Activates or recharges a gift card.
208
+ */
209
+ async giftActivate(request: Models.GiftActivateRequest): Promise<AxiosResponse<Models.GiftActivateResponse>> {
210
+ return this.routeTerminalRequest('post', request, '/api/gift-activate', '/api/gift-activate');
211
+ }
212
+
213
+ /**
214
+ * Checks the remaining balance on a payment method.
215
+ */
216
+ async balance(request: Models.BalanceRequest): Promise<AxiosResponse<Models.BalanceResponse>> {
217
+ return this.routeTerminalRequest('post', request, '/api/balance', '/api/balance');
218
+ }
219
+
220
+ /**
221
+ * Clears the line item display and any in progress transaction.
222
+ */
223
+ async clear(request: Models.ClearTerminalRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
224
+ return this.routeTerminalRequest('post', request, '/api/clear', '/api/terminal-clear');
225
+ }
226
+
227
+ /**
228
+ * Returns the current status of a terminal.
229
+ */
230
+ async terminalStatus(request: Models.TerminalStatusRequest): Promise<AxiosResponse<Models.TerminalStatusResponse>> {
231
+ return this.routeTerminalRequest('post', request, '/api/terminal-status', '/api/terminal-status');
232
+ }
233
+
234
+ /**
235
+ * Prompts the user to accept terms and conditions.
236
+ */
237
+ async termsAndConditions(request: Models.TermsAndConditionsRequest): Promise<AxiosResponse<Models.TermsAndConditionsResponse>> {
238
+ return this.routeTerminalRequest('post', request, '/api/tc', '/api/terminal-tc');
239
+ }
240
+
241
+ /**
242
+ * Captures and returns a signature.
243
+ */
244
+ async captureSignature(request: Models.CaptureSignatureRequest): Promise<AxiosResponse<Models.CaptureSignatureResponse>> {
245
+ return this.routeTerminalRequest('post', request, '/api/capture-signature', '/api/capture-signature');
246
+ }
247
+
248
+ /**
249
+ * Displays a new transaction on the terminal.
250
+ */
251
+ async newTransactionDisplay(request: Models.TransactionDisplayRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
252
+ return this.routeTerminalRequest('post', request, '/api/txdisplay', '/api/terminal-txdisplay');
253
+ }
254
+
255
+ /**
256
+ * Appends items to an existing transaction display. Subtotal, Tax, and Total are
257
+ * overwritten by the request. Items with the same description are combined into
258
+ * groups.
259
+ */
260
+ async updateTransactionDisplay(request: Models.TransactionDisplayRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
261
+ return this.routeTerminalRequest('put', request, '/api/txdisplay', '/api/terminal-txdisplay');
262
+ }
263
+
264
+ /**
265
+ * Displays a short message on the terminal.
266
+ */
267
+ async message(request: Models.MessageRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
268
+ return this.routeTerminalRequest('post', request, '/api/message', '/api/message');
269
+ }
270
+
271
+ /**
272
+ * Asks the consumer a yes/no question.
273
+ */
274
+ async booleanPrompt(request: Models.BooleanPromptRequest): Promise<AxiosResponse<Models.BooleanPromptResponse>> {
275
+ return this.routeTerminalRequest('post', request, '/api/boolean-prompt', '/api/boolean-prompt');
276
+ }
277
+
278
+ /**
279
+ * Asks the consumer a text based question.
280
+ */
281
+ async textPrompt(request: Models.TextPromptRequest): Promise<AxiosResponse<Models.TextPromptResponse>> {
282
+ return this.routeTerminalRequest('post', request, '/api/text-prompt', '/api/text-prompt');
283
+ }
284
+
285
+ /**
286
+ * Returns a list of queued transactions on a terminal.
287
+ */
288
+ async listQueuedTransactions(request: Models.ListQueuedTransactionsRequest): Promise<AxiosResponse<Models.ListQueuedTransactionsResponse>> {
289
+ return this.routeTerminalRequest('post', request, '/api/queue/list', '/api/queue/list');
290
+ }
291
+
292
+ /**
293
+ * Deletes a queued transaction from the terminal.
294
+ */
295
+ async deleteQueuedTransaction(request: Models.DeleteQueuedTransactionRequest): Promise<AxiosResponse<Models.DeleteQueuedTransactionResponse>> {
296
+ return this.routeTerminalRequest('post', request, '/api/queue/delete', '/api/queue/delete');
297
+ }
298
+
299
+ /**
300
+ * Reboot a payment terminal.
301
+ */
302
+ async reboot(request: Models.PingRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
303
+ return this.routeTerminalRequest('post', request, '/api/reboot', '/api/terminal-reboot');
304
+ }
305
+
306
+ /**
307
+ * Returns routing and location data for a payment terminal.
308
+ */
309
+ locate(request: Models.LocateRequest): Promise<AxiosResponse<Models.LocateResponse>> {
310
+ return this._gatewayRequest('post', '/api/terminal-locate', request);
311
+ }
312
+
313
+ /**
314
+ * Captures a preauthorization.
315
+ */
316
+ capture(request: Models.CaptureRequest): Promise<AxiosResponse<Models.CaptureResponse>> {
317
+ return this._gatewayRequest('post', '/api/capture', request);
318
+ }
319
+
320
+ /**
321
+ * Discards a previous transaction.
322
+ */
323
+ void(request: Models.VoidRequest): Promise<AxiosResponse<Models.VoidResponse>> {
324
+ return this._gatewayRequest('post', '/api/void', request);
325
+ }
326
+
327
+ /**
328
+ * Executes a manual time out reversal.
329
+ *
330
+ * We love time out reversals. Don't be afraid to use them whenever a request to a
331
+ * BlockChyp terminal times out. You have up to two minutes to reverse any transaction.
332
+ * The only caveat is that you must assign transactionRef values when you build the
333
+ * original request. Otherwise, we have no real way of knowing which transaction you're
334
+ * trying to reverse because we may not have assigned it an id yet. And if we did assign it an
335
+ * id, you wouldn't know what it is because your request to the terminal timed out before
336
+ * you got a response.
337
+ */
338
+ reverse(request: Models.AuthorizationRequest): Promise<AxiosResponse<Models.AuthorizationResponse>> {
339
+ return this._gatewayRequest('post', '/api/reverse', request);
340
+ }
341
+
342
+ /**
343
+ * Closes the current credit card batch.
344
+ */
345
+ closeBatch(request: Models.CloseBatchRequest): Promise<AxiosResponse<Models.CloseBatchResponse>> {
346
+ return this._gatewayRequest('post', '/api/close-batch', request);
347
+ }
348
+
349
+ /**
350
+ * Creates and send a payment link to a customer.
351
+ */
352
+ sendPaymentLink(request: Models.PaymentLinkRequest): Promise<AxiosResponse<Models.PaymentLinkResponse>> {
353
+ return this._gatewayRequest('post', '/api/send-payment-link', request);
354
+ }
355
+
356
+ /**
357
+ * Resends payment link.
358
+ */
359
+ resendPaymentLink(request: Models.ResendPaymentLinkRequest): Promise<AxiosResponse<Models.ResendPaymentLinkResponse>> {
360
+ return this._gatewayRequest('post', '/api/resend-payment-link', request);
361
+ }
362
+
363
+ /**
364
+ * Cancels a payment link.
365
+ */
366
+ cancelPaymentLink(request: Models.CancelPaymentLinkRequest): Promise<AxiosResponse<Models.CancelPaymentLinkResponse>> {
367
+ return this._gatewayRequest('post', '/api/cancel-payment-link', request);
368
+ }
369
+
370
+ /**
371
+ * Retrieves the status of a payment link.
372
+ */
373
+ paymentLinkStatus(request: Models.PaymentLinkStatusRequest): Promise<AxiosResponse<Models.PaymentLinkStatusResponse>> {
374
+ return this._gatewayRequest('post', '/api/payment-link-status', request);
375
+ }
376
+
377
+ /**
378
+ * Retrieves the current status of a transaction.
379
+ */
380
+ transactionStatus(request: Models.TransactionStatusRequest): Promise<AxiosResponse<Models.AuthorizationResponse>> {
381
+ return this._gatewayRequest('post', '/api/tx-status', request);
382
+ }
383
+
384
+ /**
385
+ * Updates or creates a customer record.
386
+ */
387
+ updateCustomer(request: Models.UpdateCustomerRequest): Promise<AxiosResponse<Models.CustomerResponse>> {
388
+ return this._gatewayRequest('post', '/api/update-customer', request);
389
+ }
390
+
391
+ /**
392
+ * Retrieves a customer by id.
393
+ */
394
+ customer(request: Models.CustomerRequest): Promise<AxiosResponse<Models.CustomerResponse>> {
395
+ return this._gatewayRequest('post', '/api/customer', request);
396
+ }
397
+
398
+ /**
399
+ * Searches the customer database.
400
+ */
401
+ customerSearch(request: Models.CustomerSearchRequest): Promise<AxiosResponse<Models.CustomerSearchResponse>> {
402
+ return this._gatewayRequest('post', '/api/customer-search', request);
403
+ }
404
+
405
+ /**
406
+ * Calculates the discount for actual cash transactions.
407
+ */
408
+ cashDiscount(request: Models.CashDiscountRequest): Promise<AxiosResponse<Models.CashDiscountResponse>> {
409
+ return this._gatewayRequest('post', '/api/cash-discount', request);
410
+ }
411
+
412
+ /**
413
+ * Returns the batch history for a merchant.
414
+ */
415
+ batchHistory(request: Models.BatchHistoryRequest): Promise<AxiosResponse<Models.BatchHistoryResponse>> {
416
+ return this._gatewayRequest('post', '/api/batch-history', request);
417
+ }
418
+
419
+ /**
420
+ * Returns the batch details for a single batch.
421
+ */
422
+ batchDetails(request: Models.BatchDetailsRequest): Promise<AxiosResponse<Models.BatchDetailsResponse>> {
423
+ return this._gatewayRequest('post', '/api/batch-details', request);
424
+ }
425
+
426
+ /**
427
+ * Returns the transaction history for a merchant.
428
+ */
429
+ transactionHistory(request: Models.TransactionHistoryRequest): Promise<AxiosResponse<Models.TransactionHistoryResponse>> {
430
+ return this._gatewayRequest('post', '/api/tx-history', request);
431
+ }
432
+
433
+ /**
434
+ * Returns pricing policy for a merchant.
435
+ */
436
+ pricingPolicy(request: Models.PricingPolicyRequest): Promise<AxiosResponse<Models.PricingPolicyResponse>> {
437
+ return this._gatewayRequest('post', '/api/read-pricing-policy', request);
438
+ }
439
+
440
+ /**
441
+ * Returns a list of partner statements.
442
+ */
443
+ partnerStatements(request: Models.PartnerStatementListRequest): Promise<AxiosResponse<Models.PartnerStatementListResponse>> {
444
+ return this._gatewayRequest('post', '/api/partner-statement-list', request);
445
+ }
446
+
447
+ /**
448
+ * Returns detail for a single partner statement.
449
+ */
450
+ partnerStatementDetail(request: Models.PartnerStatementDetailRequest): Promise<AxiosResponse<Models.PartnerStatementDetailResponse>> {
451
+ return this._gatewayRequest('post', '/api/partner-statement-detail', request);
452
+ }
453
+
454
+ /**
455
+ * Returns a list of merchant invoices.
456
+ */
457
+ merchantInvoices(request: Models.MerchantInvoiceListRequest): Promise<AxiosResponse<Models.MerchantInvoiceListResponse>> {
458
+ return this._gatewayRequest('post', '/api/merchant-invoice-list', request);
459
+ }
460
+
461
+ /**
462
+ * Returns detail for a single merchant-invoice statement.
463
+ */
464
+ merchantInvoiceDetail(request: Models.MerchantInvoiceDetailRequest): Promise<AxiosResponse<Models.MerchantInvoiceDetailResponse>> {
465
+ return this._gatewayRequest('post', '/api/merchant-invoice-detail', request);
466
+ }
467
+
468
+ /**
469
+ * Returns low level details for how partner commissions were calculated for a specific
470
+ * merchant statement.
471
+ */
472
+ partnerCommissionBreakdown(request: Models.PartnerCommissionBreakdownRequest): Promise<AxiosResponse<Models.PartnerCommissionBreakdownResponse>> {
473
+ return this._gatewayRequest('post', '/api/partner-commission-breakdown', request);
474
+ }
475
+
476
+ /**
477
+ * Generates and returns api credentials for a given merchant.
478
+ */
479
+ merchantCredentialGeneration(request: Models.MerchantCredentialGenerationRequest): Promise<AxiosResponse<Models.MerchantCredentialGenerationResponse>> {
480
+ return this._gatewayRequest('post', '/api/creds/generateMerchant', request);
481
+ }
482
+
483
+ /**
484
+ * Returns profile information for a merchant.
485
+ */
486
+ merchantProfile(request: Models.MerchantProfileRequest): Promise<AxiosResponse<Models.MerchantProfileResponse>> {
487
+ return this._gatewayRequest('post', '/api/public-merchant-profile', request);
488
+ }
489
+
490
+ /**
491
+ * Deletes a customer record.
492
+ */
493
+ deleteCustomer(request: Models.DeleteCustomerRequest): Promise<AxiosResponse<Models.DeleteCustomerResponse>> {
494
+ return this._gatewayRequest('delete', '/api/customer/' + request.customerId, request);
495
+ }
496
+
497
+ /**
498
+ * Retrieves payment token metadata.
499
+ */
500
+ tokenMetadata(request: Models.TokenMetadataRequest): Promise<AxiosResponse<Models.TokenMetadataResponse>> {
501
+ return this._gatewayRequest('get', '/api/token/' + request.token, request);
502
+ }
503
+
504
+ /**
505
+ * Links a token to a customer record.
506
+ */
507
+ linkToken(request: Models.LinkTokenRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
508
+ return this._gatewayRequest('post', '/api/link-token', request);
509
+ }
510
+
511
+ /**
512
+ * Removes a link between a customer and a token.
513
+ */
514
+ unlinkToken(request: Models.UnlinkTokenRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
515
+ return this._gatewayRequest('post', '/api/unlink-token', request);
516
+ }
517
+
518
+ /**
519
+ * Deletes a payment token.
520
+ */
521
+ deleteToken(request: Models.DeleteTokenRequest): Promise<AxiosResponse<Models.DeleteTokenResponse>> {
522
+ return this._gatewayRequest('delete', '/api/token/' + request.token, request);
523
+ }
524
+
525
+ /**
526
+ * Adds a test merchant account.
527
+ */
528
+ getMerchants(request: Models.GetMerchantsRequest): Promise<AxiosResponse<Models.GetMerchantsResponse>> {
529
+ return this._dashboardRequest('post', '/api/get-merchants', request);
530
+ }
531
+
532
+ /**
533
+ * Adds or updates a merchant account. Can be used to create or update test merchants.
534
+ * Only gateway partners may create new live merchants.
535
+ */
536
+ updateMerchant(request: Models.MerchantProfile): Promise<AxiosResponse<Models.MerchantProfileResponse>> {
537
+ return this._dashboardRequest('post', '/api/update-merchant', request);
538
+ }
539
+
540
+ /**
541
+ * List all active users and pending invites for a merchant account.
542
+ */
543
+ merchantUsers(request: Models.MerchantProfileRequest): Promise<AxiosResponse<Models.MerchantUsersResponse>> {
544
+ return this._dashboardRequest('post', '/api/merchant-users', request);
545
+ }
546
+
547
+ /**
548
+ * Invites a user to join a merchant account.
549
+ */
550
+ inviteMerchantUser(request: Models.InviteMerchantUserRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
551
+ return this._dashboardRequest('post', '/api/invite-merchant-user', request);
552
+ }
553
+
554
+ /**
555
+ * Adds a test merchant account.
556
+ */
557
+ addTestMerchant(request: Models.AddTestMerchantRequest): Promise<AxiosResponse<Models.MerchantProfileResponse>> {
558
+ return this._dashboardRequest('post', '/api/add-test-merchant', request);
559
+ }
560
+
561
+ /**
562
+ * Deletes a test merchant account. Supports partner scoped API credentials only. Live
563
+ * merchant accounts cannot be deleted.
564
+ */
565
+ deleteTestMerchant(request: Models.MerchantProfileRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
566
+ return this._dashboardRequest('delete', '/api/test-merchant/' + request.merchantId, request);
567
+ }
568
+
569
+ /**
570
+ * List all merchant platforms configured for a gateway merchant.
571
+ */
572
+ merchantPlatforms(request: Models.MerchantProfileRequest): Promise<AxiosResponse<Models.MerchantPlatformsResponse>> {
573
+ return this._dashboardRequest('get', '/api/plugin-configs/' + request.merchantId, request);
574
+ }
575
+
576
+ /**
577
+ * List all merchant platforms configured for a gateway merchant.
578
+ */
579
+ updateMerchantPlatforms(request: Models.MerchantPlatform): Promise<AxiosResponse<Models.Acknowledgement>> {
580
+ return this._dashboardRequest('post', '/api/plugin-configs', request);
581
+ }
582
+
583
+ /**
584
+ * Deletes a boarding platform configuration.
585
+ */
586
+ deleteMerchantPlatforms(request: Models.MerchantPlatformRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
587
+ return this._dashboardRequest('delete', '/api/plugin-config/' + request.platformId, request);
588
+ }
589
+
590
+ /**
591
+ * Returns all terminals associated with the merchant account.
592
+ */
593
+ terminals(request: Models.TerminalProfileRequest): Promise<AxiosResponse<Models.TerminalProfileResponse>> {
594
+ return this._dashboardRequest('get', '/api/terminals', request);
595
+ }
596
+
597
+ /**
598
+ * Deactivates a terminal.
599
+ */
600
+ deactivateTerminal(request: Models.TerminalDeactivationRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
601
+ return this._dashboardRequest('delete', '/api/terminal/' + request.terminalId, request);
602
+ }
603
+
604
+ /**
605
+ * Activates a terminal.
606
+ */
607
+ activateTerminal(request: Models.TerminalActivationRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
608
+ return this._dashboardRequest('post', '/api/terminal-activate', request);
609
+ }
610
+
611
+ /**
612
+ * Returns a list of terms and conditions templates associated with a merchant account.
613
+ */
614
+ tcTemplates(request: Models.TermsAndConditionsTemplateRequest): Promise<AxiosResponse<Models.TermsAndConditionsTemplateResponse>> {
615
+ return this._dashboardRequest('get', '/api/tc-templates', request);
616
+ }
617
+
618
+ /**
619
+ * Returns a single terms and conditions template.
620
+ */
621
+ tcTemplate(request: Models.TermsAndConditionsTemplateRequest): Promise<AxiosResponse<Models.TermsAndConditionsTemplate>> {
622
+ return this._dashboardRequest('get', '/api/tc-templates/' + request.templateId, request);
623
+ }
624
+
625
+ /**
626
+ * Updates or creates a terms and conditions template.
627
+ */
628
+ tcUpdateTemplate(request: Models.TermsAndConditionsTemplate): Promise<AxiosResponse<Models.TermsAndConditionsTemplate>> {
629
+ return this._dashboardRequest('post', '/api/tc-templates', request);
630
+ }
631
+
632
+ /**
633
+ * Deletes a single terms and conditions template.
634
+ */
635
+ tcDeleteTemplate(request: Models.TermsAndConditionsTemplateRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
636
+ return this._dashboardRequest('delete', '/api/tc-templates/' + request.templateId, request);
637
+ }
638
+
639
+ /**
640
+ * Returns up to 250 entries from the Terms and Conditions log.
641
+ */
642
+ tcLog(request: Models.TermsAndConditionsLogRequest): Promise<AxiosResponse<Models.TermsAndConditionsLogResponse>> {
643
+ return this._dashboardRequest('post', '/api/tc-log', request);
644
+ }
645
+
646
+ /**
647
+ * Returns a single detailed Terms and Conditions entry.
648
+ */
649
+ tcEntry(request: Models.TermsAndConditionsLogRequest): Promise<AxiosResponse<Models.TermsAndConditionsLogEntry>> {
650
+ return this._dashboardRequest('get', '/api/tc-entry/' + request.logEntryId, request);
651
+ }
652
+
653
+ /**
654
+ * Returns all survey questions for a given merchant.
655
+ */
656
+ surveyQuestions(request: Models.SurveyQuestionRequest): Promise<AxiosResponse<Models.SurveyQuestionResponse>> {
657
+ return this._dashboardRequest('get', '/api/survey-questions', request);
658
+ }
659
+
660
+ /**
661
+ * Returns a single survey question with response data.
662
+ */
663
+ surveyQuestion(request: Models.SurveyQuestionRequest): Promise<AxiosResponse<Models.SurveyQuestion>> {
664
+ return this._dashboardRequest('get', '/api/survey-questions/' + request.questionId, request);
665
+ }
666
+
667
+ /**
668
+ * Updates or creates a survey question.
669
+ */
670
+ updateSurveyQuestion(request: Models.SurveyQuestion): Promise<AxiosResponse<Models.SurveyQuestion>> {
671
+ return this._dashboardRequest('post', '/api/survey-questions', request);
672
+ }
673
+
674
+ /**
675
+ * Deletes a survey question.
676
+ */
677
+ deleteSurveyQuestion(request: Models.SurveyQuestionRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
678
+ return this._dashboardRequest('delete', '/api/survey-questions/' + request.questionId, request);
679
+ }
680
+
681
+ /**
682
+ * Returns results for a single survey question.
683
+ */
684
+ surveyResults(request: Models.SurveyResultsRequest): Promise<AxiosResponse<Models.SurveyQuestion>> {
685
+ return this._dashboardRequest('post', '/api/survey-results', request);
686
+ }
687
+
688
+ /**
689
+ * Returns the media library for a given partner, merchant, or organization.
690
+ */
691
+ media(request: Models.MediaRequest): Promise<AxiosResponse<Models.MediaLibraryResponse>> {
692
+ return this._dashboardRequest('get', '/api/media', request);
693
+ }
694
+
695
+ /**
696
+ * Uploads a media asset to the media library.
697
+ */
698
+ uploadMedia(request: Models.UploadMetadata, content: any): Promise<AxiosResponse<Models.MediaMetadata>> {
699
+ return this._uploadRequest('/api/upload-media', request, content);
700
+ }
701
+ /**
702
+ * Retrieves the current status of a file upload.
703
+ */
704
+ uploadStatus(request: Models.UploadStatusRequest): Promise<AxiosResponse<Models.UploadStatus>> {
705
+ return this._dashboardRequest('get', '/api/media-upload/' + request.uploadId, request);
706
+ }
707
+
708
+ /**
709
+ * Returns the media details for a single media asset.
710
+ */
711
+ mediaAsset(request: Models.MediaRequest): Promise<AxiosResponse<Models.MediaMetadata>> {
712
+ return this._dashboardRequest('get', '/api/media/' + request.mediaId, request);
713
+ }
714
+
715
+ /**
716
+ * Deletes a media asset.
717
+ */
718
+ deleteMediaAsset(request: Models.MediaRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
719
+ return this._dashboardRequest('delete', '/api/media/' + request.mediaId, request);
720
+ }
721
+
722
+ /**
723
+ * Returns a collection of slide shows.
724
+ */
725
+ slideShows(request: Models.SlideShowRequest): Promise<AxiosResponse<Models.SlideShowResponse>> {
726
+ return this._dashboardRequest('get', '/api/slide-shows', request);
727
+ }
728
+
729
+ /**
730
+ * Returns a single slide show with slides.
731
+ */
732
+ slideShow(request: Models.SlideShowRequest): Promise<AxiosResponse<Models.SlideShow>> {
733
+ return this._dashboardRequest('get', '/api/slide-shows/' + request.slideShowId, request);
734
+ }
735
+
736
+ /**
737
+ * Updates or creates a slide show.
738
+ */
739
+ updateSlideShow(request: Models.SlideShow): Promise<AxiosResponse<Models.SlideShow>> {
740
+ return this._dashboardRequest('post', '/api/slide-shows', request);
741
+ }
742
+
743
+ /**
744
+ * Deletes a single slide show.
745
+ */
746
+ deleteSlideShow(request: Models.SlideShowRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
747
+ return this._dashboardRequest('delete', '/api/slide-shows/' + request.slideShowId, request);
748
+ }
749
+
750
+ /**
751
+ * Returns the terminal branding stack for a given set of API credentials.
752
+ */
753
+ terminalBranding(request: Models.BrandingAssetRequest): Promise<AxiosResponse<Models.BrandingAssetResponse>> {
754
+ return this._dashboardRequest('get', '/api/terminal-branding', request);
755
+ }
756
+
757
+ /**
758
+ * Updates a branding asset.
759
+ */
760
+ updateBrandingAsset(request: Models.BrandingAsset): Promise<AxiosResponse<Models.BrandingAsset>> {
761
+ return this._dashboardRequest('post', '/api/terminal-branding', request);
762
+ }
763
+
764
+ /**
765
+ * Deletes a branding asset.
766
+ */
767
+ deleteBrandingAsset(request: Models.BrandingAssetRequest): Promise<AxiosResponse<Models.Acknowledgement>> {
768
+ return this._dashboardRequest('delete', '/api/terminal-branding/' + request.assetId, request);
769
+ }
770
+
771
+ async routeTerminalRequest(method: any, request: any, terminalPath: string, cloudPath: string): Promise<any> {
772
+ if (this.isTerminalRouted(request)) {
773
+ const route = await this._resolveTerminalRoute(request.terminalName);
774
+ if (route && !route.cloudRelayEnabled) {
775
+ return this._terminalRequest(method, route, terminalPath, request);
776
+ }
777
+ }
778
+ if (cloudPath) {
779
+ return this._relayRequest(method, cloudPath, request);
780
+ }
781
+ return this._gatewayRequest(method, terminalPath, request);
782
+ }
783
+
784
+ async routeTerminalPost(request: any, terminalPath: string, cloudPath: string): Promise<any> {
785
+ return this.routeTerminalRequest('post', request, terminalPath, cloudPath);
786
+ }
787
+
788
+ returnValidationError(desc: string): any {
789
+ const result: any = {
790
+ data: {
791
+ approved: false,
792
+ success: false,
793
+ error: desc
794
+ }
795
+ };
796
+ return result;
797
+ }
798
+
799
+ validateRequest(request: any): boolean {
800
+ if (!this.validateCurrency(request.amount)) {
801
+ return false;
802
+ }
803
+ return true;
804
+ }
805
+
806
+ validateCurrency(val: string): boolean {
807
+ const amt: number = parseFloat(val);
808
+ if (amt && !isNaN(amt)) {
809
+ const decMatch: RegExpMatchArray | null = val.match(/\./g);
810
+ if (decMatch && decMatch.length > 1) {
811
+ return false;
812
+ }
813
+ return true;
814
+ }
815
+ return false;
816
+ }
817
+
818
+ isTerminalRouted(request: any): boolean {
819
+ if (this.cloudRelay) {
820
+ return false;
821
+ } else if (request.terminalName) {
822
+ return true;
823
+ }
824
+ return false;
825
+ }
826
+
827
+ _relayRequest(method: any, path: string, request: any): Promise<any> {
828
+ return this._gatewayRequest(method, path, request, true);
829
+ }
830
+
831
+ _uploadRequest(path: string, request: any, content: any): Promise<any> {
832
+ const config: AxiosRequestConfig = {
833
+ method: 'post',
834
+ url: this._assembleDashboardUrl(path),
835
+ timeout: this._getTimeout(request, this.gatewayTimeout) * 1000,
836
+ headers: {
837
+ [AGENT_HEADER]: USER_AGENT,
838
+ },
839
+ };
840
+
841
+ config.data = content;
842
+
843
+ if (this.credentials && this.credentials.apiKey) {
844
+ config.headers = Object.assign(config.headers, CryptoUtils.generateGatewayHeaders(this.credentials));
845
+ }
846
+ if (request.fileSize) {
847
+ config.headers['X-File-Size'] = request.fileSize.toFixed();
848
+ }
849
+ if (request.fileName) {
850
+ config.headers['X-Upload-File-Name'] = request.fileName;
851
+ }
852
+ if (request.uploadId) {
853
+ config.headers['X-Upload-ID'] = request.uploadId;
854
+ }
855
+
856
+ return axios(config);
857
+ }
858
+
859
+ _dashboardRequest(method: any, path: string, request: any): Promise<any> {
860
+ const config: AxiosRequestConfig = {
861
+ method: method,
862
+ url: this._assembleDashboardUrl(path),
863
+ timeout: this._getTimeout(request, this.gatewayTimeout) * 1000,
864
+ headers: {
865
+ [AGENT_HEADER]: USER_AGENT,
866
+ 'Content-Type': 'application/json',
867
+ },
868
+ };
869
+
870
+ if (method !== 'get') {
871
+ config.data = request;
872
+ }
873
+
874
+ if (this.credentials && this.credentials.apiKey) {
875
+ config.headers = Object.assign(config.headers, CryptoUtils.generateGatewayHeaders(this.credentials));
876
+ }
877
+ return axios(config);
878
+ }
879
+
880
+ _gatewayRequest(method: any, path: string, request?: any, relay?: boolean): Promise<any> {
881
+ const config: AxiosRequestConfig = {
882
+ method: method,
883
+ url: this._assembleGatewayUrl(path, request),
884
+ timeout: this._getTimeout(request, relay ? this.terminalTimeout : this.gatewayTimeout) * 1000,
885
+ headers: {
886
+ [AGENT_HEADER]: USER_AGENT,
887
+ 'Content-Type': 'application/json',
888
+ },
889
+ };
890
+
891
+ if (method !== 'get') {
892
+ config.data = request;
893
+ }
894
+
895
+ if (this.credentials && this.credentials.apiKey) {
896
+ config.headers = Object.assign(config.headers, CryptoUtils.generateGatewayHeaders(this.credentials));
897
+ }
898
+
899
+ return axios(config);
900
+ }
901
+
902
+ _getTimeout(request: any, defaultTimeout: number): number {
903
+ if (request && 'timeout' in request) {
904
+ return request['timeout'];
905
+ }
906
+
907
+ return defaultTimeout;
908
+ }
909
+
910
+ _assembleDashboardUrl(path: string): string {
911
+ return this.dashboardHost + path;
912
+ }
913
+
914
+ _assembleGatewayUrl(path: string, payload?: any): string {
915
+ let result: string = '';
916
+ if (payload && payload.test) {
917
+ result = result + this.testGatewayHost;
918
+ } else {
919
+ result = result + this.gatewayHost;
920
+ }
921
+ result = result + path;
922
+ return result;
923
+ }
924
+
925
+ async _terminalRequest(method: any, route: TerminalRoute, path: string, request: any): Promise<any> {
926
+ const url: string = await this._assembleTerminalUrl(route, path);
927
+
928
+ const config: AxiosRequestConfig = {
929
+ method: method,
930
+ url: url,
931
+ headers: {
932
+ [AGENT_HEADER]: USER_AGENT,
933
+ 'Content-Type': 'application/json',
934
+ },
935
+ timeout: this._getTimeout(request, this.terminalTimeout) * 1000,
936
+ };
937
+ if (typeof window === 'undefined') {
938
+ if (this.https) {
939
+ config.httpsAgent = new nodeHttps.Agent({
940
+ rejectUnauthorized: false
941
+ });
942
+ }
943
+ } else {
944
+ config.httpsAgent = {
945
+ protocol: 'https:',
946
+ rejectUnauthorized: false
947
+ };
948
+ }
949
+
950
+ if (request) {
951
+ config.data = {
952
+ apiKey: route.transientCredentials.apiKey,
953
+ bearerToken: route.transientCredentials.bearerToken,
954
+ signingKey: route.transientCredentials.signingKey,
955
+ request: request,
956
+ };
957
+ }
958
+
959
+ return axios(config);
960
+ }
961
+
962
+ async _assembleTerminalUrl(route: TerminalRoute, path: string): Promise<string> {
963
+ let result: string = 'http';
964
+ if (this.https) {
965
+ result = result + 's';
966
+ }
967
+ result = result + '://';
968
+ result = result + route.ipAddress;
969
+ if (this.https) {
970
+ result = result + ':8443';
971
+ } else {
972
+ result = result + ':8080';
973
+ }
974
+ result = result + path;
975
+ return result;
976
+ }
977
+
978
+ async _resolveTerminalRoute(terminalName: string): Promise<TerminalRoute> {
979
+ const cacheEntry: RouteCacheEntry | undefined = this._routeCache[terminalName];
980
+
981
+ if (cacheEntry) {
982
+ if (cacheEntry.ttl >= new Date().getTime()) {
983
+ return cacheEntry.route;
984
+ }
985
+ }
986
+
987
+ const routeResponse: any = await this._gatewayRequest('get', '/api/terminal-route?terminal=' + terminalName);
988
+ const route: TerminalRoute = routeResponse.data;
989
+ this._routeCache[terminalName] =
990
+ {
991
+ ttl: new Date().getTime() + (this.routeCacheTTL * 60000),
992
+ route: route
993
+ };
994
+
995
+ return route;
996
+ }
997
+ }
998
+
999
+ export class BlockChypCredentials {
1000
+ constructor(public apiKey: string, public bearerToken: string, public signingKey: string) {
1001
+ this.apiKey = apiKey
1002
+ this.bearerToken = bearerToken
1003
+ this.signingKey = signingKey
1004
+ }
1005
+ }
1006
+
1007
+ const BlockChyp: BlockChypClient = new BlockChypClient();
1008
+ export default BlockChyp;
1009
+
1010
+ export function newClient(creds: BlockChypCredentials): BlockChypClient {
1011
+ return BlockChyp.newClient(creds);
1012
+ }