paytrace 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bd07fbb1aa8790f15aef76475889b670c70dcf6
4
- data.tar.gz: 3278c3fb6a5dbd3ee70a37fe3c936d077c9ea665
3
+ metadata.gz: 3d869a7a1682a69f321a50d93bd9e866c4149f1a
4
+ data.tar.gz: f71c44dd7d62b4aa4fd233342c3f3dbfe4d24ae0
5
5
  SHA512:
6
- metadata.gz: f91baaad3173806193bc0ca109975cd16617b0a5423e03f9cfc127c0e338abcf077ee285e17b64a60a866198bc7130a282104af75d7450611187df54f2cc1a9f
7
- data.tar.gz: e900959662bf88b1b3b196db6d431d67952b3e492c98cf8c94ef1b8516840e8742c98ec344d26d217f6f7b4e1062f13ea0ea62fec04df8dbf53dedfa40d91f88
6
+ metadata.gz: 00ef5897480340a8f83e9e690d8057e39706398215f46e5c55ea106b5a218a9f8eaa17242f4116f8877a22ce4eb900c1feb6e415862aa19e19a33d225b9fe856
7
+ data.tar.gz: 21f438fc6405a3cb60333b15860b1f04a01f5fda2d13f8cb561dfa5bce75dcbba5d6b11efecdb497e4c110e2ab106ab4f04164b000cab3405b793c1da70c69de
data/README.md CHANGED
@@ -2,11 +2,6 @@
2
2
 
