blockchyp 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/Makefile +71 -0
  3. data/README.md +997 -0
  4. data/Rakefile +39 -0
  5. data/lib/blockchyp.rb +190 -0
  6. data/lib/blockchyp/version.rb +5 -0
  7. data/lib/blockchyp_client.rb +346 -0
  8. data/lib/crypto_utils.rb +25 -0
  9. data/test/boolean_prompt_test.rb +43 -0
  10. data/test/capture_signature_test.rb +40 -0
  11. data/test/gateway_timeout_test.rb +40 -0
  12. data/test/heartbeat_test.rb +27 -0
  13. data/test/new_transaction_display_test.rb +78 -0
  14. data/test/pan_charge_test.rb +53 -0
  15. data/test/pan_enroll_test.rb +51 -0
  16. data/test/pan_preauth_test.rb +52 -0
  17. data/test/simple_batch_close_test.rb +48 -0
  18. data/test/simple_capture_test.rb +47 -0
  19. data/test/simple_gift_activate_test.rb +42 -0
  20. data/test/simple_message_test.rb +40 -0
  21. data/test/simple_ping_test.rb +39 -0
  22. data/test/simple_refund_test.rb +48 -0
  23. data/test/simple_reversal_test.rb +48 -0
  24. data/test/simple_void_test.rb +48 -0
  25. data/test/terminal_charge_test.rb +51 -0
  26. data/test/terminal_clear_test.rb +39 -0
  27. data/test/terminal_ebt_balance_test.rb +41 -0
  28. data/test/terminal_ebt_charge_test.rb +53 -0
  29. data/test/terminal_enroll_test.rb +50 -0
  30. data/test/terminal_gift_card_balance_test.rb +40 -0
  31. data/test/terminal_keyed_charge_test.rb +52 -0
  32. data/test/terminal_manual_ebt_charge_test.rb +54 -0
  33. data/test/terminal_preauth_test.rb +51 -0
  34. data/test/terminal_status_test.rb +39 -0
  35. data/test/terminal_timeout_test.rb +39 -0
  36. data/test/terms_and_conditions_test.rb +44 -0
  37. data/test/test_helper.rb +65 -0
  38. data/test/text_prompt_test.rb +41 -0
  39. data/test/update_transaction_display_test.rb +78 -0
  40. metadata +81 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 86d27e3160740596687ca591054e375b984d84685874fe628d778d57a2693a16
