@staxpayments/staxpayments-js 2.30.18

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.
package/README.md ADDED
@@ -0,0 +1,1192 @@
1
+
2
+ # Stax Payments JavaScript SDK
3
+
4
+ [![Build Status](https://github.com/blockchyp/staxpayments-js/actions/workflows/main.yml/badge.svg)](https://github.com/blockchyp/staxpayments-js/actions/workflows/main.yml)
5
+ [![NPM](https://img.shields.io/npm/v/@staxpayments/staxpayments-js)](https://www.npmjs.com/package/@staxpayments/staxpayments-js)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/blockchyp/staxpayments-js/blob/master/LICENSE)
7
+
8
+ This is the SDK for JavaScript. Like all Stax Payments SDKs, it provides a full
9
+ client for the Stax Payments gateway and Stax Payments payment terminals.
10
+
11
+ This SDK is designed to run in a browser or in Node.js. But given that this library
12
+ is designed for direct communication with the gateway and terminals, in browser
13
+ use is not recommended because API credentials would be discoverable via browser
14
+ developer tools. There are legitimate use cases for in browser use, but they're rare.
15
+
16
+ ## Browser Based Integrations
17
+
18
+ This library is designed primarily server side use via Node.js. Stax Payments provides
19
+ a separate library for public facing web side or e-commerce systems. The Stax Payments
20
+ Web Tokenizer uses cross-origin iframes to tokenize payments in the browser, keeping
21
+ web based applications out of PCI scope.
22
+
23
+ [Stax Payments Web Tokenizer on GitHub](https://github.com/blockchyp/staxpayments-tokenizer)
24
+
25
+ ## Installation
26
+
27
+ The Stax Payments SDK is installable via NPM. Type the following command to add
28
+ Stax Payments to your package.json.
29
+
30
+ ```
31
+ npm install @staxpayments/staxpayments-js --save
32
+ ```
33
+
34
+ ## A Simple Example
35
+
36
+ Running your first transaction is easy. Make sure you have a Stax Payments terminal,
37
+ activate it, and obtain a Stax bearer token.
38
+
39
+ The SDK exposes a single root client, `StaxPaymentsClient`, organized into
40
+ namespaces (one per API area) reached as properties — e.g. `client.payments`,
41
+ `client.terminals`. The root client builds one shared transport, so a single set
42
+ of transient credentials is fetched and reused across every namespace.
43
+
44
+ ```javascript
45
+ let StaxPayments = require('@staxpayments/staxpayments-js');
46
+
47
+ // Construct the root client with your Stax bearer token. Terminal transactions
48
+ // (charge, preauth) transparently exchange it for short-lived transient
49
+ // credentials, shared across every namespace.
50
+ let client = new StaxPayments.StaxPaymentsClient(
51
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
52
+ );
53
+
54
+ client.payments.charge({
55
+ test: true,
56
+ terminalName: 'Test Terminal',
57
+ amount: '55.00',
58
+ })
59
+ .then(function (response) {
60
+ if (response.approved) {
61
+ console.log('Approved');
62
+ console.log(response.transactionId);
63
+ console.log(response.authCode);
64
+ console.log(response.authorizedAmount);
65
+ } else {
66
+ console.log(response.responseDescription);
67
+ }
68
+ })
69
+ .catch(function (error) {
70
+ console.log(error);
71
+ });
72
+ ```
73
+
74
+ The response contains all the information you'll need to complete processing
75
+ a transaction. Of particular importance is `receiptSuggestions`, which contains
76
+ all the fields that are required or recommended for PCI or EMV compliance.
77
+
78
+ ## Stax Payments Models
79
+
80
+ `charge` and `preauth` take a Stax Payments request and resolve to a Stax
81
+ Payments response:
82
+
83
+ | Model | Purpose |
84
+ | ----- | ------- |
85
+ | Auth request | Charge and preauth request. Carries the amount, terminal, currency, tip and tax subtotals, and the test flag. |
86
+ | Auth response | Charge and preauth response. Carries the approval, transaction id, auth code, authorized and requested amounts, card details such as the masked PAN, entry method and network, and the `receiptSuggestions` needed for PCI and EMV compliance. |
87
+
88
+ `transactionId` on the response is the Stax transaction id.
89
+
90
+ Note that these two operations resolve to the response body directly, unlike the
91
+ other endpoints in this SDK, which resolve to the full HTTP response and put the
92
+ body on `response.data`.
93
+
94
+
95
+
96
+ ## Additional Documentation
97
+
98
+ Complete documentation can be found on our [Developer Documentation Portal].
99
+
100
+ [Developer Documentation Portal]: https://docs.blockchyp.com/
101
+
102
+ ## Authentication
103
+
104
+ This SDK authenticates with a **Stax bearer token**. Construct a client with your
105
+ bearer token and the SDK transparently exchanges it for short-lived BlockChyp
106
+ transient credentials — cached and refreshed automatically — whenever you run a
107
+ terminal transaction such as `charge` or `refund`. Listing terminals is served
108
+ directly by the Stax core API using your bearer token.
109
+
110
+ ## Getting a Developer Kit
111
+
112
+ In order to test your integration with real terminals, you'll need a BlockChyp
113
+ Developer Kit. Our kits include a fully functioning payment terminal with
114
+ test pin encryption keys. Every kit includes a comprehensive set of test
115
+ cards with test cards for every major card brand and entry method, including
116
+ Contactless and Contact EMV and mag stripe cards. Each kit also includes
117
+ test gift cards for our blockchain gift card system.
118
+
119
+ Access to BlockChyp's developer program is currently invite only, but you
120
+ can request an invitation by contacting our engineering team at **nerds@blockchyp.com**.
121
+
122
+ You can also view a number of long form demos and learn more about us on our [YouTube Channel](https://www.youtube.com/channel/UCE-iIVlJic_XArs_U65ZcJg).
123
+
124
+ ## Transaction Code Examples
125
+
126
+ You don't want to read words. You want examples. Here's a quick rundown of the
127
+ stuff you can do with the Stax Payments JavaScript SDK and a few basic examples.
128
+
129
+ ### Payment Endpoints
130
+
131
+
132
+ These are the core payment APIs used to execute and work with payment transactions in BlockChyp.
133
+
134
+
135
+
136
+ #### Charge
137
+
138
+
139
+
140
+ * **API Credential Types:** Merchant
141
+ * **Required Role:** Payment API Access
142
+
143
+ Our most popular transaction executes a standard authorization and capture.
144
+ This is the most basic of
145
+ basic payment transactions, typically used in conventional retail.
146
+
147
+ Charge transactions can use a payment terminal to capture a payment or
148
+ use a previously enrolled payment token.
149
+
150
+ **Terminal Transactions**
151
+
152
+ For terminal transactions, make sure you pass in the terminal name using the `terminalName` property.
153
+
154
+ **Token Transactions**
155
+
156
+ If you have a payment token, omit the `terminalName` property and pass in the token with the `token`
157
+ property instead.
158
+
159
+ **Card Numbers and Mag Stripes**
160
+
161
+ You can also pass in PANs and Mag Stripes, but you probably shouldn't, as this will
162
+ put you in PCI scope and the most common vector for POS breaches is keylogging.
163
+ If you use terminals for manual card entry, you'll bypass any keyloggers that
164
+ might be maliciously running on the point-of-sale system.
165
+
166
+ **Common Variations**
167
+
168
+ * **Gift Card Redemption**: There's no special API for gift card redemption in BlockChyp. Simply execute a plain charge transaction and if the customer swipes a gift card, our terminals will identify the gift card and run a gift card redemption. Also note that if for some reason the gift card's original purchase transaction is associated with fraud or a chargeback, the transaction will be rejected.
169
+ * **EBT**: Set the `CardType` field to `BlockChyp.CardType.EBT` to process an EBT SNAP transaction. Note that test EBT transactions always assume a balance of $100.00, so test EBT transactions over that amount may be declined.
170
+ * **Cash Back**: To enable cash back for debit transactions, set the `CashBack` field. If the card presented isn't a debit card, the `CashBack` field will be ignored.
171
+ * **Manual Card Entry**: Set the `ManualEntry` field to enable manual card entry. Good as a backup when chips and MSR's don't work or for more secure phone orders. You can even combine the `ManualEntry` field with the `CardType` field set to `BlockChyp.CardType.EBT` for manual EBT card entry.
172
+ * **Inline Tokenization**: You can enroll the payment method in the token vault inline with a charge transaction by setting the `Enroll` field. You'll get a token back in the response. You can even bind the token to a customer record if you also pass in customer data.
173
+ * **Prompting for Tips**: Set the `PromptForTip` field if you'd like to prompt the customer for a tip before authorization. Good for pay-at-the-table and other service related scenarios.
174
+ * **Cash Discounting and Surcharging**: The `Surcharge` and `CashDiscount` fields can be used together to support cash discounting or surcharge problems. Consult the Cash Discount documentation for more details.
175
+ * **Cryptocurrency** The `Cryptocurrency` field can be used to switch the standard present card screen to a cryptocurrency screen. The field value can be `ANY` to enable any supported cryptocurrency or a single currency code such as `BTC` for Bitcoin.
176
+
177
+
178
+
179
+ ```javascript
180
+ let StaxPayments = require('@staxpayments/staxpayments-js');
181
+
182
+
183
+ // construct a client with your Stax bearer token; terminal transactions
184
+ // transparently exchange it for short-lived transient credentials
185
+ let client = new StaxPayments.StaxPaymentsClient(
186
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
187
+ );
188
+
189
+ client.payments.charge({
190
+ test: true,
191
+ terminalName: 'Test Terminal',
192
+ amount: '55.00',
193
+ })
194
+ .then(function (response) {
195
+ console.log('Response: ' + JSON.stringify(response))
196
+ })
197
+ .catch(function (error) {
198
+ console.log(error)
199
+ });
200
+
201
+ ```
202
+
203
+ #### Preauthorization
204
+
205
+
206
+
207
+ * **API Credential Types:** Merchant
208
+ * **Required Role:** Payment API Access
209
+
210
+ A preauthorization puts a hold on funds and must be captured later. This is used
211
+ in scenarios where the final transaction amount might change. A common example is
212
+ fine dining, where a tip adjustment is required before final settlement.
213
+
214
+ Another use case for preauthorization is e-commerce. Typically, an online order
215
+ is preauthorized at the time of the order and then captured when the order ships.
216
+
217
+ Preauthorizations can use a payment terminal to capture a payment or
218
+ use a previously enrolled payment token.
219
+
220
+ **Terminal Transactions**
221
+
222
+ For terminal transactions, make sure you pass in the terminal name using the `terminalName` property.
223
+
224
+ **Token Transactions**
225
+
226
+ If you have a payment token, omit the `terminalName` property and pass in the token with the `token`
227
+ property instead.
228
+
229
+ **Card Numbers and Mag Stripes**
230
+
231
+ You can also pass in PANs and Mag Stripes, but you probably shouldn't, as this will
232
+ put you in PCI scope and the most common vector for POS breaches is key logging.
233
+ If you use terminals for manual card entry, you'll bypass any key loggers that
234
+ might be maliciously running on the point-of-sale system.
235
+
236
+ **Cryptocurrency**
237
+
238
+ Note that preauths are not supported for cryptocurrency.
239
+
240
+ **Common Variations**
241
+
242
+ * **Manual Card Entry**: Set the `ManualEntry` field to enable manual card entry. Good as a backup when chips and MSR's don't work or for more secure phone orders. You can even combine the `ManualEntry` field with `CardType` set to `BlockChyp.CardType.EBT` for manual EBT card entry.
243
+ * **Inline Tokenization**: You can enroll the payment method in the token vault in line with a charge transaction by setting the `Enroll` field. You'll get a token back in the response. You can even bind the token to a customer record if you also pass in customer data.
244
+ * **Prompting for Tips**: Set the `PromptForTip` field if you'd like to prompt the customer for a tip before authorization. You can prompt for tips as part of a preauthorization, although it's not a very common approach.
245
+ * **Cash Discounting and Surcharging**: The `Surcharge` and `CashDiscount` fields can be used together to support cash discounting or surcharge problems. Consult the Cash Discount documentation for more details.
246
+
247
+
248
+
249
+
250
+ ```javascript
251
+ let StaxPayments = require('@staxpayments/staxpayments-js');
252
+
253
+
254
+ // construct a client with your Stax bearer token; terminal transactions
255
+ // transparently exchange it for short-lived transient credentials
256
+ let client = new StaxPayments.StaxPaymentsClient(
257
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
258
+ );
259
+
260
+ client.payments.preauth({
261
+ test: true,
262
+ terminalName: 'Test Terminal',
263
+ amount: '27.00',
264
+ })
265
+ .then(function (response) {
266
+ console.log('Response: ' + JSON.stringify(response))
267
+ })
268
+ .catch(function (error) {
269
+ console.log(error)
270
+ });
271
+
272
+ ```
273
+
274
+ ### Terminal Management Endpoints
275
+
276
+
277
+ These APIs support terminal management functions and additional terminal
278
+ features such as line item display, messages, and interactive prompts.
279
+ These features can be used to extend a point of sale system's functionality.
280
+
281
+
282
+
283
+ #### Terminal Ping
284
+
285
+
286
+
287
+ * **API Credential Types:** Merchant
288
+ * **Required Role:** Payment API Access
289
+
290
+ This simple test transaction helps ensure good communication with a payment terminal
291
+ and is usually the first test you'll run in development.
292
+
293
+ It tests communication with the terminal and returns a positive response if everything
294
+ is okay. It works the same way in local or cloud relay mode.
295
+
296
+ If you get a positive response, you've successfully verified all of the following:
297
+
298
+ * The terminal is online.
299
+ * There is a valid route to the terminal.
300
+ * The API Credentials are valid.
301
+
302
+
303
+
304
+
305
+ ```javascript
306
+ let StaxPayments = require('@staxpayments/staxpayments-js');
307
+
308
+
309
+ // construct a client with your Stax bearer token; terminal transactions
310
+ // transparently exchange it for short-lived transient credentials
311
+ let client = new StaxPayments.StaxPaymentsClient(
312
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
313
+ );
314
+
315
+ client.terminals.ping({
316
+ terminalName: 'Test Terminal',
317
+ })
318
+ .then(function (response) {
319
+ console.log('Response: ' + JSON.stringify(response.data))
320
+ })
321
+ .catch(function (error) {
322
+ console.log(error)
323
+ });
324
+
325
+ ```
326
+
327
+ #### Terminal Locate
328
+
329
+
330
+
331
+ * **API Credential Types:** Merchant
332
+ * **Required Role:** Payment API Access
333
+
334
+ This endpoint returns a terminal's routing and location information.
335
+
336
+ The result will indicate whether or not the terminal is in cloud relay mode and will
337
+ return the local IP address if the terminal is in local mode.
338
+
339
+ The terminal will also return the public key for the terminal.
340
+
341
+
342
+
343
+
344
+ ```javascript
345
+ let StaxPayments = require('@staxpayments/staxpayments-js');
346
+
347
+
348
+ // construct a client with your Stax bearer token; terminal transactions
349
+ // transparently exchange it for short-lived transient credentials
350
+ let client = new StaxPayments.StaxPaymentsClient(
351
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
352
+ );
353
+
354
+ client.terminals.locate({
355
+ terminalName: 'Test Terminal',
356
+ })
357
+ .then(function (response) {
358
+ console.log('Response: ' + JSON.stringify(response.data))
359
+ })
360
+ .catch(function (error) {
361
+ console.log(error)
362
+ });
363
+
364
+ ```
365
+
366
+ #### Terminal Clear
367
+
368
+
369
+
370
+ * **API Credential Types:** Merchant
371
+ * **Required Role:** Payment API Access
372
+
373
+ This API interrupts whatever a terminal may be doing and returns it to the
374
+ idle state.
375
+
376
+
377
+
378
+
379
+
380
+ ```javascript
381
+ let StaxPayments = require('@staxpayments/staxpayments-js');
382
+
383
+
384
+ // construct a client with your Stax bearer token; terminal transactions
385
+ // transparently exchange it for short-lived transient credentials
386
+ let client = new StaxPayments.StaxPaymentsClient(
387
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
388
+ );
389
+
390
+ client.terminals.clear({
391
+ test: true,
392
+ terminalName: 'Test Terminal',
393
+ })
394
+ .then(function (response) {
395
+ console.log('Response: ' + JSON.stringify(response.data))
396
+ })
397
+ .catch(function (error) {
398
+ console.log(error)
399
+ });
400
+
401
+ ```
402
+
403
+ #### Terminal Status
404
+
405
+
406
+
407
+ * **API Credential Types:** Merchant
408
+ * **Required Role:** Payment API Access
409
+
410
+ This API returns the current status of a payment terminal. This is typically used
411
+ as a way to determine if the terminal is busy before sending a new transaction.
412
+
413
+ If the terminal is busy, `idle` will be false and the `status` field will return
414
+ a short string that indicates the transaction type currently in progress. The system
415
+ will also return the timestamp of the last status change in the `since` field.
416
+
417
+ The `cardInSlot` field in the response will indicates whether or not a card is currently in the card reader slot.
418
+
419
+ If the system is running a payment transaction and you wisely passed in a
420
+ Transaction Ref, this API will also return the Transaction Ref of the in progress
421
+ transaction.
422
+
423
+ The table below lists all possible status responses.
424
+
425
+ | Status Code | Description |
426
+ |----------------------|-----------------------------------------------------------------------------------------|
427
+ | idle | The terminal is idle and ready for transactions. The default branding is being displayed. |
428
+ | activate | The terminal is in the process of activating and pairing with the merchant account. |
429
+ | balance | A balance check (EBT or Gift Card) is pending on the terminal. |
430
+ | boolean-prompt | A boolean prompt (yes/no) operation is pending on the terminal. |
431
+ | signature | A signature capture is pending. |
432
+ | crypto | A cryptocurrency transaction is pending. |
433
+ | enroll | A token vault enrollment operation is pending. |
434
+ | gift-activate | A gift card activation operation is in progress. |
435
+ | message | The terminal is displaying a custom message. |
436
+ | charge | The terminal is executing a charge transaction. |
437
+ | preauth | The terminal is executing a preauth transaction. |
438
+ | refund | The terminal is executing a refund transaction. |
439
+ | survey | The terminal is displaying post transaction survey questions. |
440
+ | terms-and-conditions | The terminal is pending terms and conditions acceptance and signature. |
441
+ | text-prompt | The terminal is awaiting response to a text input prompt. |
442
+ | txdisplay | The terminal is displaying transaction and/or line item level details. |
443
+
444
+
445
+
446
+
447
+ ```javascript
448
+ let StaxPayments = require('@staxpayments/staxpayments-js');
449
+
450
+
451
+ // construct a client with your Stax bearer token; terminal transactions
452
+ // transparently exchange it for short-lived transient credentials
453
+ let client = new StaxPayments.StaxPaymentsClient(
454
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
455
+ );
456
+
457
+ client.terminals.terminalStatus({
458
+ terminalName: 'Test Terminal',
459
+ })
460
+ .then(function (response) {
461
+ console.log('Response: ' + JSON.stringify(response.data))
462
+ })
463
+ .catch(function (error) {
464
+ console.log(error)
465
+ });
466
+
467
+ ```
468
+
469
+ #### Capture Signature
470
+
471
+
472
+
473
+ * **API Credential Types:** Merchant
474
+ * **Required Role:** Payment API Access
475
+
476
+ This endpoint captures a written signature from the terminal and returns the
477
+ image.
478
+
479
+ Unlike the Terms & Conditions API, this endpoint performs basic signature
480
+ capture with no agreement display or signature archival.
481
+
482
+ Under the hood, signatures are captured in a proprietary vector format and
483
+ must be converted to a common raster format in order to be useful to most
484
+ applications. At a minimum, you must specify an image format using the
485
+ `sigFormat` parameter. Currently, JPG and PNG are supported.
486
+
487
+ By default, images are returned in the JSON response as hex encoded binary.
488
+ You can redirect the binary image output to a file using the `sigFile`
489
+ parameter.
490
+
491
+ You can also scale the output image to your preferred width by
492
+ passing in a `sigWidth` parameter. The image will be scaled to that
493
+ width, preserving the aspect ratio of the original image.
494
+
495
+
496
+
497
+
498
+ ```javascript
499
+ let StaxPayments = require('@staxpayments/staxpayments-js');
500
+
501
+
502
+ // construct a client with your Stax bearer token; terminal transactions
503
+ // transparently exchange it for short-lived transient credentials
504
+ let client = new StaxPayments.StaxPaymentsClient(
505
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
506
+ );
507
+
508
+ client.terminals.captureSignature({
509
+ terminalName: 'Test Terminal',
510
+
511
+ // File format for the signature image.
512
+ sigFormat: BlockChyp.SignatureFormat.PNG,
513
+
514
+ // Width of the signature image in pixels.
515
+ sigWidth: 200,
516
+ })
517
+ .then(function (response) {
518
+ console.log('Response: ' + JSON.stringify(response.data))
519
+ })
520
+ .catch(function (error) {
521
+ console.log(error)
522
+ });
523
+
524
+ ```
525
+
526
+ #### New Transaction Display
527
+
528
+
529
+
530
+ * **API Credential Types:** Merchant
531
+ * **Required Role:** Payment API Access
532
+
533
+ This API sends totals and line item level data to the terminal.
534
+
535
+ At a minimum, you should send total information as part of a display request,
536
+ including `total`, `tax`, and `subtotal`.
537
+
538
+ You can also send line item level data and each line item can have a `description`,
539
+ `qty`, `price`, and `extended` price.
540
+
541
+ If you fail to send an extended price, BlockChyp will multiply the `qty` by the
542
+ `price`. However, we strongly recommend you precalculate all the fields yourself
543
+ to ensure consistency. For example, your treatment of floating-point multiplication
544
+ and rounding may differ slightly from BlockChyp's.
545
+
546
+ **Discounts**
547
+
548
+ You have the option to show discounts on the display as individual line items
549
+ with negative values or you can associate discounts with a specific line item.
550
+ You can apply any number of discounts to an individual line item with a description
551
+ and amount.
552
+
553
+
554
+
555
+
556
+ ```javascript
557
+ let StaxPayments = require('@staxpayments/staxpayments-js');
558
+
559
+
560
+ // construct a client with your Stax bearer token; terminal transactions
561
+ // transparently exchange it for short-lived transient credentials
562
+ let client = new StaxPayments.StaxPaymentsClient(
563
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
564
+ );
565
+
566
+ client.terminals.newTransactionDisplay({
567
+ test: true,
568
+ terminalName: 'Test Terminal',
569
+ transaction: {
570
+ subtotal: '60.00',
571
+ tax: '5.00',
572
+ total: '65.00',
573
+ items: [
574
+ {
575
+ description: 'Leki Trekking Poles',
576
+ price: '35.00',
577
+ quantity: 2,
578
+ extended: '70.00',
579
+ discounts: [
580
+ {
581
+ description: 'memberDiscount',
582
+ amount: '10.00',
583
+ },
584
+ ],
585
+ },
586
+ ],
587
+ },
588
+ })
589
+ .then(function (response) {
590
+ console.log('Response: ' + JSON.stringify(response.data))
591
+ })
592
+ .catch(function (error) {
593
+ console.log(error)
594
+ });
595
+
596
+ ```
597
+
598
+ #### Update Transaction Display
599
+
600
+
601
+
602
+ * **API Credential Types:** Merchant
603
+ * **Required Role:** Payment API Access
604
+
605
+ Similar to *New Transaction Display*, this variant allows developers to update
606
+ line item level data currently being displayed on the terminal.
607
+
608
+ This feature is designed for situations where you want to update the terminal display as
609
+ items are scanned. You'll only have to send information to the
610
+ terminal that's changed, which usually means the new line item and updated totals.
611
+
612
+ If the terminal is not in line item display mode and you invoke this endpoint,
613
+ the first invocation will behave like a *New Transaction Display* call.
614
+
615
+ At a minimum, you should send total information as part of a display request,
616
+ including `total`, `tax`, and `subtotal`.
617
+
618
+ You can also send line item level data and each line item can have a `description`,
619
+ `qty`, `price`, and `extended` price.
620
+
621
+ If you fail to send an extended price, BlockChyp will multiply the `qty` by the
622
+ `price`. However, we strongly recommend you precalculate all the fields yourself
623
+ to ensure consistency. For example, your treatment of floating-point multiplication and rounding
624
+ may differ slightly from BlockChyp's.
625
+
626
+ **Discounts**
627
+
628
+ You have the option to show discounts on the display as individual line items
629
+ with negative values or you can associate discounts with a specific line item.
630
+ You can apply any number of discounts to an individual line item with a description
631
+ and amount.
632
+
633
+
634
+
635
+
636
+ ```javascript
637
+ let StaxPayments = require('@staxpayments/staxpayments-js');
638
+
639
+
640
+ // construct a client with your Stax bearer token; terminal transactions
641
+ // transparently exchange it for short-lived transient credentials
642
+ let client = new StaxPayments.StaxPaymentsClient(
643
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
644
+ );
645
+
646
+ client.terminals.updateTransactionDisplay({
647
+ test: true,
648
+ terminalName: 'Test Terminal',
649
+ transaction: {
650
+ subtotal: '60.00',
651
+ tax: '5.00',
652
+ total: '65.00',
653
+ items: [
654
+ {
655
+ description: 'Leki Trekking Poles',
656
+ price: '35.00',
657
+ quantity: 2,
658
+ extended: '70.00',
659
+ discounts: [
660
+ {
661
+ description: 'memberDiscount',
662
+ amount: '10.00',
663
+ },
664
+ ],
665
+ },
666
+ ],
667
+ },
668
+ })
669
+ .then(function (response) {
670
+ console.log('Response: ' + JSON.stringify(response.data))
671
+ })
672
+ .catch(function (error) {
673
+ console.log(error)
674
+ });
675
+
676
+ ```
677
+
678
+ #### Display Message
679
+
680
+
681
+
682
+ * **API Credential Types:** Merchant
683
+ * **Required Role:** Payment API Access
684
+
685
+ This API displays a message on the payment terminal.
686
+
687
+ Just specify the target terminal and the message using the `message` parameter.
688
+
689
+
690
+
691
+
692
+ ```javascript
693
+ let StaxPayments = require('@staxpayments/staxpayments-js');
694
+
695
+
696
+ // construct a client with your Stax bearer token; terminal transactions
697
+ // transparently exchange it for short-lived transient credentials
698
+ let client = new StaxPayments.StaxPaymentsClient(
699
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
700
+ );
701
+
702
+ client.terminals.message({
703
+ test: true,
704
+ terminalName: 'Test Terminal',
705
+ message: 'Thank you for your business.',
706
+ })
707
+ .then(function (response) {
708
+ console.log('Response: ' + JSON.stringify(response.data))
709
+ })
710
+ .catch(function (error) {
711
+ console.log(error)
712
+ });
713
+
714
+ ```
715
+
716
+ #### Boolean Prompt
717
+
718
+
719
+
720
+ * **API Credential Types:** Merchant
721
+ * **Required Role:** Payment API Access
722
+
723
+ This API prompts the customer to answer a yes or no question.
724
+
725
+ You can specify the question or prompt with the `prompt` parameter and
726
+ the response is returned in the `response` field.
727
+
728
+ This can be used for a number of use cases including starting a loyalty enrollment
729
+ workflow or customer facing suggestive selling prompts.
730
+
731
+ **Custom Captions**
732
+
733
+ You can optionally override the "YES" and "NO" button captions by
734
+ using the `yesCaption` and `noCaption` request parameters.
735
+
736
+
737
+
738
+
739
+ ```javascript
740
+ let StaxPayments = require('@staxpayments/staxpayments-js');
741
+
742
+
743
+ // construct a client with your Stax bearer token; terminal transactions
744
+ // transparently exchange it for short-lived transient credentials
745
+ let client = new StaxPayments.StaxPaymentsClient(
746
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
747
+ );
748
+
749
+ client.terminals.booleanPrompt({
750
+ test: true,
751
+ terminalName: 'Test Terminal',
752
+ prompt: 'Would you like to become a member?',
753
+ yesCaption: 'Yes',
754
+ noCaption: 'No',
755
+ })
756
+ .then(function (response) {
757
+ console.log('Response: ' + JSON.stringify(response.data))
758
+ })
759
+ .catch(function (error) {
760
+ console.log(error)
761
+ });
762
+
763
+ ```
764
+
765
+ #### Text Prompt
766
+
767
+
768
+
769
+ * **API Credential Types:** Merchant
770
+ * **Required Role:** Payment API Access
771
+
772
+ This API prompts the customer to enter numeric or alphanumeric data.
773
+
774
+ Due to PCI rules, free-form prompts are not permitted when the response
775
+ could be any valid string. The reason for this is that a malicious
776
+ developer (not you, of course) could use text prompts to ask the customer to
777
+ input a card number or PIN code.
778
+
779
+ This means that instead of providing a prompt, you provide a `promptType` instead.
780
+
781
+ The prompt types currently supported are listed below:
782
+
783
+ * **phone**: Captures a phone number.
784
+ * **email**: Captures an email address.
785
+ * **first-name**: Captures a first name.
786
+ * **last-name**: Captures a last name.
787
+ * **customer-number**: Captures a customer number.
788
+ * **rewards-number**: Captures a rewards number.
789
+
790
+ You can specify the prompt with the `promptType` parameter and
791
+ the response is returned in the `response` field.
792
+
793
+
794
+
795
+
796
+
797
+ ```javascript
798
+ let StaxPayments = require('@staxpayments/staxpayments-js');
799
+
800
+
801
+ // construct a client with your Stax bearer token; terminal transactions
802
+ // transparently exchange it for short-lived transient credentials
803
+ let client = new StaxPayments.StaxPaymentsClient(
804
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
805
+ );
806
+
807
+ client.terminals.textPrompt({
808
+ test: true,
809
+ terminalName: 'Test Terminal',
810
+
811
+ // Type of prompt. Can be 'email', 'phone', 'customer-number', or
812
+ // 'rewards-number'.
813
+ promptType: BlockChyp.PromptType.EMAIL,
814
+ })
815
+ .then(function (response) {
816
+ console.log('Response: ' + JSON.stringify(response.data))
817
+ })
818
+ .catch(function (error) {
819
+ console.log(error)
820
+ });
821
+
822
+ ```
823
+
824
+ #### List Terminals
825
+
826
+
827
+
828
+ * **API Credential Types:** Merchant & Partner
829
+ * **Required Role:** Terminal Management
830
+
831
+ This API returns details about terminals associated with a merchant account.
832
+
833
+ Status and resource information is returned for all terminals along with a preview of the
834
+ current branding image displayed on the terminal
835
+
836
+
837
+
838
+
839
+ ```javascript
840
+ let StaxPayments = require('@staxpayments/staxpayments-js');
841
+
842
+
843
+ // construct a client with your Stax bearer token; terminal transactions
844
+ // transparently exchange it for short-lived transient credentials
845
+ let client = new StaxPayments.StaxPaymentsClient(
846
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
847
+ );
848
+
849
+ client.terminals.terminals({
850
+ })
851
+ .then(function (response) {
852
+ console.log('Response: ' + JSON.stringify(response.data))
853
+ })
854
+ .catch(function (error) {
855
+ console.log(error)
856
+ });
857
+
858
+ ```
859
+
860
+ #### Deactivate Terminal
861
+
862
+
863
+
864
+ * **API Credential Types:** Merchant & Partner
865
+ * **Required Role:** Terminal Management
866
+
867
+ This API deactivates a payment terminal.
868
+
869
+ If the terminal exists and is currently online, it will be removed from the merchant's
870
+ terminal inventory. The terminal will be remotely cleared and factory reset.
871
+
872
+
873
+
874
+
875
+ ```javascript
876
+ let StaxPayments = require('@staxpayments/staxpayments-js');
877
+
878
+
879
+ // construct a client with your Stax bearer token; terminal transactions
880
+ // transparently exchange it for short-lived transient credentials
881
+ let client = new StaxPayments.StaxPaymentsClient(
882
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
883
+ );
884
+
885
+ client.terminals.deactivateTerminal({
886
+ terminalId: '<TERMINAL ID>',
887
+ })
888
+ .then(function (response) {
889
+ console.log('Response: ' + JSON.stringify(response.data))
890
+ })
891
+ .catch(function (error) {
892
+ console.log(error)
893
+ });
894
+
895
+ ```
896
+
897
+ #### Activate Terminal
898
+
899
+
900
+
901
+ * **API Credential Types:** Stax Bearer Token
902
+
903
+ This API activates a payment terminal.
904
+
905
+ If successful, the payment terminal will restart, generate new encryption keys, and download any active
906
+ branding assets for the merchant account it's been added to.
907
+
908
+ Activation requests require an activation code and a unique terminal name. All terminal names must be unique across
909
+ a merchant account.
910
+
911
+ This request is served by the Stax core API, so the merchant is derived from your bearer token and
912
+ cannot be overridden.
913
+
914
+
915
+
916
+ ```javascript
917
+ let StaxPayments = require('@staxpayments/staxpayments-js');
918
+
919
+
920
+ // construct a client with your Stax bearer token; terminal transactions
921
+ // transparently exchange it for short-lived transient credentials
922
+ let client = new StaxPayments.StaxPaymentsClient(
923
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
924
+ );
925
+
926
+ client.terminals.activateTerminal({
927
+ terminalName: 'Test Terminal',
928
+ activationCode: '<ACTIVATION CODE>',
929
+ })
930
+ .then(function (response) {
931
+ console.log('Response: ' + JSON.stringify(response.data))
932
+ })
933
+ .catch(function (error) {
934
+ console.log(error)
935
+ });
936
+
937
+ ```
938
+
939
+ #### Reboot Terminal
940
+
941
+
942
+
943
+ * **API Credential Types:** Merchant
944
+ * **Required Role:** Payment API Access
945
+
946
+ This API reboots the terminal.
947
+
948
+
949
+
950
+
951
+ ```javascript
952
+ let StaxPayments = require('@staxpayments/staxpayments-js');
953
+
954
+
955
+ // construct a client with your Stax bearer token; terminal transactions
956
+ // transparently exchange it for short-lived transient credentials
957
+ let client = new StaxPayments.StaxPaymentsClient(
958
+ new StaxPayments.StaxApiCredentials('<your-stax-bearer-token>')
959
+ );
960
+
961
+ client.terminals.reboot({
962
+ terminalName: 'Test Terminal',
963
+ })
964
+ .then(function (response) {
965
+ console.log('Response: ' + JSON.stringify(response.data))
966
+ })
967
+ .catch(function (error) {
968
+ console.log(error)
969
+ });
970
+
971
+ ```
972
+
973
+ ### Terms & Conditions Endpoints
974
+
975
+
976
+ Developers can use BlockChyp to display and capture acceptance of contracts or agreements related to transactions.
977
+ These agreements can be any long-form contract ranging from rental agreements to HIPPA disclosures.
978
+
979
+ There are two basic approaches to terms and conditions capture. Merchants can store contract templates in
980
+ BlockChyp or they can send the full agreement text as part of every API call. The right approach will largely
981
+ depend on whether or not the system being integrated with BlockChyp already has a mechanism for organizing
982
+ and managing agreements. For systems that already have this feature built in, it's probably not necessary
983
+ to use Terms and Conditions.
984
+
985
+ When agreements are displayed on a terminal, the consumer can scroll through and read the entire agreement,
986
+ and provide a signature. Results are returned as part of the API response, but BlockChyp also stores a
987
+ record of the agreement including the signature image, timestamp, and the full text of the agreement that was
988
+ agreed to.
989
+
990
+ The Terms and Conditions Log APIs can be used to search and retrieve acceptance records. Those records
991
+ can also be linked to a transaction if a transaction id is provided with the original API request.
992
+
993
+
994
+
995
+ ### Token Management
996
+
997
+
998
+ BlockChyp supports saved payments and recurring payments through the use of tokens. Tokens can be created
999
+ via the Enroll API or the web tokenizer. Once created, these tokens can be used for subsequent payments
1000
+ or associated with customer records as saved payment methods.
1001
+
1002
+ Tokens are limited to a single merchant by default, but can be shared across an organization for multi-location
1003
+ merchants by special arrangement with BlockChyp. Contact your BlockChyp rep to setup token sharing.
1004
+
1005
+
1006
+
1007
+ ### Customer Endpoints
1008
+
1009
+
1010
+ These APIs allow developers to create and manage customer records in BlockChyp. Developers who wish to use
1011
+ BlockChyp for tokenized recurring payments can use tokens directly if they have their own customer management
1012
+ system. However, BlockChyp provides additional tools for managing customers and keeping track of a customer's saved
1013
+ payment tokens.
1014
+
1015
+ In addition, if customer features are used, BlockChyp can detect a payment method associated with an existing
1016
+ customer, and return customer data with payment transactions. This can be used as a passive method to detect
1017
+ repeat customers.
1018
+
1019
+
1020
+
1021
+ ### Survey Reference
1022
+
1023
+
1024
+ These APIs are used to work with post-transaction surveys and survey data.
1025
+
1026
+ Merchants can optionally configure scaled (1-5) or yes/no questions that can be presented to consumers
1027
+ after every approved Charge and Preauth transaction. Surveys do not require any custom programming and
1028
+ merchants can simply configure them without the point-of-sale system needing any additional customization.
1029
+
1030
+ However, these APIs allow point-of-sale or third-party system developers to integrate survey question configuration
1031
+ or result visualization into their own systems.
1032
+
1033
+
1034
+
1035
+ ### Media and Branding Control
1036
+
1037
+
1038
+ BlockChyp has a sophisticated terminal media and branding control platform. Terminals can be configured to
1039
+ display logos, images, videos, and slide shows when a terminal is idle. Branding assets can be configured
1040
+ at the partner, organization, and merchant level with fine-grained hour-by-hour schedules, if desired.
1041
+
1042
+ Conceptually, all branding and media start with the media library. Merchants, Partners, and Organizations can
1043
+ upload images or video and build branding assets from uploaded media.
1044
+
1045
+ Slide shows can combine images from the media library into a timed loop of repeating images.
1046
+
1047
+ Branding Assets can then be used to combine media or slide shows with priority and timing rules to create what
1048
+ we call the Terminal Branding Stack.
1049
+
1050
+ We call a group of branding assets the *Terminal Branding Stack* because there are implicit rules about which
1051
+ branding assets take priority. For example, a merchant with no branding assets configured will inherit the
1052
+ branding rules from any organization to which the merchant may belong. If the merchant doesn't belong to an organization
1053
+ or the organization has no branding rules configured, then the system will defer to branding defaults established
1054
+ by the point-of-sale or software partner that owns the merchant.
1055
+
1056
+ This feature enables partners and organizations (multi-store operators and large national chains) to configure branding
1057
+ for potentially thousands of terminals from a single interface.
1058
+
1059
+ Terminal Branding can also be configured at the individual terminal level and a merchant's terminal fleet
1060
+ can be broken into groups and branding configured at the group level. Branding configured at the terminal
1061
+ level will always override branding from any higher level group.
1062
+
1063
+ The order of priority for the Terminal Branding Stack is given below.
1064
+
1065
+ * Terminal
1066
+ * Terminal Group
1067
+ * Merchant
1068
+ * Organization (Region, Chain, etc)
1069
+ * Partner
1070
+ * BlockChyp Default Logo
1071
+
1072
+
1073
+
1074
+ ### Merchant Management
1075
+
1076
+
1077
+ These APIs allow partners to manage and configure their merchant portfolios.
1078
+
1079
+ Use of these APIs (other than the Merchant Profile API) requires partner scoped API credentials
1080
+ with special roles and permissions that may require a special arrangement with BlockChyp.
1081
+
1082
+ For example, Partners usually can't board merchants directly, but must board merchants using
1083
+ the standard underwriting process via offer codes and invitations.
1084
+
1085
+
1086
+
1087
+ ### Partner Utilities
1088
+
1089
+
1090
+ These partner only APIs give ISV partners advanced reporting and tools for managing their portfolio.
1091
+
1092
+ Most of the APIs below are for portfolio reporting and range from basic partner commission statements
1093
+ to individual statements with all underlying card brand data.
1094
+
1095
+ We also provide a pricing policy API that enables partners to pull down the current pricing rules
1096
+ in force for any merchant in their portfolio.
1097
+
1098
+ <aside class="info">
1099
+ <b>Currency Data</b>
1100
+ <p>
1101
+ All partner APIs return currency and percentage values in two formats: floating point and formatted strings.
1102
+ </p>
1103
+ <p>
1104
+ It's recommended that all developers use the formatted string as this will ensure the most precise values.
1105
+ Floating point numbers are usually not appropriate for currency or fixed point decimal numbers as
1106
+ the underlying binary encoding can lead to errors in precision. We provide floating point values
1107
+ only as a convenience for developers want to save development time and can live with approximated
1108
+ values in their use case.
1109
+ </p>
1110
+ </aside>
1111
+
1112
+
1113
+
1114
+
1115
+
1116
+
1117
+
1118
+ ## Running Integration Tests
1119
+
1120
+ If you'd like to run the integration tests, create a new file on your system
1121
+ called `sdk-itest-config.json` with the API credentials you'll be using as
1122
+ shown in the example below.
1123
+
1124
+ ```
1125
+ {
1126
+ "gatewayHost": "https://api.blockchyp.com",
1127
+ "testGatewayHost": "https://test.blockchyp.com",
1128
+ "apiKey": "PZZNEFK7HFULCB3HTLA7HRQDJU",
1129
+ "bearerToken": "QUJCHIKNXOMSPGQ4QLT2UJX5DI",
1130
+ "signingKey": "f88a72d8bc0965f193abc7006bbffa240663c10e4d1dc3ba2f81e0ca10d359f5"
1131
+ }
1132
+ ```
1133
+
1134
+ This file can be located in a few different places, but is usually located
1135
+ at `<USER_HOME>/.config/blockchyp/sdk-itest-config.json`. All BlockChyp SDKs
1136
+ use the same configuration file.
1137
+
1138
+ To run the integration test suite via `make`, type the following command:
1139
+
1140
+ `make integration`
1141
+
1142
+
1143
+ ## Running Integration Tests With Jasmine
1144
+
1145
+ If you'd like to bypass make and run the integration test suite directly,
1146
+ use the following command:
1147
+
1148
+ `BC_TEST_DELAY=5 jasmine itest/*Spec.js`
1149
+
1150
+ If you'd like to run individual tests, try the following command:
1151
+
1152
+ `jasmine itest/TerminalChargeITestSpec.js`
1153
+
1154
+ ## Contributions
1155
+
1156
+ BlockChyp welcomes contributions from the open source community, but bear in mind
1157
+ that this repository has been generated by our internal SDK Generator tool. If
1158
+ we choose to accept a PR or contribution, your code will be moved into our SDK
1159
+ Generator project, which is a private repository.
1160
+
1161
+ ## License
1162
+
1163
+ Copyright BlockChyp, Inc., 2019
1164
+
1165
+ Distributed under the terms of the [MIT] license, staxpayments-js is free and open source software.
1166
+
1167
+ [MIT]: https://github.com/blockchyp/staxpayments-js/blob/master/LICENSE
1168
+
1169
+ ## Other SDKs
1170
+
1171
+ BlockChyp has officially supported SDKs for eight different development platforms and counting.
1172
+ Here's the full list with links to their GitHub repositories.
1173
+
1174
+ [Go SDK](https://github.com/blockchyp/blockchyp-go)
1175
+
1176
+ [Node.js/JavaScript SDK](https://github.com/blockchyp/blockchyp-js)
1177
+
1178
+ [Typescript SDK](https://github.com/blockchyp/blockchyp-ts)
1179
+
1180
+ [Java SDK](https://github.com/blockchyp/blockchyp-java)
1181
+
1182
+ [.net/C# SDK](https://github.com/blockchyp/blockchyp-csharp)
1183
+
1184
+ [Ruby SDK](https://github.com/blockchyp/blockchyp-ruby)
1185
+
1186
+ [PHP SDK](https://github.com/blockchyp/blockchyp-php)
1187
+
1188
+ [Python SDK](https://github.com/blockchyp/blockchyp-python)
1189
+
1190
+ [iOS (Objective-C/Swift) SDK](https://github.com/blockchyp/blockchyp-ios)
1191
+
1192
+ [Rust SDK](https://github.com/blockchyp/blockchyp-rust)