3
3
  ![Build Status](https://www.codeship.io/projects/611ffe60-f3ee-0130-0299-1a84c3740ef1/status)
4
4
 
5
- *This SDK is actively under development but should still be considered in an alpha
6
- state. It does not provide all the access we are planning to our API at this time.
7
- Please feel free to experiment with it and we will be regularly pushing out new
8
- updates with increased functionality over the coming weeks*
9
-
10
5
  This gem integrates with the PayTrace API. It provides functionality to the
11
6
  publicly available functionality including:
12
7
 
@@ -14,6 +9,7 @@ publicly available functionality including:
14
9
  * Creating Customers
15
10
  * Exporting Transaction or Customer Data
16
11
 
12
+ Note that the gem is intended to be a "thin shim" around the public API, cleaning up and organizing the URL-based function calls. It is designed to be consumed by other code for payment processing.
17
13
 
18
14
  ## Installation
19
15
 
@@ -46,15 +42,15 @@ end
46
42
  ### Transactions
47
43
 
48
44
  Transactions can be processed utilizing class methods on the PayTrace::Transaction
49
- class.
45
+ class. A simple example:
50
46
 
51
47
  ```ruby
52
- transaction = Transaction.sale(
53
- {amount: "1.00",
54
- credit_card: {
55
- card_number: "1111222233334444",
56
- expiration_year: 14,
57
- expiration_month: 3
48
+ response = Transaction.sale(
49
+ {
50
+ amount: "1.00",
51
+ card_number: "1111222233334444",
52
+ expiration_year: 14,
53
+ expiration_month: 3
58
54
  }
59
55
  }
60
56
  )
@@ -62,12 +58,12 @@ transaction = Transaction.sale(
62
58
  #
63
59
  ## Response information is available on the transaction
64
60
  #
65
- puts transaction.response_code # 101. Your transaction was successfully approved.
61
+ puts response.get_response() # 101. Your transaction was successfully approved.
66
62
 
67
63
  #
68
- ## All values returned are accessible through the attached response property
64
+ ## All values returned are accessible through the response
69
65
  #
70
- transaction.response.each do |key, value|
66
+ response.values do |key, value|
71
67
  puts key # e.g. APPCODE
72
68
  puts value # TAS671
73
69
  end
@@ -77,21 +73,19 @@ end
77
73
 
78
74
  ```ruby
79
75
  # running a transaction for a customer
80
- transaction = Transaction.sale({amount: "1.00",customer: my_customer_id})
76
+ Transaction.sale({amount: "1.00",customer: my_customer_id})
81
77
 
82
78
  ```
83
79
  ### Some Optional Fields
84
80
  ```ruby
85
81
  #Adding Optional Fields
86
82
 
87
- transaction = Transaction.Sale(
83
+ Transaction.Sale(
88
84
  {
89
85
  amount: "1.00",
90
- credit_card: {
91
- card_number: "1111222233334444",
92
- expiration_year: 14,
93
- expiration_month: 3
94
- },
86
+ card_number: "1111222233334444",
87
+ expiration_year: 14,
88
+ expiration_month: 3,
95
89
  email:"me@example.com",
96
90
  description:"This is a test",
97
91
  tax_amount:".50",
@@ -103,27 +97,20 @@ transaction = Transaction.Sale(
103
97
 
104
98
  ### Billing and Shipping Address
105
99
  ```ruby
106
- transaction = Transaction.Sale(
107
- {amount: "1.00",
108
- credit_card: {
100
+ Transaction.Sale(
101
+ {
102
+ amount: "1.00",
109
103
  card_number: "1111222233334444",
110
104
  expiration_year: 14,
111
- expiration_month: 3
112
- },
113
- billing_address:{
114
- name:"Jane Doe",
115
- street:"1234 happy st.",
116
- street2:"apt#2",
117
- city:"Seattle",
118
- state:"WA",
119
- country: "US",
120
- postal_code:"98107"
121
- },
122
- shipping_address: {
123
- #Same as billing above.
124
- }
125
- }
126
- )
105
+ expiration_month: 3,
106
+ billing_name:"Jane Doe",
107
+ billing_address:"1234 happy st.",
108
+ billing_address2:"apt#2",
109
+ billing_city:"Seattle",
110
+ billing_state:"WA",
111
+ billing_country: "US",
112
+ billing_postal_code:"98107"
113
+ })
127
114
 
128
115
  ```
129
116
 
@@ -92,7 +92,7 @@ module PayTrace
92
92
  @@next_response = nil # just to be sure
93
93
 
94
94
  if @@raise_exceptions && response.has_errors?
95
- raise PayTrace::Exceptions::ErrorResponse.new(response.get_response())
95
+ raise PayTrace::Exceptions::ErrorResponse.new(response)
96
96
  else
97
97
  response
98
98
  end
@@ -42,9 +42,10 @@ module PayTrace
42
42
 
43
43
  begin
44
44
  yield
45
- rescue Exception => e
45
+ rescue PayTrace::Exceptions::ErrorResponse => e
46
46
  puts "[REQUEST] #{PayTrace::API::Gateway.last_request}"
47
-
47
+ puts "[RESPONSE] #{PayTrace::API::Gateway.last_response}"
48
+
48
49
  raise
49
50
  else
50
51
  dump_transaction
@@ -61,12 +62,17 @@ module PayTrace
61
62
  end
62
63
  end
63
64
 
65
+ # helper method to make CodeClimate happy
66
+ def self.split_tuples(raw, case_sensitive = false)
67
+ PayTrace::Debug.split_request_string(raw).map {|tuple| case_sensitive ? tuple : [tuple[0].upcase, tuple[1]]}
68
+ end
69
+
64
70
  # verify whether two requests match
65
71
  def self.diff_requests(expected_raw, actual_raw, case_sensitive = false)
66
72
  whats_wrong = []
67
73
 
68
- expected = PayTrace::Debug.split_request_string(expected_raw).map {|tuple| case_sensitive ? tuple : [tuple[0].upcase, tuple[1]]}
69
- actual = PayTrace::Debug.split_request_string(actual_raw).map {|tuple| case_sensitive ? tuple : [tuple[0].upcase, tuple[1]]}
74
+ expected = PayTrace::Debug.split_tuples(expected_raw, case_sensitive)
75
+ actual = PayTrace::Debug.split_tuples(actual_raw, case_sensitive)
70
76
 
71
77
  expected_remaining = []
72
78
  actual_extra = actual.dup
@@ -11,6 +11,15 @@ module PayTrace
11
11
 
12
12
  # Raised by default when an error response is returned from the server
13
13
  class ErrorResponse < Base
14
+ attr_reader :response
15
+
16
+ def initialize(response)
17
+ @response = response
18
+ end
19
+
20
+ def to_s
21
+ @response.get_response()
22
+ end
14
23
  end
15
24
  end
16
25
  end
@@ -90,6 +90,21 @@ module PayTrace
90
90
 
91
91
  STORE_AND_FORWARD_OPTIONAL = ALL_OPTIONAL_FIELDS + [:store_forward_date]
92
92
 
93
+ CASH_ADVANCE_REQUIRED = [
94
+ :transaction_type,
95
+ :amount,
96
+ :cash_advance,
97
+ :id_number,
98
+ :id_expiration,
99
+ :cc_last_4,
100
+ :billing_name,
101
+ :billing_address,
102
+ :billing_address2,
103
+ :billing_city,
104
+ :billing_state,
105
+ :billing_postal_code
106
+ ]
107
+
93
108
  CASH_ADVANCE_OPTIONAL = [
94
109
  :billing_country,
95
110
  :shipping_name,
@@ -119,10 +134,7 @@ module PayTrace
119
134
  # * *:expiration_month* -- the expiration month of the credit card
120
135
  # * *:expiration_year* -- the expiration year of the credit card
121
136
  def self.keyed_sale(params)
122
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
123
- params.merge({transaction_type: TransactionTypes::SALE}),
124
- KEYED_SALE_REQUEST_REQUIRED,
125
- KEYED_SALE_REQUEST_OPTIONAL)
137
+ send_transaction(params, TransactionTypes::SALE, KEYED_SALE_REQUEST_REQUIRED, KEYED_SALE_REQUEST_OPTIONAL)
126
138
  end
127
139
 
128
140
  # See http://help.paytrace.com/api-sale
@@ -134,10 +146,7 @@ module PayTrace
134
146
  # * *:amount* -- the amount of the transaction
135
147
  # * *:swipe* -- credit card swipe data (card swiped sales)
136
148
  def self.swiped_sale(params)
137
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
138
- params.merge({transaction_type: TransactionTypes::SALE}),
139
- SWIPED_SALE_REQUEST_REQUIRED,
140
- SWIPED_SALE_REQUEST_OPTIONAL)
149
+ send_transaction(params, TransactionTypes::SALE, SWIPED_SALE_REQUEST_REQUIRED, SWIPED_SALE_REQUEST_OPTIONAL)
141
150
  end
142
151
 
143
152
  # See http://help.paytrace.com/api-sale
@@ -177,10 +186,7 @@ module PayTrace
177
186
  # * *:custom_dba* -- optional value that is sent to the cardholder’s issuer and overrides the business name stored in PayTrace. Custom DBA values are only used with requests to process sales or authorizations through accounts on the TSYS/Vital, Heartland, and Trident networks (customer ID token sale)
178
187
  # * *:enable_partial_authentication* -- flag that must be set to ‘Y’ in order to support partial authorization and balance amounts in transaction responses (customer ID token sale)
179
188
  def self.customer_id_sale(params)
180
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
181
- params.merge({transaction_type: TransactionTypes::SALE}),
182
- CUSTID_SALE_REQUEST_REQUIRED,
183
- CUSTID_SALE_REQUEST_OPTIONAL)
189
+ send_transaction(params, TransactionTypes::SALE, CUSTID_SALE_REQUEST_REQUIRED, CUSTID_SALE_REQUEST_OPTIONAL)
184
190
  end
185
191
 
186
192
  # See http://help.paytrace.com/api-authorizations
@@ -194,9 +200,11 @@ module PayTrace
194
200
  # * *:expiration_month* -- the expiration month of the credit card
195
201
  # * *:expiration_year* -- the expiration year of the credit card
196
202
  def self.keyed_authorization(params)
197
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
198
- params.merge({transaction_type: TransactionTypes::Authorization}),
199
- [:transaction_type, :amount, :card_number, :expiration_month, :expiration_year])
203
+ send_transaction(
204
+ params,
205
+ TransactionTypes::Authorization,
206
+ [:transaction_type, :amount, :card_number, :expiration_month, :expiration_year],
207
+ [])
200
208
  end
201
209
 
202
210
  # See http://help.paytrace.com/api-authorizations
@@ -208,8 +216,7 @@ module PayTrace
208
216
  # * *:amount* -- the amount of the transaction
209
217
  # * *:customer_id* -- the customer ID to reference for this authorization
210
218
  def self.customer_id_authorization(params)
211
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
212
- params.merge({transaction_type: TransactionTypes::Authorization}), [:transaction_type, :amount, :customer_id])
219
+ send_transaction(params, TransactionTypes::Authorization, [:transaction_type, :amount, :customer_id], [])
213
220
  end
214
221
 
215
222
  # See http://help.paytrace.com/api-refunds
@@ -249,8 +256,7 @@ module PayTrace
249
256
  # * *:custom_dba* -- optional value that is sent to the cardholder’s issuer and overrides the business name stored in PayTrace. Custom DBA values are only used with requests to process sales or authorizations through accounts on the TSYS/Vital, Heartland, and Trident networks (customer ID token sale)
250
257
  # * *:enable_partial_authentication* -- flag that must be set to ‘Y’ in order to support partial authorization and balance amounts in transaction responses (customer ID token sale)
251
258
  def self.swiped_refund(params)
252
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
253
- params.merge({transaction_type: TransactionTypes::Refund}), [:transaction_type, :amount, :swipe], REFUND_OPTIONAL)
259
+ send_transaction(params, TransactionTypes::Refund, [:transaction_type, :amount, :swipe], REFUND_OPTIONAL)
254
260
  end