4
+ data.tar.gz: b9dfdf70be0b995ae1507194a994050b41831c21c757211373c3d8db1395f3b7
5
+ SHA512:
6
+ metadata.gz: bd19a88cad2c75ea351fda2e2db1d3b5aeb9b21f8042f690bc5504a8c22a0bb1db3016598eb6171ec1e2e3c5870030603dbc8fc55dd89991946e669728ef5b4d
7
+ data.tar.gz: e8c99dc0f04805c73378303cf19cad3a6e9419f9eb24034e4604ce30cbba9435b4edefd37050c4c2b882ca874f772c1d78df10228a9abffc378ef3c5d81e9575
@@ -0,0 +1,71 @@
1
+ # Version config
2
+ TAG := $(shell git tag --points-at HEAD | sort --version-sort | tail -n 1)
3
+ LASTTAG := $(or $(shell git tag -l | sort -r -V | head -n 1),0.1.0)
4
+ SNAPINFO := $(shell date +%Y%m%d%H%M%S)git$(shell git log -1 --pretty=%h)
5
+ RELEASE := $(or $(BUILD_NUMBER), 1)
6
+ VERSION := $(or $(TAG:v%=%),$(LASTTAG:v%=%))-$(or $(BUILD_NUMBER), 1)$(if $(TAG),,.$(SNAPINFO))
7
+
8
+ # Executables
9
+ DOCKER = docker
10
+ BUNDLE = bundle
11
+ SED = sed
12
+
13
+ # Integration test config
14
+ export BC_TEST_DELAY := 5
15
+ IMAGE := circleci/ruby
16
+ SCMROOT := $(shell git rev-parse --show-toplevel)
17
+ PWD := $(shell pwd)
18
+ CACHE := $(HOME)/.local/share/blockchyp/itest-cache
19
+ CONFIGFILE := $(HOME)/.config/blockchyp/sdk-itest-config.json
20
+ CACHEPATHS := $(dir $(CONFIGFILE)) $(HOME)/.bundle
21
+ ifeq ($(shell uname -s), Linux)
22
+ HOSTIP = $(shell ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
23
+ else
24
+ HOSTIP = host.docker.internal
25
+ endif
26
+
27
+ # Default target
28
+ .PHONY: all
29
+ all: clean build test
30
+
31
+ # Clean build artifacts
32
+ .PHONY: clean
33
+ clean:
34
+ $(RM) ./*.gem
35
+
36
+ # Build compiles the package
37
+ .PHONY: build
38
+ build:
39
+ $(BUNDLE) exec rake build
40
+
41
+ # Runs unit tests
42
+ .PHONY: test
43
+ test:
44
+
45
+ # Runs integration tests
46
+ .PHONY: integration
47
+ integration:
48
+ $(if $(LOCALBUILD), \
49
+ $(BUNDLE) exec rake test $(if $(TEST),TEST=$(TEST),,), \
50
+ $(foreach path,$(CACHEPATHS),mkdir -p $(CACHE)/$(path) ; ) \
51
+ sed 's/localhost/$(HOSTIP)/' $(CONFIGFILE) >$(CACHE)/$(CONFIGFILE) ; \
52
+ $(DOCKER) run \
53
+ -u $(shell id -u):$(shell id -g) \
54
+ -v $(SCMROOT):$(SCMROOT):Z \
55
+ -v /etc/passwd:/etc/passwd:ro \
56
+ $(foreach path,$(CACHEPATHS),-v $(CACHE)/$(path):$(path):Z) \
57
+ -e BC_TEST_DELAY=$(BC_TEST_DELAY) \
58
+ -e HOME=$(HOME) \
59
+ -w $(PWD) \
60
+ --rm -it $(IMAGE) \
61
+ bash -c "$(BUNDLE) install --path $(HOME)/.bundle/vendor && $(BUNDLE) exec rake test $(if $(TEST),TEST=$(TEST),)")
62
+
63
+ # Performs any tasks necessary before a release build
64
+ .PHONY: stage
65
+ stage:
66
+ $(SED) -i "s/VERSION = '.*'/VERSION = '$(shell sed 's/-/.pre./' <<<$(VERSION))'/" lib/blockchyp/version.rb
67
+
68
+ # Publish
69
+ .PHONY: publish
70
+ publish:
71
+ $(BUNDLE) exec rake publish
@@ -0,0 +1,997 @@
1
+ # BlockChyp Ruby SDK
2
+
3
+ [![Build Status](https://circleci.com/gh/blockchyp/blockchyp-ruby/tree/master.svg?style=shield)](https://circleci.com/gh/blockchyp/blockchyp-ruby/tree/master)
4
+ [![Gem](https://img.shields.io/gem/v/blockchyp)](https://rubygems.org/gems/blockchyp)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/blockchyp/blockchyp-ruby/blob/master/LICENSE)
6
+
7
+ This is the SDK for Ruby. Like all BlockChyp SDKs, it provides a full client
8
+ for the BlockChyp gateway and BlockChyp payment terminals.
9
+
10
+ ## Installation
11
+
12
+ This SDK is best consumed as a Ruby Gem. Type the following command to install
13
+ the BlockChyp Gem in your project.
14
+
15
+ ```
16
+ gem install blockchyp
17
+ ```
18
+
19
+ ## A Simple Example
20
+
21
+ Running your first transaction is easy. Make sure you have a BlockChyp terminal,
22
+ activate it, and generate a set of API keys. The sample code below show how
23
+ to run a basic terminal transaction.
24
+
25
+ ```ruby
26
+ require 'blockchyp'
27
+
28
+ blockchyp = BlockChyp.new("SPBXTSDAQVFFX5MGQMUMIRINVI", "7BXBTBUPSL3BP7I6Z2CFU6H3WQ", "bcae3708938cb8004ab1278e6c0fcd68f9d815e1c3c86228d028242b147af58e")
29
+
30
+ # setup request object
31
+ request = Hash.new
32
+ request["test"] = true
33
+ request["terminalName"] = "Test Terminal"
34
+ request["amount"] = "55.00"
35
+
36
+ response = blockchyp.charge(request)
37
+
38
+ if (response["approved"])
39
+ puts "Approved"
40
+ puts "authCode:" + response["authCode"]
41
+ puts "authorizedAmount:" + response["authorizedAmount"]
42
+ end
43
+ ```
44
+
45
+
46
+
47
+ ## The Rest APIs
48
+
49
+ All BlockChyp SDKs provide a convenient way of accessing the BlockChyp REST APIs.
50
+ You can checkout the REST API documentation via the links below.
51
+
52
+ [Terminal REST API Docs](https://docs.blockchyp.com/rest-api/terminal/index.html)
53
+
54
+ [Gateway REST API Docs](https://docs.blockchyp.com/rest-api/gateway/index.html)
55
+
56
+ ## Other SDKs
57
+
58
+ BlockChyp has officially supported SDKs for eight different development platforms and counting.
59
+ Here's the full list with links to their GitHub repositories.
60
+
61
+ [Go SDK](https://github.com/blockchyp/blockchyp-go)
62
+
63
+ [Node.js/JavaScript SDK](https://github.com/blockchyp/blockchyp-js)
64
+
65
+ [Java SDK](https://github.com/blockchyp/blockchyp-java)
66
+
67
+ [.net/C# SDK](https://github.com/blockchyp/blockchyp-csharp)
68
+
69
+ [Ruby SDK](https://github.com/blockchyp/blockchyp-ruby)
70
+
71
+ [PHP SDK](https://github.com/blockchyp/blockchyp-php)
72
+
73
+ [Python SDK](https://github.com/blockchyp/blockchyp-python)
74
+
75
+ [iOS (Objective-C/Swift) SDK](https://github.com/blockchyp/blockchyp-ios)
76
+
77
+ ## Getting a Developer Kit
78
+
79
+ In order to test your integration with real terminals, you'll need a BlockChyp
80
+ Developer Kit. Our kits include a fully functioning payment terminal with
81
+ test pin encryption keys. Every kit includes a comprehensive set of test
82
+ cards with test cards for every major card brand and entry method, including
83
+ Contactless and Contact EMV and mag stripe cards. Each kit also includes
84
+ test gift cards for our blockchain gift card system.
85
+
86
+ Access to BlockChyp's developer program is currently invite only, but you
87
+ can request an invitation by contacting our engineering team at **nerds@blockchyp.com**.
88
+
89
+ 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).
90
+
91
+ ## Transaction Code Examples
92
+
93
+ You don't want to read words. You want examples. Here's a quick rundown of the
94
+ stuff you can do with the BlockChyp Ruby SDK and a few basic examples.
95
+
96
+ #### Charge
97
+
98
+ Executes a standard direct preauth and capture.
99
+
100
+
101
+ ```ruby
102
+ # frozen_string_literal: true
103
+
104
+ require 'blockchyp'
105
+
106
+ blockchyp = BlockChyp::BlockChyp.new(
107
+ ENV['BC_API_KEY'],
108
+ ENV['BC_BEARER_TOKEN'],
109
+ ENV['BC_SIGNING_KEY']
110
+ )
111
+
112
+ # setup request object
113
+ request = {}
114
+ request['test'] = true
115
+ request['terminalName'] = 'Test Terminal'
116
+ request['amount'] = '55.00'
117
+
118
+ response = blockchyp.charge(request)
119
+
120
+ puts "Response: #{response.inspect}"
121
+
122
+
123
+ ```
124
+
125
+ #### Preauthorization
126
+
127
+ Executes a preauthorization intended to be captured later.
128
+
129
+
130
+ ```ruby
131
+ # frozen_string_literal: true
132
+
133
+ require 'blockchyp'
134
+
135
+ blockchyp = BlockChyp::BlockChyp.new(
136
+ ENV['BC_API_KEY'],
137
+ ENV['BC_BEARER_TOKEN'],
138
+ ENV['BC_SIGNING_KEY']
139
+ )
140
+
141
+ # setup request object
142
+ request = {}
143
+ request['test'] = true
144
+ request['terminalName'] = 'Test Terminal'
145
+ request['amount'] = '27.00'
146
+
147
+ response = blockchyp.preauth(request)
148
+
149
+ puts "Response: #{response.inspect}"
150
+
151
+
152
+ ```
153
+
154
+ #### Terminal Ping
155
+
156
+ Tests connectivity with a payment terminal.
157
+
158
+
159
+ ```ruby
160
+ # frozen_string_literal: true
161
+
162
+ require 'blockchyp'
163
+
164
+ blockchyp = BlockChyp::BlockChyp.new(
165
+ ENV['BC_API_KEY'],
166
+ ENV['BC_BEARER_TOKEN'],
167
+ ENV['BC_SIGNING_KEY']
168
+ )
169
+
170
+ # setup request object
171
+ request = {}
172
+ request['terminalName'] = 'Test Terminal'
173
+
174
+ response = blockchyp.ping(request)
175
+
176
+ puts "Response: #{response.inspect}"
177
+
178
+
179
+ ```
180
+
181
+ #### Balance
182
+
183
+ Checks the remaining balance on a payment method.
184
+
185
+
186
+ ```ruby
187
+ # frozen_string_literal: true
188
+
189
+ require 'blockchyp'
190
+
191
+ blockchyp = BlockChyp::BlockChyp.new(
192
+ ENV['BC_API_KEY'],
193
+ ENV['BC_BEARER_TOKEN'],
194
+ ENV['BC_SIGNING_KEY']
195
+ )
196
+
197
+ # setup request object
198
+ request = {}
199
+ request['test'] = true
200
+ request['terminalName'] = 'Test Terminal'
201
+ request['cardType'] = CardType::EBT
202
+
203
+ response = blockchyp.balance(request)
204
+
205
+ puts "Response: #{response.inspect}"
206
+
207
+
208
+ ```
209
+
210
+ #### Terminal Clear
211
+
212
+ Clears the line item display and any in progress transaction.
213
+
214
+
215
+ ```ruby
216
+ # frozen_string_literal: true
217
+
218
+ require 'blockchyp'
219
+
220
+ blockchyp = BlockChyp::BlockChyp.new(
221
+ ENV['BC_API_KEY'],
222
+ ENV['BC_BEARER_TOKEN'],
223
+ ENV['BC_SIGNING_KEY']
224
+ )
225
+
226
+ # setup request object
227
+ request = {}
228
+ request['test'] = true
229
+ request['terminalName'] = 'Test Terminal'
230
+
231
+ response = blockchyp.clear(request)
232
+
233
+ puts "Response: #{response.inspect}"
234
+
235
+
236
+ ```
237
+
238
+ #### Terms & Conditions Capture
239
+
240
+ Prompts the user to accept terms and conditions.
241
+
242
+
243
+ ```ruby
244
+ # frozen_string_literal: true
245
+
246
+ require 'blockchyp'
247
+
248
+ blockchyp = BlockChyp::BlockChyp.new(
249
+ ENV['BC_API_KEY'],
250
+ ENV['BC_BEARER_TOKEN'],
251
+ ENV['BC_SIGNING_KEY']
252
+ )
253
+
254
+ # setup request object
255
+ request = {}
256
+ request['test'] = true
257
+ request['terminalName'] = 'Test Terminal'
258
+ request['tcAlias'] = 'hippa'
259
+ request['tcName'] = 'HIPPA Disclosure'
260
+ request['tcContent'] = 'Full contract text'
261
+ request['sigFormat'] = SignatureFormat::PNG
262
+ request['sigWidth'] = 200
263
+ request['sigRequired'] = true
264
+
265
+ response = blockchyp.termsAndConditions(request)
266
+
267
+ puts "Response: #{response.inspect}"
268
+
269
+
270
+ ```
271
+
272
+ #### Update Transaction Display
273
+
274
+ Appends items to an existing transaction display. Subtotal, Tax, and Total are
275
+ overwritten by the request. Items with the same description are combined into
276
+ groups.
277
+
278
+
279
+ ```ruby
280
+ # frozen_string_literal: true
281
+
282
+ require 'blockchyp'
283
+
284
+ blockchyp = BlockChyp::BlockChyp.new(
285
+ ENV['BC_API_KEY'],
286
+ ENV['BC_BEARER_TOKEN'],
287
+ ENV['BC_SIGNING_KEY']
288
+ )
289
+
290
+ # setup request object
291
+ request = {}
292
+ request['test'] = true
293
+ request['terminalName'] = 'Test Terminal'
294
+ request['transaction'] = new_transaction_display_transaction
295
+
296
+ response = blockchyp.updateTransactionDisplay(request)
297
+
298
+ puts "Response: #{response.inspect}"
299
+ def new_transaction_display_transaction
300
+ val = {}
301
+ val['subtotal'] = '60.00'
302
+ val['tax'] = '5.00'
303
+ val['total'] = '65.00'
304
+ val['items'] = new_transaction_display_items
305
+ val
306
+ end
307
+
308
+ def new_transaction_display_items
309
+ val = []
310
+ val = val.push(new_transaction_display_item_2)
311
+ val
312
+ end
313
+
314
+ def new_transaction_display_item_2
315
+ val = {}
316
+ val['description'] = 'Leki Trekking Poles'
317
+ val['price'] = '35.00'
318
+ val['quantity'] = 2
319
+ val['extended'] = '70.00'
320
+ val['discounts'] = new_transaction_display_discounts
321
+ val
322
+ end
323
+
324
+ def new_transaction_display_discounts
325
+ val = []
326
+ val = val.push(new_transaction_display_discount_2)
327
+ val
328
+ end
329
+
330
+ def new_transaction_display_discount_2
331
+ val = {}
332
+ val['description'] = 'memberDiscount'
333
+ val['amount'] = '10.00'
334
+ val
335
+ end
336
+
337
+
338
+
339
+ ```
340
+
341
+ #### New Transaction Display
342
+
343
+ Displays a new transaction on the terminal.
344
+
345
+
346
+ ```ruby
347
+ # frozen_string_literal: true
348
+
349
+ require 'blockchyp'
350
+
351
+ blockchyp = BlockChyp::BlockChyp.new(
352
+ ENV['BC_API_KEY'],
353
+ ENV['BC_BEARER_TOKEN'],
354
+ ENV['BC_SIGNING_KEY']
355
+ )
356
+
357
+ # setup request object
358
+ request = {}
359
+ request['test'] = true
360
+ request['terminalName'] = 'Test Terminal'
361
+ request['transaction'] = new_transaction_display_transaction
362
+
363
+ response = blockchyp.newTransactionDisplay(request)
364
+
365
+ puts "Response: #{response.inspect}"
366
+ def new_transaction_display_transaction
367
+ val = {}
368
+ val['subtotal'] = '60.00'
369
+ val['tax'] = '5.00'
370
+ val['total'] = '65.00'
371
+ val['items'] = new_transaction_display_items
372
+ val
373
+ end
374
+
375
+ def new_transaction_display_items
376
+ val = []
377
+ val = val.push(new_transaction_display_item_2)
378
+ val
379
+ end
380
+
381
+ def new_transaction_display_item_2
382
+ val = {}
383
+ val['description'] = 'Leki Trekking Poles'
384
+ val['price'] = '35.00'
385
+ val['quantity'] = 2
386
+ val['extended'] = '70.00'
387
+ val['discounts'] = new_transaction_display_discounts
388
+ val
389
+ end
390
+
391
+ def new_transaction_display_discounts
392
+ val = []
393
+ val = val.push(new_transaction_display_discount_2)
394
+ val
395
+ end
396
+
397
+ def new_transaction_display_discount_2
398
+ val = {}
399
+ val['description'] = 'memberDiscount'
400
+ val['amount'] = '10.00'
401
+ val
402
+ end
403
+
404
+
405
+
406
+ ```
407
+
408
+ #### Text Prompt
409
+
410
+ Asks the consumer a text based question.
411
+
412
+
413
+ ```ruby
414
+ # frozen_string_literal: true
415
+
416
+ require 'blockchyp'
417
+
418
+ blockchyp = BlockChyp::BlockChyp.new(
419
+ ENV['BC_API_KEY'],
420
+ ENV['BC_BEARER_TOKEN'],
421
+ ENV['BC_SIGNING_KEY']
422
+ )
423
+
424
+ # setup request object
425
+ request = {}
426
+ request['test'] = true
427
+ request['terminalName'] = 'Test Terminal'
428
+ request['promptType'] = PromptType::EMAIL
429
+
430
+ response = blockchyp.textPrompt(request)
431
+
432
+ puts "Response: #{response.inspect}"
433
+
434
+
435
+ ```
436
+
437
+ #### Boolean Prompt
438
+
439
+ Asks the consumer a yes/no question.
440
+
441
+
442
+ ```ruby
443
+ # frozen_string_literal: true
444
+
445
+ require 'blockchyp'
446
+
447
+ blockchyp = BlockChyp::BlockChyp.new(
448
+ ENV['BC_API_KEY'],
449
+ ENV['BC_BEARER_TOKEN'],
450
+ ENV['BC_SIGNING_KEY']
451
+ )
452
+
453
+ # setup request object
454
+ request = {}
455
+ request['test'] = true
456
+ request['terminalName'] = 'Test Terminal'
457
+ request['prompt'] = 'Would you like to become a member?'
458
+ request['yesCaption'] = 'Yes'
459
+ request['noCaption'] = 'No'
460
+
461
+ response = blockchyp.booleanPrompt(request)
462
+
463
+ puts "Response: #{response.inspect}"
464
+
465
+
466
+ ```
467
+
468
+ #### Display Message
469
+
470
+ Displays a short message on the terminal.
471
+
472
+
473
+ ```ruby
474
+ # frozen_string_literal: true
475
+
476
+ require 'blockchyp'
477
+
478
+ blockchyp = BlockChyp::BlockChyp.new(
479
+ ENV['BC_API_KEY'],
480
+ ENV['BC_BEARER_TOKEN'],
481
+ ENV['BC_SIGNING_KEY']
482
+ )
483
+
484
+ # setup request object
485
+ request = {}
486
+ request['test'] = true
487
+ request['terminalName'] = 'Test Terminal'
488
+ request['message'] = 'Thank you for your business.'
489
+
490
+ response = blockchyp.message(request)
491
+
492
+ puts "Response: #{response.inspect}"
493
+
494
+
495
+ ```
496
+
497
+ #### Refund
498
+
499
+ Executes a refund.
500
+
501
+
502
+ ```ruby
503
+ # frozen_string_literal: true
504
+
505
+ require 'blockchyp'
506
+
507
+ blockchyp = BlockChyp::BlockChyp.new(
508
+ ENV['BC_API_KEY'],
509
+ ENV['BC_BEARER_TOKEN'],
510
+ ENV['BC_SIGNING_KEY']
511
+ )
512
+
513
+ # setup request object
514
+ request = {}
515
+ request['terminalName'] = 'Test Terminal'
516
+ request['transactionId'] = '<PREVIOUS TRANSACTION ID>'
517
+ request['amount'] = '5.00'
518
+
519
+ response = blockchyp.refund(request)
520
+
521
+ puts "Response: #{response.inspect}"
522
+
523
+
524
+ ```
525
+
526
+ #### Enroll
527
+
528
+ Adds a new payment method to the token vault.
529
+
530
+
531
+ ```ruby
532
+ # frozen_string_literal: true
533
+
534
+ require 'blockchyp'
535
+
536
+ blockchyp = BlockChyp::BlockChyp.new(
537
+ ENV['BC_API_KEY'],
538
+ ENV['BC_BEARER_TOKEN'],
539
+ ENV['BC_SIGNING_KEY']
540
+ )
541
+
542
+ # setup request object
543
+ request = {}
544
+ request['test'] = true
545
+ request['terminalName'] = 'Test Terminal'
546
+
547
+ response = blockchyp.enroll(request)
548
+
549
+ puts "Response: #{response.inspect}"
550
+
551
+
552
+ ```
553
+
554
+ #### Gift Card Activation
555
+
556
+ Activates or recharges a gift card.
557
+
558
+
559
+ ```ruby
560
+ # frozen_string_literal: true
561
+
562
+ require 'blockchyp'
563
+
564
+ blockchyp = BlockChyp::BlockChyp.new(
565
+ ENV['BC_API_KEY'],
566
+ ENV['BC_BEARER_TOKEN'],
567
+ ENV['BC_SIGNING_KEY']
568
+ )
569
+
570
+ # setup request object
571
+ request = {}
572
+ request['test'] = true
573
+ request['terminalName'] = 'Test Terminal'
574
+ request['amount'] = '50.00'
575
+
576
+ response = blockchyp.giftActivate(request)
577
+
578
+ puts "Response: #{response.inspect}"
579
+
580
+
581
+ ```
582
+
583
+ #### Time Out Reversal
584
+
585
+ Executes a manual time out reversal.
586
+
587
+ We love time out reversals. Don't be afraid to use them whenever a request to a
588
+ BlockChyp terminal times out. You have up to two minutes to reverse any
589
+ transaction. The only caveat is that you must assign transactionRef values when
590
+ you build the original request. Otherwise, we have no real way of knowing which
591
+ transaction you're trying to reverse because we may not have assigned it an id
592
+ yet. And if we did assign it an id, you wouldn't know what it is because your
593
+ request to the terminal timed out before you got a response.
594
+
595
+
596
+ ```ruby
597
+ # frozen_string_literal: true
598
+
599
+ require 'blockchyp'
600
+
601
+ blockchyp = BlockChyp::BlockChyp.new(
602
+ ENV['BC_API_KEY'],
603
+ ENV['BC_BEARER_TOKEN'],
604
+ ENV['BC_SIGNING_KEY']
605
+ )
606
+
607
+ # setup request object
608
+ request = {}
609
+ request['terminalName'] = 'Test Terminal'
610
+ request['transactionRef'] = '<LAST TRANSACTION REF>'
611
+
612
+ response = blockchyp.reverse(request)
613
+
614
+ puts "Response: #{response.inspect}"
615
+
616
+
617
+ ```
618
+
619
+ #### Capture Preauthorization
620
+
621
+ Captures a preauthorization.
622
+
623
+
624
+ ```ruby
625
+ # frozen_string_literal: true
626
+
627
+ require 'blockchyp'
628
+
629
+ blockchyp = BlockChyp::BlockChyp.new(
630
+ ENV['BC_API_KEY'],
631
+ ENV['BC_BEARER_TOKEN'],
632
+ ENV['BC_SIGNING_KEY']
633
+ )
634
+
635
+ # setup request object
636
+ request = {}
637
+ request['test'] = true
638
+ request['transactionId'] = '<PREAUTH TRANSACTION ID>'
639
+
640
+ response = blockchyp.capture(request)
641
+
642
+ puts "Response: #{response.inspect}"
643
+
644
+
645
+ ```
646
+
647
+ #### Close Batch
648
+
649
+ Closes the current credit card batch.
650
+
651
+
652
+ ```ruby
653
+ # frozen_string_literal: true
654
+
655
+ require 'blockchyp'
656
+
657
+ blockchyp = BlockChyp::BlockChyp.new(
658
+ ENV['BC_API_KEY'],
659
+ ENV['BC_BEARER_TOKEN'],
660
+ ENV['BC_SIGNING_KEY']
661
+ )
662
+
663
+ # setup request object
664
+ request = {}
665
+ request['test'] = true
666
+
667
+ response = blockchyp.closeBatch(request)
668
+
669
+ puts "Response: #{response.inspect}"
670
+
671
+
672
+ ```
673
+
674
+ #### Void Transaction
675
+
676
+ Discards a previous preauth transaction.
677
+
678
+
679
+ ```ruby
680
+ # frozen_string_literal: true
681
+
682
+ require 'blockchyp'
683
+
684
+ blockchyp = BlockChyp::BlockChyp.new(
685
+ ENV['BC_API_KEY'],
686
+ ENV['BC_BEARER_TOKEN'],
687
+ ENV['BC_SIGNING_KEY']
688
+ )
689
+
690
+ # setup request object
691
+ request = {}
692
+ request['test'] = true
693
+ request['transactionId'] = '<PREVIOUS TRANSACTION ID>'
694
+
695
+ response = blockchyp.void(request)
696
+
697
+ puts "Response: #{response.inspect}"
698
+
699
+
700
+ ```
701
+
702
+ #### Terminal Status
703
+
704
+ Returns the current status of a terminal.
705
+
706
+
707
+ ```ruby
708
+ # frozen_string_literal: true
709
+
710
+ require 'blockchyp'
711
+
712
+ blockchyp = BlockChyp::BlockChyp.new(
713
+ ENV['BC_API_KEY'],
714
+ ENV['BC_BEARER_TOKEN'],
715
+ ENV['BC_SIGNING_KEY']
716
+ )
717
+
718
+ # setup request object
719
+ request = {}
720
+ request['terminalName'] = 'Test Terminal'
721
+
722
+ response = blockchyp.terminalStatus(request)
723
+
724
+ puts "Response: #{response.inspect}"
725
+
726
+
727
+ ```
728
+
729
+ #### Capture Signature.
730
+
731
+ Captures and returns a signature.
732
+
733
+
734
+ ```ruby
735
+ # frozen_string_literal: true
736
+
737
+ require 'blockchyp'
738
+
739
+ blockchyp = BlockChyp::BlockChyp.new(
740
+ ENV['BC_API_KEY'],
741
+ ENV['BC_BEARER_TOKEN'],
742
+ ENV['BC_SIGNING_KEY']
743
+ )
744
+
745
+ # setup request object
746
+ request = {}
747
+ request['terminalName'] = 'Test Terminal'
748
+ request['sigFormat'] = SignatureFormat::PNG
749
+ request['sigWidth'] = 200
750
+
751
+ response = blockchyp.captureSignature(request)
752
+
753
+ puts "Response: #{response.inspect}"
754
+
755
+
756
+ ```
757
+
758
+ #### Update Customer
759
+
760
+ Updates or creates a customer record.
761
+
762
+
763
+ ```ruby
764
+ # frozen_string_literal: true
765
+
766
+ require 'blockchyp'
767
+
768
+ blockchyp = BlockChyp::BlockChyp.new(
769
+ ENV['BC_API_KEY'],
770
+ ENV['BC_BEARER_TOKEN'],
771
+ ENV['BC_SIGNING_KEY']
772
+ )
773
+
774
+ # setup request object
775
+ request = {}
776
+ request['customer'] = new_customer
777
+
778
+ response = blockchyp.updateCustomer(request)
779
+
780
+ puts "Response: #{response.inspect}"
781
+ def new_customer
782
+ val = {}
783
+ val['id'] = 'ID of the customer to update'
784
+ val['customerRef'] = 'Customer reference string'
785
+ val['firstName'] = 'FirstName'
786
+ val['lastName'] = 'LastName'
787
+ val['companyName'] = 'Company Name'
788
+ val['emailAddress'] = 'support@blockchyp.com'
789
+ val['smsNumber'] = '(123) 123-1231'
790
+ val
791
+ end
792
+
793
+
794
+
795
+ ```
796
+
797
+ #### Retrieve Customer
798
+
799
+ Retrieves a customer by id.
800
+
801
+
802
+ ```ruby
803
+ # frozen_string_literal: true
804
+
805
+ require 'blockchyp'
806
+
807
+ blockchyp = BlockChyp::BlockChyp.new(
808
+ ENV['BC_API_KEY'],
809
+ ENV['BC_BEARER_TOKEN'],
810
+ ENV['BC_SIGNING_KEY']
811
+ )
812
+
813
+ # setup request object
814
+ request = {}
815
+ request['customerId'] = 'ID of the customer to retrieve'
816
+
817
+ response = blockchyp.customer(request)
818
+
819
+ puts "Response: #{response.inspect}"
820
+
821
+
822
+ ```
823
+
824
+ #### Search Customer
825
+
826
+ Searches the customer database.
827
+
828
+
829
+ ```ruby
830
+ # frozen_string_literal: true
831
+
832
+ require 'blockchyp'
833
+
834
+ blockchyp = BlockChyp::BlockChyp.new(
835
+ ENV['BC_API_KEY'],
836
+ ENV['BC_BEARER_TOKEN'],
837
+ ENV['BC_SIGNING_KEY']
838
+ )
839
+
840
+ # setup request object
841
+ request = {}
842
+ request['query'] = '(123) 123-1234'
843
+
844
+ response = blockchyp.customerSearch(request)
845
+
846
+ puts "Response: #{response.inspect}"
847
+
848
+
849
+ ```
850
+
851
+ #### Transaction Status
852
+
853
+ Retrieves the current status of a transaction.
854
+
855
+
856
+ ```ruby
857
+ # frozen_string_literal: true
858
+
859
+ require 'blockchyp'
860
+
861
+ blockchyp = BlockChyp::BlockChyp.new(
862
+ ENV['BC_API_KEY'],
863
+ ENV['BC_BEARER_TOKEN'],
864
+ ENV['BC_SIGNING_KEY']
865
+ )
866
+
867
+ # setup request object
868
+ request = {}
869
+ request['transactionId'] = 'ID of transaction to retrieve'
870
+
871
+ response = blockchyp.transactionStatus(request)
872
+
873
+ puts "Response: #{response.inspect}"
874
+
875
+
876
+ ```
877
+
878
+ #### Send Payment Link
879
+
880
+ Creates and send a payment link to a customer.
881
+
882
+
883
+ ```ruby
884
+ # frozen_string_literal: true
885
+
886
+ require 'blockchyp'
887
+
888
+ blockchyp = BlockChyp::BlockChyp.new(
889
+ ENV['BC_API_KEY'],
890
+ ENV['BC_BEARER_TOKEN'],
891
+ ENV['BC_SIGNING_KEY']
892
+ )
893
+
894
+ # setup request object
895
+ request = {}
896
+ request['amount'] = '199.99'
897
+ request['description'] = 'Widget'
898
+ request['subject'] = 'Widget invoice'
899
+ request['transaction'] = new_transaction_display_transaction
900
+ request['autoSend'] = true
901
+ request['customer'] = new_customer
902
+
903
+ response = blockchyp.sendPaymentLink(request)
904
+
905
+ puts "Response: #{response.inspect}"
906
+ def new_transaction_display_transaction
907
+ val = {}
908
+ val['subtotal'] = '195.00'
909
+ val['tax'] = '4.99'
910
+ val['total'] = '199.99'
911
+ val['items'] = new_transaction_display_items
912
+ val
913
+ end
914
+
915
+ def new_transaction_display_items
916
+ val = []
917
+ val = val.push(new_transaction_display_item_2)
918
+ val
919
+ end
920
+
921
+ def new_transaction_display_item_2
922
+ val = {}
923
+ val['description'] = 'Widget'
924
+ val['price'] = '195.00'
925
+ val['quantity'] = 1
926
+ val
927
+ end
928
+
929
+ def new_customer
930
+ val = {}
931
+ val['customerRef'] = 'Customer reference string'
932
+ val['firstName'] = 'FirstName'
933
+ val['lastName'] = 'LastName'
934
+ val['companyName'] = 'Company Name'
935
+ val['emailAddress'] = 'support@blockchyp.com'
936
+ val['smsNumber'] = '(123) 123-1231'
937
+ val
938
+ end
939
+
940
+
941
+
942
+ ```
943
+
944
+ ## Running Integration Tests
945
+
946
+ If you'd like to run the integration tests, create a new file on your system
947
+ called `sdk-itest-config.json` with the API credentials you'll be using as
948
+ shown in the example below.
949
+
950
+ ```
951
+ {
952
+ "gatewayHost": "https://api.blockchyp.com",
953
+ "testGatewayHost": "https://test.blockchyp.com",
954
+ "apiKey": "PZZNEFK7HFULCB3HTLA7HRQDJU",
955
+ "bearerToken": "QUJCHIKNXOMSPGQ4QLT2UJX5DI",
956
+ "signingKey": "f88a72d8bc0965f193abc7006bbffa240663c10e4d1dc3ba2f81e0ca10d359f5"
957
+ }
958
+ ```
959
+
960
+ This file can be located in a few different places, but is usually located
961
+ at `<USER_HOME>/.config/blockchyp/sdk-itest-config.json`. All BlockChyp SDKs
962
+ use the same configuration file.
963
+
964
+ To run the integration test suite via `make`, type the following command:
965
+
966
+ `make integration`
967
+
968
+
969
+ ## Running Integration Tests Via Rake or Ruby
970
+
971
+ If you'd like to bypass make and run the integration test suite directly,
972
+ you can run the entire test suite with Rake using the following command:
973
+
974
+ `BC_TEST_DELAY=5 rake test`
975
+
976
+ You can run individual tests by adding executing them as normal Ruby files.
977
+
978
+ `ruby test/terminal_charge_test.rb`
979
+
980
+
981
+
982
+
983
+
984
+ ## Contributions
985
+
986
+ BlockChyp welcomes contributions from the open source community, but bear in mind
987
+ that this repository has been generated by our internal SDK Generator tool. If
988
+ we choose to accept a PR or contribution, your code will be moved into our SDK
989
+ Generator project, which is a private repository.
990
+
991
+ ## License
992
+
993
+ Copyright BlockChyp, Inc., 2019
994
+
995
+ Distributed under the terms of the [MIT] license, blockchyp-ruby is free and open source software.
996
+
997
+ [MIT]: https://github.com/blockchyp/blockchyp-ruby/blob/master/LICENSE