255
261
 
256
262
  # See http://help.paytrace.com/api-refunds
@@ -266,13 +272,11 @@ module PayTrace
266
272
  #
267
273
  # _Note:_ optional parameters are identical to those for swiped_refund
268
274
  def self.keyed_refund(params)
269
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
270
- params.merge({transaction_type: TransactionTypes::Refund}), [
271
- :transaction_type,
272
- :amount,
273
- :card_number,
274
- :expiration_month,
275
- :expiration_year], REFUND_OPTIONAL)
275
+ send_transaction(
276
+ params,
277
+ TransactionTypes::Refund,
278
+ [:transaction_type, :amount, :card_number, :expiration_month, :expiration_year],
279
+ REFUND_OPTIONAL)
276
280
  end
277
281
 
278
282
 
@@ -287,8 +291,11 @@ module PayTrace
287
291
  #
288
292
  # _Note:_ optional parameters are identical to those for swiped_refund
289
293
  def self.customer_id_refund(params)
290
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
291
- params.merge({transaction_type: TransactionTypes::Refund}), [:transaction_type, :amount, :customer_id], REFUND_OPTIONAL)
294
+ send_transaction(
295
+ params,
296
+ TransactionTypes::Refund,
297
+ [:transaction_type, :amount, :customer_id],
298
+ REFUND_OPTIONAL)
292
299
  end
293
300
 
294
301
 
@@ -303,8 +310,11 @@ module PayTrace
303
310
  #
304
311
  # _Note:_ optional parameters are identical to those for swiped_refund
305
312
  def self.transaction_id_refund(params)
306
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
307
- params.merge({transaction_type: TransactionTypes::Refund}), [:transaction_type, :transaction_id], REFUND_OPTIONAL)
313
+ send_transaction(
314
+ params,
315
+ TransactionTypes::Refund,
316
+ [:transaction_type, :transaction_id],
317
+ REFUND_OPTIONAL)
308
318
  end
309
319
 
310
320
  # See http://help.paytrace.com/api-void
@@ -315,8 +325,7 @@ module PayTrace
315
325
  #
316
326
  # * *:transaction_id* -- the transaction ID to void
317
327
  def self.void(params)
318
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
319
- params.merge({transaction_type: TransactionTypes::Void}), [:transaction_type, :transaction_id])
328
+ send_transaction(params, TransactionTypes::Void, [:transaction_type, :transaction_id], [])
320
329
  end
321
330
 
322
331
  # See http://help.paytrace.com/api-forced-sale
@@ -329,8 +338,10 @@ module PayTrace
329
338
  # * *:swipe* -- credit card swipe data (card swiped sales)
330
339
  # * *:approval_code* -- the approval code obtained external to the PayTrace system
331
340
  def self.swiped_forced_sale(params)
332
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
333
- params.merge({transaction_type: TransactionTypes::ForcedSale}), [:transaction_type, :amount, :swipe, :approval_code],
341
+ send_transaction(
342
+ params,
343
+ TransactionTypes::ForcedSale,
344
+ [:transaction_type, :amount, :swipe, :approval_code],
334
345
  ADDRESSES_AND_EXTRA)
335
346
  end
336
347
 
@@ -346,8 +357,10 @@ module PayTrace
346
357
  # * *:expiration_year* -- the expiration year of the credit card
347
358
  # * *:approval_code* -- the approval code obtained external to the PayTrace system
348
359
  def self.keyed_forced_sale(params)
349
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
350
- params.merge({transaction_type: TransactionTypes::ForcedSale}), [:transaction_type, :amount, :card_number, :expiration_month, :expiration_year, :approval_code],
360
+ send_transaction(
361
+ params,
362
+ TransactionTypes::ForcedSale,
363
+ [:transaction_type, :amount, :card_number, :expiration_month, :expiration_year, :approval_code],
351
364
  ADDRESSES_AND_EXTRA)
352
365
  end
353
366
 
@@ -361,8 +374,10 @@ module PayTrace
361
374
  # * *:customer_id -- the customer ID for the forced sale
362
375
  # * *:approval_code* -- the approval code obtained external to the PayTrace system
363
376
  def self.customer_id_forced_sale(params)
364
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
365
- params.merge({transaction_type: TransactionTypes::ForcedSale}), [:transaction_type, :amount, :customer_id, :approval_code],
377
+ send_transaction(
378
+ params,
379
+ TransactionTypes::ForcedSale,
380
+ [:transaction_type, :amount, :customer_id, :approval_code],
366
381
  ADDRESSES_AND_EXTRA)
367
382
  end
368
383
 
@@ -376,8 +391,10 @@ module PayTrace
376
391
  # * *:transaction_id -- the transaction ID for the forced sale
377
392
  # * *:approval_code* -- the approval code obtained external to the PayTrace system
378
393
  def self.transaction_id_forced_sale(params)
379
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
380
- params.merge({transaction_type: TransactionTypes::ForcedSale}), [:transaction_type, :transaction_id, :approval_code],
394
+ send_transaction(
395
+ params,
396
+ TransactionTypes::ForcedSale,
397
+ [:transaction_type, :transaction_id, :approval_code],
381
398
  ADDRESSES_AND_EXTRA)
382
399
  end
383
400
 
@@ -389,8 +406,11 @@ module PayTrace
389
406
  #
390
407
  # * *transaction_id* -- the transaction ID to be captured
391
408
  def self.capture(params)
392
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
393
- params.merge({transaction_type: TransactionTypes::Capture}), [:transaction_type, :transaction_id])
409
+ send_transaction(
410
+ params,
411
+ TransactionTypes::Capture,
412
+ [:transaction_type, :transaction_id],
413
+ [])
394
414
  end
395
415
 
396
416
  # See http://help.paytrace.com/api-cash-advance
@@ -426,21 +446,11 @@ module PayTrace
426
446
  # * *:tax_amount* -- the amount of tax on the sale (customer ID token or referenced transaction sale)
427
447
  # * *:customer_reference_id* -- a customer reference ID (customer ID token or referenced transaction sale)
428
448
  def self.swiped_cash_advance(params)
429
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
430
- params.merge({transaction_type: TransactionTypes::SALE, cash_advance: 'Y'}), [
431
- :transaction_type,
432
- :amount,
433
- :swipe,
434
- :cash_advance,
435
- :id_number,
436
- :id_expiration,
437
- :cc_last_4,
438
- :billing_name,
439
- :billing_address,
440
- :billing_address2,
441
- :billing_city,
442
- :billing_state,
443
- :billing_postal_code], CASH_ADVANCE_OPTIONAL)
449
+ send_transaction(
450
+ {cash_advance: 'Y'}.merge(params),
451
+ TransactionTypes::SALE,
452
+ CASH_ADVANCE_REQUIRED + [:swipe],
453
+ CASH_ADVANCE_OPTIONAL)
444
454
  end
445
455
 
446
456
  # See http://help.paytrace.com/api-cash-advance
@@ -478,23 +488,11 @@ module PayTrace
478
488
  # * *:tax_amount* -- the amount of tax on the sale (customer ID token or referenced transaction sale)
479
489
  # * *:customer_reference_id* -- a customer reference ID (customer ID token or referenced transaction sale)
480
490
  def self.keyed_cash_advance(params)
481
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
482
- params.merge({transaction_type: TransactionTypes::SALE, cash_advance: 'Y'}), [
483
- :transaction_type,
484
- :amount,
485
- :card_number,
486
- :expiration_month,
487
- :expiration_year,
488
- :cash_advance,
489
- :id_number,
490
- :id_expiration,
491
- :cc_last_4,
492
- :billing_name,
493
- :billing_address,
494
- :billing_address2,
495
- :billing_city,
496
- :billing_state,
497
- :billing_postal_code], CASH_ADVANCE_OPTIONAL)
491
+ send_transaction(
492
+ {cash_advance: 'Y'}.merge(params),
493
+ TransactionTypes::SALE,
494
+ CASH_ADVANCE_REQUIRED + [:card_number, :expiration_month, :expiration_year],
495
+ CASH_ADVANCE_OPTIONAL)
498
496
  end
499
497
 
500
498
  # See http://help.paytrace.com/api-store-and-forward
@@ -535,8 +533,7 @@ module PayTrace
535
533
  # * *:enable_partial_authentication* -- flag that must be set to ‘Y’ in order to support partial authorization and balance amounts in transaction responses (customer ID token sale)
536
534
  # * *:store_forward_date* -- optional future date when the transaction should be authorized and settled. Only applicable if the TranxType is STR/FWD
537
535
  def self.swiped_store_forward(params)
538
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
539
- params.merge({transaction_type: TransactionTypes::StoreForward}), [:transaction_type, :amount, :swipe], STORE_AND_FORWARD_OPTIONAL)
536
+ send_transaction(params, TransactionTypes::StoreForward, [:transaction_type, :amount, :swipe], STORE_AND_FORWARD_OPTIONAL)
540
537
  end
541
538
 
542
539
  # See http://help.paytrace.com/api-store-and-forward
@@ -579,8 +576,11 @@ module PayTrace
579
576
  # * *:enable_partial_authentication* -- flag that must be set to ‘Y’ in order to support partial authorization and balance amounts in transaction responses (customer ID token sale)
580
577
  # * *:store_forward_date* -- optional future date when the transaction should be authorized and settled. Only applicable if the TranxType is STR/FWD
581
578
  def self.keyed_store_forward(params)
582
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
583
- params.merge({transaction_type: TransactionTypes::StoreForward}), [:transaction_type, :amount, :card_number, :expiration_month, :expiration_year], STORE_AND_FORWARD_OPTIONAL)
579
+ send_transaction(
580
+ params,
581
+ TransactionTypes::StoreForward,
582
+ [:transaction_type, :amount, :card_number, :expiration_month, :expiration_year],
583
+ STORE_AND_FORWARD_OPTIONAL)
584
584
  end
585
585
 
586
586
  # See http://help.paytrace.com/api-store-and-forward
@@ -621,8 +621,11 @@ module PayTrace
621
621
  # * *:enable_partial_authentication* -- flag that must be set to ‘Y’ in order to support partial authorization and balance amounts in transaction responses (customer ID token sale)
622
622
  # * *:store_forward_date* -- optional future date when the transaction should be authorized and settled. Only applicable if the TranxType is STR/FWD
623
623
  def self.customer_id_store_forward(params)
624
- PayTrace::API::Gateway.send_request(TRANSACTION_METHOD,
625
- params.merge({transaction_type: TransactionTypes::StoreForward}), [:transaction_type, :amount, :customer_id], STORE_AND_FORWARD_OPTIONAL)
624
+ send_transaction(
625
+ params,
626
+ TransactionTypes::StoreForward,
627
+ [:transaction_type, :amount, :customer_id],
628
+ STORE_AND_FORWARD_OPTIONAL)
626
629
  end
627
630
 
628
631
  # See http://help.paytrace.com/api-export-transaction-information
@@ -936,6 +939,17 @@ module PayTrace
936
939
  def self.adjust_amount(params = {})
937
940
  PayTrace::API::Gateway.send_request(ADJUST_AMOUNT_METHOD, params, [:transaction_id, :amount])
938
941
  end
942
+
943
+ # private helper method to DRY things up a bit
944
+ def self.send_transaction(params, type, required, optional)
945
+ PayTrace::API::Gateway.send_request(
946
+ TRANSACTION_METHOD,
947
+ {transaction_type: type}.merge(params),
948
+ required,
949
+ optional)
950
+ end
951
+
952
+ private_class_method :send_transaction
939
953
  end
940
954
 
941
955
  # enumeration of transaction subtypes
@@ -1,4 +1,4 @@
1
1
  module PayTrace
2
2
  # Version number
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
@@ -1,3 +1,15 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '../../test_helper.rb')
2
2
 
3
- include PayTrace::Exceptions
3
+ include PayTrace::Exceptions
4
+
5
+ describe PayTrace::Exceptions do
6
+ describe PayTrace::Exceptions::ErrorResponse do
7
+ it "shows the error code in to_s" do
8
+ raw = "ERROR~779. BLOCKED - This card number has been blocked to prevent potential fraud.|"
9
+ response = PayTrace::API::Response.new(raw)
10
+ exception = PayTrace::Exceptions::ErrorResponse.new(response)
11
+
12
+ exception.to_s.must_equal response.get_response()
13
+ end
14
+ end
15
+ end
@@ -6,14 +6,7 @@ require "paytrace/debug"
6
6
  # change this as needed to reflect the username, password, and test host you're testing against
7
7
  PayTrace::Debug.configure_test("demo123", "demo123", "stage.paytrace.com")
8
8
 
9
- # settle a transaction via a recurrence ID
10
- PayTrace::Debug.trace do
11
- params = { recur_id: "1143" } # you must replace this with a valid recurrence ID!
12
- PayTrace::Transaction.settle_transactions(params)
13
- end
14
-
15
9
  # settle a transaction via a customer ID
16
10
  PayTrace::Debug.trace do
17
- params = { customer_id: "1143" } # you must replace this with a valid customer ID!
18
- PayTrace::Transaction.settle_transactions(params)
11
+ PayTrace::Transaction.settle_transactions()
19
12
  end
@@ -0,0 +1,137 @@
1
+ $:<< "./lib" # uncomment this to run against a Git clone instead of an installed gem
2
+
3
+ require "paytrace"
4
+ require "paytrace/debug"
5
+
6
+ # change this as needed to reflect the username, password, and test host you're testing against
7
+ PayTrace.configure do |config|
8
+ config.user_name = "demo123"
9
+ config.password = "demo123"
10
+ config.domain = "stage.paytrace.com"
11
+ end
12
+
13
+ #
14
+ # Create a customer profile with a known customer ID
15
+ #
16
+
17
+ # we can handle non-fatal error responses by rescuing PayTrace::Exception::ErrorResponse objects
18
+ begin
19
+ # note that most of these parameters are optional; you do not need to include every param to make the call
20
+ # see the SDK documentation for a list of optional and required parameters for each function
21
+ params = {
22
+ customer_id: 'fake_user',
23
+ card_number: 4111111111111111,
24
+ expiration_month: 10,
25
+ expiration_year: 24,
26
+ billing_name: 'John Doe',
27
+ billing_address: '1234 Fake Lane.',
28
+ billing_address2: 'Suite 214',
29
+ billing_city: 'Shoreline',
30
+ billing_state: 'WA',
31
+ billing_postal_code: 98133,
32
+ shipping_name: 'John Doe',
33
+ billing_country: 'US',
34
+ shipping_address: '3456 Business Road',
35
+ shipping_address2: 'Apartment D',
36
+ shipping_city: 'Seattle',
37
+ shipping_region: 'King',
38
+ shipping_state: 'WA',
39
+ shipping_postal_code: 98134,
40
+ shipping_country: 'US',
41
+ email: 'support@paytrace.com',
42
+ customer_phone: '206-555-1212',
43
+ customer_fax: '206-555-1213',
44
+ customer_password: 'foobar',
45
+ account_number: 12345678,
46
+ routing_number: 325081403,
47
+ discretionary_data: {hair_color: 'red'} # note, this is level 3 ("discretionary") data appropriate to your account!
48
+ }
49
+
50
+ # here we create a new customer profile, using the credit card number variant
51
+ PayTrace::Customer.from_cc_info(params)
52
+ rescue PayTrace::Exceptions::ErrorResponse => e
53
+ if e.response.errors.count == 1 && e.response.errors.has_key?('ERROR-171') # duplicate customer ID
54
+ puts "*** Customer ID #{params[:customer_id]} already exists, continuing..."
55
+ else
56
+ raise
57
+ end
58
+ else
59
+ puts "*** Successfully created customer ID #{params[:customer_id]}"
60
+ end
61
+
62
+ #
63
+ # Perform a keyed (manually-entered, as opposed to swiped) sale transaction
64
+ #
65
+
66
+ params = {
67
+ # a "sandbox" credit card number
68
+ card_number: 4111111111111111,
69
+ amount: 15.99,
70
+ expiration_month: 10,
71
+ expiration_year: 24
72
+ }
73
+
74
+ response = PayTrace::Transaction::keyed_sale(params)
75
+
76
+ # pull the data we care about out
77
+ transaction_id = response.values["TRANSACTIONID"]
78
+
79
+ puts "*** Successfully created transaction ID #{transaction_id}"
80
+
81
+ #
82
+ # Add level 3 data to a known transaction ID
83
+ #
84
+
85
+ # let's add level 3 data to that transaction...
86
+ params = {
87
+ transaction_id: transaction_id,
88
+ line_items: [
89
+ {product_id: 'SKU123', quantity: 3, description: 'Widgets'}
90
+ ]
91
+ }
92
+
93
+ PayTrace::Transaction::add_level_three_visa(params)
94
+
95
+ puts "*** Successfully added level 3 data to transaction_id #{transaction_id}"
96
+
97
+ #
98
+ # Void a known transaction ID
99
+ #
100
+
101
+ # void it!
102
+ params = {
103
+ # the transaction ID we received above...
104
+ transaction_id: transaction_id
105
+ }
106
+
107
+ # and now we refund that same transaction
108
+ response = PayTrace::Transaction::void(params)
109
+
110
+ puts "*** Successfully voided transaction_id #{transaction_id}"
111
+
112
+ #
113
+ # Perform a refund to a known credit card
114
+ #
115
+
116
+ # now, let's do a refund!
117
+ params = {
118
+ amount: 15.99,
119
+ card_number: 4111111111111111,
120
+ expiration_month: 10,
121
+ expiration_year: 24
122
+ }
123
+
124
+ # this might fail if you run against the staging server
125
+ # But, it demonstrates the minimal information necessary to perform a keyed refund.
126
+ PayTrace::Transaction::keyed_refund(params)
127
+
128
+ puts "*** Successfully refunded $#{params[:amount]} to card number #{params[:card_number]}"
129
+
130
+ #
131
+ # Delete customer profile
132
+ #
133
+
134
+ # we know the customer id, so we can delete the profile.
135
+ PayTrace::Customer.delete('fake_user')
136
+
137
+ puts "*** Successfully deleted customer ID fake_user"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paytrace
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Redfern
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-13 00:00:00.000000000 Z
11
+ date: 2014-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -183,6 +183,7 @@ files:
183
183
  - test/scripts/run_level3_data.rb
184
184
  - test/scripts/run_recur_payments_integration.rb
185
185
  - test/scripts/run_settle_transaction.rb
186
+ - test/scripts/sample_transaction.rb
186
187
  - test/scripts/smiley_face.png
187
188
  - test/test_helper.rb
188
189
  - vagrant-bootstrap.sh
@@ -238,5 +239,6 @@ test_files:
238
239
  - test/scripts/run_level3_data.rb
239
240
  - test/scripts/run_recur_payments_integration.rb
240
241
  - test/scripts/run_settle_transaction.rb
242
+ - test/scripts/sample_transaction.rb
241
243
  - test/scripts/smiley_face.png
242
244
  - test/test_helper.rb