hps 1.0.2 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -8
  3. data/LICENSE.txt +32 -32
  4. data/PRIVACY.txt +65 -65
  5. data/README.md +214 -41
  6. data/Rakefile +15 -15
  7. data/hps.gemspec +28 -26
  8. data/lib/hps.rb +48 -45
  9. data/lib/hps/configuration.rb +16 -16
  10. data/lib/hps/entities/hps_account_verify.rb +8 -8
  11. data/lib/hps/entities/hps_address.rb +6 -6
  12. data/lib/hps/entities/hps_authorization.rb +12 -12
  13. data/lib/hps/entities/hps_batch.rb +6 -6
  14. data/lib/hps/entities/hps_cardholder.rb +6 -10
  15. data/lib/hps/entities/hps_charge.rb +8 -8
  16. data/lib/hps/entities/hps_charge_exceptions.rb +6 -6
  17. data/lib/hps/entities/hps_credit_card.rb +34 -33
  18. data/lib/hps/entities/hps_direct_market_data.rb +5 -0
  19. data/lib/hps/entities/hps_encryption_data.rb +6 -0
  20. data/lib/hps/entities/hps_refund.rb +8 -8
  21. data/lib/hps/entities/hps_report_transaction_details.rb +10 -10
  22. data/lib/hps/entities/hps_report_transaction_summary.rb +6 -6
  23. data/lib/hps/entities/hps_reversal.rb +10 -10
  24. data/lib/hps/entities/hps_token_data.rb +10 -10
  25. data/lib/hps/entities/hps_track_data.rb +5 -0
  26. data/lib/hps/entities/hps_transaction.rb +161 -161
  27. data/lib/hps/entities/hps_transaction_details.rb +6 -6
  28. data/lib/hps/entities/hps_transaction_header.rb +8 -8
  29. data/lib/hps/entities/hps_transaction_type.rb +16 -16
  30. data/lib/hps/entities/hps_void.rb +8 -8
  31. data/lib/hps/infrastructure/api_connection_exception.rb +11 -11
  32. data/lib/hps/infrastructure/authentication_exception.rb +11 -11
  33. data/lib/hps/infrastructure/card_exception.rb +15 -15
  34. data/lib/hps/infrastructure/exceptions.json +468 -468
  35. data/lib/hps/infrastructure/hps_exception.rb +25 -25
  36. data/lib/hps/infrastructure/hps_exception_mapper.rb +134 -134
  37. data/lib/hps/infrastructure/hps_sdk_codes.rb +48 -48
  38. data/lib/hps/infrastructure/hps_track_data_method.rb +6 -0
  39. data/lib/hps/infrastructure/invalid_request_exception.rb +15 -15
  40. data/lib/hps/services/hps_batch_service.rb +29 -29
  41. data/lib/hps/services/hps_charge_service.rb +735 -635
  42. data/lib/hps/services/hps_service.rb +127 -128
  43. data/lib/hps/version.rb +3 -3
  44. data/tests/amex_tests.rb +292 -231
  45. data/tests/cert_tests.rb +80 -80
  46. data/tests/certification/card_present_spec.rb +320 -0
  47. data/tests/discover_tests.rb +386 -325
  48. data/tests/exception_mapper_tests.rb +244 -244
  49. data/tests/general_tests.rb +65 -57
  50. data/tests/hps_token_service.rb +56 -56
  51. data/tests/mastercard_tests.rb +387 -326
  52. data/tests/secret_key.rb +11 -11
  53. data/tests/test_data.rb +128 -128
  54. data/tests/test_helper.rb +115 -108
  55. data/tests/token_tests.rb +512 -512
  56. data/tests/visa_tests.rb +445 -378
  57. metadata +36 -3
@@ -1,30 +1,30 @@
1
- module Hps
2
- class HpsBatchService < HpsService
3
-
4
- def close_batch()
5
-
6
- xml = Builder::XmlMarkup.new
7
-
8
- xml.hps :Transaction do
9
- xml.hps :BatchClose, "BatchClose"
10
- end
11
-
12
- response = doTransaction(xml.target!)
13
- header = response["Header"]
14
-
15
- unless header["GatewayRspCode"].eql? "0"
16
- raise @exception_mapper.map_gateway_exception(header["GatewayTxnId"], header["GatewayRspCode"], header["GatewayRspMsg"])
17
- end
18
-
19
- batch_close = response["Transaction"]["BatchClose"]
20
- result = HpsBatch.new()
21
- result.id = batch_close["BatchId"]
22
- result.sequence_number = batch_close["BatchSeqNbr"]
23
- result.total_amount = batch_close["TotalAmt"]
24
- result.transaction_count = batch_close["TxnCnt"]
25
-
26
- result
27
- end
28
-
29
- end
1
+ module Hps
2
+ class HpsBatchService < HpsService
3
+
4
+ def close_batch()
5
+
6
+ xml = Builder::XmlMarkup.new
7
+
8
+ xml.hps :Transaction do
9
+ xml.hps :BatchClose, "BatchClose"
10
+ end
11
+
12
+ response = doTransaction(xml.target!)
13
+ header = response["Header"]
14
+
15
+ unless header["GatewayRspCode"].eql? "0"
16
+ raise @exception_mapper.map_gateway_exception(header["GatewayTxnId"], header["GatewayRspCode"], header["GatewayRspMsg"])
17
+ end
18
+
19
+ batch_close = response["Transaction"]["BatchClose"]
20
+ result = HpsBatch.new()
21
+ result.id = batch_close["BatchId"]
22
+ result.sequence_number = batch_close["BatchSeqNbr"]
23
+ result.total_amount = batch_close["TotalAmt"]
24
+ result.transaction_count = batch_close["TxnCnt"]
25
+
26
+ result
27
+ end
28
+
29
+ end
30
30
  end
@@ -1,635 +1,735 @@
1
- module Hps
2
- class HpsChargeService < HpsService
3
-
4
- def get(transaction_id)
5
-
6
- if transaction_id.nil? or transaction_id == 0
7
- raise @exception_mapper.map_sdk_exception(SdkCodes.invalid_transaction_id)
8
- end
9
-
10
- xml = Builder::XmlMarkup.new
11
- xml.hps :Transaction do
12
- xml.hps :ReportTxnDetail do
13
- xml.hps :TxnId, transaction_id
14
- end
15
- end
16
-
17
- response = doTransaction(xml.target!)
18
- detail = response["Transaction"]["ReportTxnDetail"]
19
-
20
- header = hydrate_transaction_header(response["Header"])
21
- result = HpsReportTransactionDetails.new(header)
22
- result.transaction_id = detail["GatewayTxnId"]
23
- result.original_transaction_id = detail["OriginalGatewayTxnId"]
24
- result.authorized_amount = detail["Data"]["AuthAmt"]
25
- result.authorization_code = detail["Data"]["AuthCode"]
26
- result.avs_result_code = detail["Data"]["AVSRsltCode"]
27
- result.avs_result_text = detail["Data"]["AVSRsltText"]
28
- result.card_type = detail["Data"]["CardType"]
29
- result.masked_card_number = detail["Data"]["MaskedCardNbr"]
30
- result.transaction_type = Hps.service_name_to_transaction_type(detail["ServiceName"])
31
- result.transaction_date = detail["RspUtcDT"]
32
- result.cpc_indicator = detail["Data"]["CPCInd"]
33
- result.cvv_result_code = detail["Data"]["CVVRsltCode"]
34
- result.cvv_result_text = detail["Data"]["CVVRsltText"]
35
- result.reference_number = detail["Data"]["RefNbr"]
36
- result.response_code = detail["Data"]["RspCode"]
37
- result.response_text = detail["Data"]["RspText"]
38
-
39
- tokenization_message = detail["Data"]["TokenizationMsg"]
40
-
41
- unless tokenization_message.nil?
42
- result.token_data = HpsTokenData.new(tokenization_message)
43
- end
44
-
45
- header_response_code = response["Header"]["GatewayRspCode"]
46
- data_response_code = detail["Data"]["RspCode"]
47
-
48
- if header_response_code != "0" or data_response_code != "00"
49
-
50
- exceptions = HpsChargeExceptions.new()
51
-
52
- if header_response_code != "0"
53
- message = response["Header"]["GatewayRspMsg"]
54
- exceptions.hps_exception = @exception_mapper.map_gateway_exception(result.transaction_id, header_response_code, message)
55
- end
56
-
57
- if data_response_code != "0"
58
- message = detail["Data"]["RspText"]
59
- exceptions.card_exception = @exception_mapper.map_issuer_exception(transaction_id, data_response_code, message)
60
- end
61
-
62
- result.exceptions = exceptions
63
-
64
- end
65
-
66
- result
67
-
68
- end
69
-
70
- def list(start_date, end_date, filter_by = nil)
71
-
72
- if start_date > DateTime.now
73
- raise @exception_mapper.map_sdk_exception(SdkCodes.invalid_start_date)
74
- elsif end_date > DateTime.now
75
- raise @exception_mapper.map_sdk_exception(SdkCodes.invalid_end_date)
76
- end
77
-
78
- xml = Builder::XmlMarkup.new
79
- xml.hps :Transaction do
80
- xml.hps :ReportActivity do
81
- xml.hps :RptStartUtcDT, start_date.utc.iso8601
82
- xml.hps :RptEndUtcDT, end_date.utc.iso8601
83
- end
84
- end
85
-
86
- response = doTransaction(xml.target!)
87
-
88
- # Gateway exception
89
- if response["Header"]["GatewayRspCode"] != "0"
90
- transaction_id = response["Header"]["GatewayTxnId"]
91
- response_code = response["Header"]["GatewayRspCode"]
92
- response_message = response["Header"]["GatewayRspMsg"]
93
- raise @exception_mapper.map_gateway_exception(transaction_id, response_code, response_message)
94
- end
95
-
96
- result = Array.new
97
-
98
- if response["Transaction"]["ReportActivity"]["Header"]["TxnCnt"] == "0"
99
- return result
100
- end
101
-
102
- response["Transaction"]["ReportActivity"]["Details"].each { |charge|
103
-
104
- next if !filter_by.nil? and charge.serviceName != Hps.transaction_type_to_service_name(filter_by)
105
-
106
- summary = HpsReportTransactionSummary.new()
107
- summary.transaction_id = charge["GatewayTxnId"]
108
- summary.original_transaction_id = charge["OriginalGatewayTxnId"]
109
- summary.masked_card_number = charge["MaskedCardNbr"]
110
- summary.response_code = charge["IssuerRspCode"]
111
- summary.response_text = charge["IssuerRspText"]
112
- summary.transaction_type = Hps.transaction_type_to_service_name(charge["ServiceName"]) if filter_by.nil? == false
113
-
114
- gw_response_code = charge["GatewayRspCode"]
115
- issuer_response_code = charge["IssuerRspCode"]
116
-
117
- if gw_response_code != "0" or issuer_response_code != "00"
118
-
119
- exceptions = HpsChargeExceptions.new()
120
-
121
- if gw_response_code != "0"
122
- message = charge["GatewayRspMsg"]
123
- exceptions.hps_exception = @exception_mapper.map_gateway_exception(charge["GatewayTxnId"], gw_response_code, message)
124
- end
125
-
126
- if issuer_response_code != "0"
127
- message = charge["IssuerRspText"]
128
- exceptions.card_exception = @exception_mapper.map_issuer_exception(charge["GatewayTxnId"], issuer_response_code, message)
129
- end
130
-
131
- summary.exceptions = exceptions
132
-
133
- end
134
-
135
- result << summary
136
- }
137
-
138
- result
139
- end
140
-
141
- def charge(amount, currency, card, card_holder = nil, request_multi_use_token = false, details = nil)
142
- check_amount(amount)
143
- check_currency(currency)
144
-
145
- xml = Builder::XmlMarkup.new
146
- xml.hps :Transaction do
147
- xml.hps :CreditSale do
148
- xml.hps :Block1 do
149
- xml.hps :AllowDup, "Y"
150
- xml.hps :Amt, amount
151
- xml << hydrate_cardholder_data(card_holder) if card_holder
152
- xml << hydrate_additional_txn_fields(details) if details
153
- xml.hps :CardData do
154
-
155
- # NOTE: Process as Manual Entry if they gave us a Credit Card
156
- if card.is_a? HpsCreditCard
157
- xml << hydrate_manual_entry(card)
158
- # Note: Otherwise, consider it a token
159
- else
160
- xml.hps :TokenData do
161
- xml.hps :TokenValue, card
162
- end
163
- end
164
-
165
- xml.hps :TokenRequest, request_multi_use_token ? "Y" : "N"
166
-
167
- end
168
- end
169
- end
170
- end
171
-
172
- submit_charge(xml.target!, amount, currency)
173
- end
174
-
175
- def verify(card, card_holder = nil, request_multi_use_token = false)
176
-
177
- xml = Builder::XmlMarkup.new
178
- xml.hps :Transaction do
179
- xml.hps :CreditAccountVerify do
180
- xml.hps :Block1 do
181
- xml << hydrate_cardholder_data(card_holder) if card_holder
182
- xml.hps :CardData do
183
-
184
- # NOTE: Process as Manual Entry if they gave us a Credit Card
185
- if card.is_a? HpsCreditCard
186
- xml << hydrate_manual_entry(card)
187
- # Note: Otherwise, consider it a token
188
- else
189
- xml.hps :TokenData do
190
- xml.hps :TokenValue, card
191
- end
192
- end
193
-
194
- xml.hps :TokenRequest, request_multi_use_token ? "Y" : "N"
195
-
196
- end
197
- end
198
- end
199
- end
200
-
201
- submit_verify(xml.target!)
202
- end
203
-
204
- def authorize(amount, currency, card, card_holder = nil, request_multi_use_token = false, details = nil)
205
-
206
- check_amount(amount)
207
- check_currency(currency)
208
-
209
- xml = Builder::XmlMarkup.new
210
- xml.hps :Transaction do
211
- xml.hps :CreditAuth do
212
- xml.hps :Block1 do
213
- xml.hps :AllowDup, "Y"
214
- xml.hps :Amt, amount
215
- xml << hydrate_cardholder_data(card_holder) if card_holder
216
- xml << hydrate_additional_txn_fields(details) if details
217
- xml.hps :CardData do
218
-
219
- # NOTE: Process as Manual Entry if they gave us a Credit Card
220
- if card.is_a? HpsCreditCard
221
- xml << hydrate_manual_entry(card)
222
- # Note: Otherwise, consider it a token
223
- else
224
- xml.hps :TokenData do
225
- xml.hps :TokenValue, card
226
- end
227
- end
228
-
229
- xml.hps :TokenRequest, request_multi_use_token ? "Y" : "N"
230
-
231
- end
232
- end
233
- end
234
- end
235
-
236
- submit_authorize(xml.target!, amount, currency)
237
- end
238
-
239
- def capture(transaction_id, amount = nil)
240
-
241
- xml = Builder::XmlMarkup.new
242
- xml.hps :Transaction do
243
- xml.hps :CreditAddToBatch do
244
- xml.hps :GatewayTxnId, transaction_id
245
- xml.hps :Amt, amount if amount
246
- end
247
- end
248
-
249
- response = doTransaction(xml.target!)
250
- header = response["Header"]
251
-
252
- raise @exception_mapper.map_gateway_exception(transaction_id, header["GatewayRspCode"], header["GatewayRspMsg"]) unless header["GatewayRspCode"].eql? "0"
253
-
254
- get(transaction_id)
255
- end
256
-
257
- def reverse(card, amount, currency, details = nil)
258
- check_amount(amount)
259
- check_currency(currency)
260
-
261
- xml = Builder::XmlMarkup.new
262
- xml.hps :Transaction do
263
- xml.hps :CreditReversal do
264
- xml.hps :Block1 do
265
- xml.hps :Amt, amount
266
- xml << hydrate_additional_txn_fields(details) if details
267
- xml.hps :CardData do
268
-
269
- # NOTE: Process as Manual Entry if they gave us a Credit Card
270
- if card.is_a? HpsCreditCard
271
- xml << hydrate_manual_entry(card)
272
- # Note: Otherwise, consider it a token
273
- else
274
- xml.hps :TokenData do
275
- xml.hps :TokenValue, card
276
- end
277
- end
278
-
279
- end
280
- end
281
- end
282
- end
283
-
284
- submit_reverse(xml.target!)
285
- end
286
-
287
- def reverse_transaction(transaction_id, amount, currency, details = nil)
288
- check_amount(amount)
289
- check_currency(currency)
290
-
291
- xml = Builder::XmlMarkup.new
292
- xml.hps :Transaction do
293
- xml.hps :CreditReversal do
294
- xml.hps :Block1 do
295
- xml.hps :Amt, amount
296
- xml.hps :GatewayTxnId, transaction_id
297
- xml << hydrate_additional_txn_fields(details) if details
298
- end
299
- end
300
- end
301
-
302
- submit_reverse(xml.target!)
303
- end
304
-
305
- def refund(amount, currency, card, card_holder = nil, details = nil)
306
- check_amount(amount)
307
- check_currency(currency)
308
-
309
- xml = Builder::XmlMarkup.new
310
- xml.hps :Transaction do
311
- xml.hps :CreditReturn do
312
- xml.hps :Block1 do
313
- xml.hps :AllowDup, "Y"
314
- xml.hps :Amt, amount
315
- xml << hydrate_cardholder_data(card_holder) if card_holder
316
- xml << hydrate_additional_txn_fields(details) if details
317
- xml.hps :CardData do
318
-
319
- # NOTE: Process as Manual Entry if they gave us a Credit Card
320
- if card.is_a? HpsCreditCard
321
- xml << hydrate_manual_entry(card)
322
- # Note: Otherwise, consider it a token
323
- else
324
- xml.hps :TokenData do
325
- xml.hps :TokenValue, card
326
- end
327
- end
328
-
329
- end
330
- end
331
- end
332
- end
333
-
334
- submit_refund(xml.target!)
335
- end
336
-
337
- def refund_transaction(amount, currency, transaction_id, card_holder = nil, details = nil)
338
- check_amount(amount)
339
- check_currency(currency)
340
-
341
- xml = Builder::XmlMarkup.new
342
- xml.hps :Transaction do
343
- xml.hps :CreditReturn do
344
- xml.hps :Block1 do
345
- xml.hps :AllowDup, "Y"
346
- xml.hps :Amt, amount
347
- xml.hps :GatewayTxnId, transaction_id
348
- xml << hydrate_cardholder_data(card_holder) if card_holder
349
- xml << hydrate_additional_txn_fields(details) if details
350
- end
351
- end
352
- end
353
-
354
- submit_refund(xml.target!)
355
- end
356
-
357
- def void(transaction_id)
358
- xml = Builder::XmlMarkup.new
359
- xml.hps :Transaction do
360
- xml.hps :CreditVoid do
361
- xml.hps :GatewayTxnId, transaction_id
362
- end
363
- end
364
-
365
- submit_void(xml.target!)
366
- end
367
- private
368
-
369
- def check_amount(amount)
370
- raise @exception_mapper.map_sdk_exception(SdkCodes.invalid_amount) if amount.nil? or amount <= 0
371
- end
372
-
373
- def check_currency(currency)
374
- raise @exception_mapper.map_sdk_exception(SdkCodes.missing_currency) if currency.empty?
375
- raise @exception_mapper.map_sdk_exception(SdkCodes.invalid_currency) unless currency.downcase.eql? "usd"
376
- end
377
-
378
- def hydrate_cardholder_data(card_holder)
379
- xml = Builder::XmlMarkup.new
380
- xml.hps :CardHolderData do
381
- xml.hps :CardHolderFirstName, card_holder.first_name
382
- xml.hps :CardHolderLastName, card_holder.last_name
383
- xml.hps :CardHolderEmail, card_holder.email_address
384
- xml.hps :CardHolderPhone, card_holder.phone
385
- xml.hps :CardHolderAddr, card_holder.address.address
386
- xml.hps :CardHolderCity, card_holder.address.city
387
- xml.hps :CardHolderState, card_holder.address.state
388
- xml.hps :CardHolderZip, card_holder.address.zip
389
- end
390
- xml.target!
391
- end
392
-
393
- def hydrate_manual_entry(card)
394
- xml = Builder::XmlMarkup.new
395
- xml.hps :ManualEntry do
396
- xml.hps :CardNbr, card.number
397
- xml.hps :ExpMonth, card.exp_month
398
- xml.hps :ExpYear, card.exp_year
399
- xml.hps :CVV2, card.cvv
400
- xml.hps :CardPresent, "N"
401
- xml.hps :ReaderPresent, "N"
402
- end
403
- xml.target!
404
- end
405
-
406
- def hydrate_additional_txn_fields(details)
407
- xml = Builder::XmlMarkup.new
408
- xml.hps :AdditionalTxnFields do
409
- xml.hps :Description, details.memo if details.memo
410
- xml.hps :InvoiceNbr, details.invoice_number if details.invoice_number
411
- xml.hps :CustomerID, details.customer_id if details.customer_id
412
- end
413
- xml.target!
414
- end
415
-
416
- def submit_charge(transaction, amount, currency)
417
-
418
- response = doTransaction(transaction)
419
-
420
- header = response["Header"]
421
- process_charge_gateway_response(header["GatewayRspCode"], header["GatewayRspMsg"], header["GatewayTxnId"], amount, currency)
422
-
423
- creditSaleRsp = response["Transaction"]["CreditSale"]
424
- process_charge_issuer_response(creditSaleRsp["RspCode"], creditSaleRsp["RspText"], header["GatewayTxnId"], amount, currency)
425
-
426
- result = HpsCharge.new(hydrate_transaction_header(header))
427
- result.transaction_id = header["GatewayTxnId"]
428
- result.authorized_amount = creditSaleRsp["AuthAmt"]
429
- result.authorization_code = creditSaleRsp["AuthCode"]
430
- result.avs_result_code = creditSaleRsp["AVSRsltCode"]
431
- result.avs_result_text = creditSaleRsp["AVSRsltText"]
432
- result.card_type = creditSaleRsp["CardType"]
433
- result.cpc_indicator = creditSaleRsp["CPCInd"]
434
- result.cvv_result_code = creditSaleRsp["CVVRsltCode"]
435
- result.cvv_result_text = creditSaleRsp["CVVRsltText"]
436
- result.reference_number = creditSaleRsp["RefNbr"]
437
- result.response_code = creditSaleRsp["RspCode"]
438
- result.response_text = creditSaleRsp["RspText"]
439
-
440
- unless header["TokenData"].nil?
441
- result.token_data = HpsTokenData.new()
442
- result.token_data.response_code = header["TokenData"]["TokenRspCode"];
443
- result.token_data.response_message = header["TokenData"]["TokenRspMsg"]
444
- result.token_data.token_value = header["TokenData"]["TokenValue"]
445
- end
446
-
447
- result
448
- end
449
-
450
- def submit_authorize(transaction, amount, currency)
451
-
452
- response = doTransaction(transaction)
453
- header = response["Header"]
454
- process_charge_gateway_response(header["GatewayRspCode"], header["GatewayRspMsg"], header["GatewayTxnId"], amount, currency)
455
-
456
- auth_response = response["Transaction"]["CreditAuth"]
457
- process_charge_issuer_response(auth_response["RspCode"], auth_response["RspText"], header["GatewayTxnId"], amount, currency)
458
-
459
- result = HpsAuthorization.new(hydrate_transaction_header(header))
460
- result.transaction_id = header["GatewayTxnId"]
461
- result.authorized_amount = auth_response["AuthAmt"]
462
- result.authorization_code = auth_response["AuthCode"]
463
- result.avs_result_code = auth_response["AVSRsltCode"]
464
- result.avs_result_text = auth_response["AVSRsltText"]
465
- result.card_type = auth_response["CardType"]
466
- result.cpc_indicator = auth_response["CPCInd"]
467
- result.cvv_result_code = auth_response["CVVRsltCode"]
468
- result.cvv_result_text = auth_response["CVVRsltText"]
469
- result.reference_number = auth_response["RefNbr"]
470
- result.response_code = auth_response["RspCode"]
471
- result.response_text = auth_response["RspText"]
472
-
473
- unless header["TokenData"].nil?
474
- result.token_data = HpsTokenData.new()
475
- result.token_data.response_code = header["TokenData"]["TokenRspCode"];
476
- result.token_data.response_message = header["TokenData"]["TokenRspMsg"]
477
- result.token_data.token_value = header["TokenData"]["TokenValue"]
478
- end
479
-
480
- result
481
- end
482
-
483
- def submit_refund(transaction)
484
-
485
- response = doTransaction(transaction)
486
- header = response["Header"]
487
-
488
- unless header["GatewayRspCode"].eql? "0"
489
- raise @exception_mapper.map_gateway_exception(header["GatewayTxnId"], header["GatewayRspCode"], header["GatewayRspMsg"])
490
- end
491
-
492
- result = HpsRefund.new(hydrate_transaction_header(header))
493
- result.transaction_id = header["GatewayTxnId"]
494
- result.response_code = "00"
495
- result.response_text = ""
496
-
497
- result
498
- end
499
-
500
- def submit_reverse(transaction)
501
-
502
- response = doTransaction(transaction)
503
- header = response["Header"]
504
-
505
- if !header["GatewayRspCode"].eql? "0"
506
- raise @exception_mapper.map_gateway_exception(header["GatewayTxnId"], header["GatewayRspCode"], header["GatewayRspMsg"])
507
- end
508
-
509
- reversal = response["Transaction"]["CreditReversal"]
510
- result = HpsReversal.new(hydrate_transaction_header(header))
511
- result.transaction_id = header["GatewayTxnId"]
512
- result.avs_result_code = reversal["AVSRsltCode"]
513
- result.avs_result_text = reversal["AVSRsltText"]
514
- result.cpc_indicator = reversal["CPCInd"]
515
- result.cvv_result_code = reversal["CVVRsltCode"]
516
- result.cvv_result_text = reversal["CVVRsltText"]
517
- result.reference_number = reversal["RefNbr"]
518
- result.response_code = reversal["RspCode"]
519
- result.response_text = reversal["RspText"]
520
- result
521
- end
522
-
523
- def submit_verify(transaction)
524
- response = doTransaction(transaction)
525
- header = response["Header"]
526
-
527
- if !header["GatewayRspCode"].eql? "0"
528
- raise @exception_mapper.map_gateway_exception(header["GatewayTxnId"], header["GatewayRspCode"], header["GatewayRspMsg"])
529
- end
530
-
531
- account_verify = response["Transaction"]["CreditAccountVerify"]
532
- result = HpsAccountVerify.new(hydrate_transaction_header(header))
533
- result.transaction_id = header["GatewayTxnId"]
534
- result.avs_result_code = account_verify["AVSRsltCode"]
535
- result.avs_result_text = account_verify["AVSRsltText"]
536
- result.reference_number = account_verify["RefNbr"]
537
- result.response_code = account_verify["RspCode"]
538
- result.response_text = account_verify["RspText"]
539
- result.card_type = account_verify["CardType"]
540
- result.cpc_indicator = account_verify["CPCInd"]
541
- result.cvv_result_code = account_verify["CVVRsltCode"]
542
- result.cvv_result_text = account_verify["CVVRsltText"]
543
- result.authorization_code = account_verify["AuthCode"]
544
- result.authorized_amount = account_verify["AuthAmt"]
545
-
546
- if [ "85", "00" ].include? result.response_code == false
547
- raise @exception_mapper.map_issuer_exception(result.transaction_id, result.response_code, result.response_text)
548
- end
549
-
550
- unless header["TokenData"].nil?
551
- result.token_data = HpsTokenData.new()
552
- result.token_data.response_code = header["TokenData"]["TokenRspCode"];
553
- result.token_data.response_message = header["TokenData"]["TokenRspMsg"]
554
- result.token_data.token_value = header["TokenData"]["TokenValue"]
555
- end
556
-
557
- result
558
- end
559
-
560
- def submit_void(transaction)
561
- response = doTransaction(transaction)
562
- header = response["Header"]
563
- unless header["GatewayRspCode"].eql? "0"
564
- raise @exception_mapper.map_gateway_exception(header["GatewayTxnId"], header["GatewayRspCode"], header["GatewayRspMsg"])
565
- end
566
-
567
- result = HpsVoid.new(hydrate_transaction_header(header))
568
- result.transaction_id = header["GatewayTxnId"]
569
- result.response_code = "00"
570
- result.response_text = ""
571
- result
572
- end
573
-
574
- def process_charge_gateway_response(response_code, response_text, transaction_id, amount, currency)
575
-
576
- if !response_code.eql? "0"
577
-
578
- if response_code.eql? "30"
579
-
580
- begin
581
-
582
- reverse_transaction(transaction_id, amount, currency)
583
-
584
- rescue => e
585
- exception = @exception_mapper.map_sdk_exception(SdkCodes.reversal_error_after_gateway_timeout, e)
586
- exception.response_code = response_code
587
- exception.response_text = response_text
588
- raise exception
589
- end
590
-
591
- end
592
-
593
- exception = @exception_mapper.map_gateway_exception(transaction_id, response_code, response_text)
594
- exception.response_code = response_code
595
- exception.response_text = response_text
596
- raise exception
597
-
598
- end
599
-
600
- end
601
-
602
- def process_charge_issuer_response(response_code, response_text, transaction_id, amount, currency)
603
-
604
- if response_code.eql? "91"
605
-
606
- begin
607
-
608
- reverse_transaction(transaction_id, amount, currency)
609
-
610
- rescue => e
611
- exception = @exception_mapper.map_sdk_exception(SdkCodes.reversal_error_after_issuer_timeout, e)
612
- exception.response_code = response_code
613
- exception.response_text = response_text
614
- raise exception
615
- end
616
-
617
- exception = @exception_mapper.map_sdk_exception(SdkCodes.processing_error)
618
- exception.response_code = response_code
619
- exception.response_text = response_text
620
- raise exception
621
-
622
- elsif !response_code.eql? "00"
623
-
624
- exception = @exception_mapper.map_issuer_exception(transaction_id, response_code, response_text)
625
- exception.response_code = response_code
626
- exception.response_text = response_text
627
- raise exception
628
-
629
- end
630
-
631
- end
632
-
633
- end
634
-
635
- end
1
+ module Hps
2
+ class HpsChargeService < HpsService
3
+
4
+ def get(transaction_id)
5
+
6
+ if transaction_id.nil? or transaction_id == 0
7
+ raise @exception_mapper.map_sdk_exception(SdkCodes.invalid_transaction_id)
8
+ end
9
+
10
+ xml = Builder::XmlMarkup.new
11
+ xml.hps :Transaction do
12
+ xml.hps :ReportTxnDetail do
13
+ xml.hps :TxnId, transaction_id
14
+ end
15
+ end
16
+
17
+ response = doTransaction(xml.target!)
18
+ detail = response["Transaction"]["ReportTxnDetail"]
19
+
20
+ header = hydrate_transaction_header(response["Header"])
21
+ result = HpsReportTransactionDetails.new(header)
22
+ result.transaction_id = detail["GatewayTxnId"]
23
+ result.original_transaction_id = detail["OriginalGatewayTxnId"]
24
+ result.authorized_amount = detail["Data"]["AuthAmt"]
25
+ result.authorization_code = detail["Data"]["AuthCode"]
26
+ result.avs_result_code = detail["Data"]["AVSRsltCode"]
27
+ result.avs_result_text = detail["Data"]["AVSRsltText"]
28
+ result.card_type = detail["Data"]["CardType"]
29
+ result.masked_card_number = detail["Data"]["MaskedCardNbr"]
30
+ result.transaction_type = Hps.service_name_to_transaction_type(detail["ServiceName"])
31
+ result.transaction_date = detail["RspUtcDT"]
32
+ result.cpc_indicator = detail["Data"]["CPCInd"]
33
+ result.cvv_result_code = detail["Data"]["CVVRsltCode"]
34
+ result.cvv_result_text = detail["Data"]["CVVRsltText"]
35
+ result.reference_number = detail["Data"]["RefNbr"]
36
+ result.response_code = detail["Data"]["RspCode"]
37
+ result.response_text = detail["Data"]["RspText"]
38
+
39
+ tokenization_message = detail["Data"]["TokenizationMsg"]
40
+
41
+ unless tokenization_message.nil?
42
+ result.token_data = HpsTokenData.new(tokenization_message)
43
+ end
44
+
45
+ header_response_code = response["Header"]["GatewayRspCode"]
46
+ data_response_code = detail["Data"]["RspCode"]
47
+
48
+ if header_response_code != "0" or data_response_code != "00"
49
+
50
+ exceptions = HpsChargeExceptions.new()
51
+
52
+ if header_response_code != "0"
53
+ message = response["Header"]["GatewayRspMsg"]
54
+ exceptions.hps_exception = @exception_mapper.map_gateway_exception(result.transaction_id, header_response_code, message)
55
+ end
56
+
57
+ if data_response_code != "0"
58
+ message = detail["Data"]["RspText"]
59
+ exceptions.card_exception = @exception_mapper.map_issuer_exception(transaction_id, data_response_code, message)
60
+ end
61
+
62
+ result.exceptions = exceptions
63
+
64
+ end
65
+
66
+ result
67
+
68
+ end
69
+
70
+ def list(start_date, end_date, filter_by = nil)
71
+
72
+ if start_date > DateTime.now
73
+ raise @exception_mapper.map_sdk_exception(SdkCodes.invalid_start_date)
74
+ elsif end_date > DateTime.now
75
+ raise @exception_mapper.map_sdk_exception(SdkCodes.invalid_end_date)
76
+ end
77
+
78
+ xml = Builder::XmlMarkup.new
79
+ xml.hps :Transaction do
80
+ xml.hps :ReportActivity do
81
+ xml.hps :RptStartUtcDT, start_date.utc.iso8601
82
+ xml.hps :RptEndUtcDT, end_date.utc.iso8601
83
+ end
84
+ end
85
+
86
+ response = doTransaction(xml.target!)
87
+
88
+ # Gateway exception
89
+ if response["Header"]["GatewayRspCode"] != "0"
90
+ transaction_id = response["Header"]["GatewayTxnId"]
91
+ response_code = response["Header"]["GatewayRspCode"]
92
+ response_message = response["Header"]["GatewayRspMsg"]
93
+ raise @exception_mapper.map_gateway_exception(transaction_id, response_code, response_message)
94
+ end
95
+
96
+ result = Array.new
97
+
98
+ if response["Transaction"]["ReportActivity"]["Header"]["TxnCnt"] == "0"
99
+ return result
100
+ end
101
+
102
+ response["Transaction"]["ReportActivity"]["Details"].each { |charge|
103
+
104
+ next if !filter_by.nil? and charge.serviceName != Hps.transaction_type_to_service_name(filter_by)
105
+
106
+ summary = HpsReportTransactionSummary.new()
107
+ summary.transaction_id = charge["GatewayTxnId"]
108
+ summary.original_transaction_id = charge["OriginalGatewayTxnId"]
109
+ summary.masked_card_number = charge["MaskedCardNbr"]
110
+ summary.response_code = charge["IssuerRspCode"]
111
+ summary.response_text = charge["IssuerRspText"]
112
+ summary.transaction_type = Hps.transaction_type_to_service_name(charge["ServiceName"]) if filter_by.nil? == false
113
+
114
+ gw_response_code = charge["GatewayRspCode"]
115
+ issuer_response_code = charge["IssuerRspCode"]
116
+
117
+ if gw_response_code != "0" or issuer_response_code != "00"
118
+
119
+ exceptions = HpsChargeExceptions.new()
120
+
121
+ if gw_response_code != "0"
122
+ message = charge["GatewayRspMsg"]
123
+ exceptions.hps_exception = @exception_mapper.map_gateway_exception(charge["GatewayTxnId"], gw_response_code, message)
124
+ end
125
+
126
+ if issuer_response_code != "0"
127
+ message = charge["IssuerRspText"]
128
+ exceptions.card_exception = @exception_mapper.map_issuer_exception(charge["GatewayTxnId"], issuer_response_code, message)
129
+ end
130
+
131
+ summary.exceptions = exceptions
132
+
133
+ end
134
+
135
+ result << summary
136
+ }
137
+
138
+ result
139
+ end
140
+
141
+ def charge(amount, currency, card, card_holder = nil, request_multi_use_token = false, details = nil, txn_descriptor = nil)
142
+ check_amount(amount)
143
+ check_currency(currency)
144
+
145
+ xml = Builder::XmlMarkup.new
146
+ xml.hps :Transaction do
147
+ xml.hps :CreditSale do
148
+ xml.hps :Block1 do
149
+ xml.hps :AllowDup, "Y"
150
+ xml.hps :Amt, amount
151
+ xml << hydrate_cardholder_data(card_holder) if card_holder
152
+ xml << hydrate_additional_txn_fields(details) if details
153
+ xml.hps :TxnDescriptor, txn_descriptor if txn_descriptor
154
+ xml.hps :CardData do
155
+
156
+ # NOTE: Process as Manual Entry if they gave us a Credit Card
157
+ if card.is_a? HpsCreditCard
158
+ xml << hydrate_manual_entry(card)
159
+ # Note: Otherwise, consider it a token
160
+ else
161
+ xml.hps :TokenData do
162
+ xml.hps :TokenValue, card
163
+ end
164
+ end
165
+
166
+ xml.hps :TokenRequest, request_multi_use_token ? "Y" : "N"
167
+
168
+ end
169
+ end
170
+ end
171
+ end
172
+
173
+ submit_charge(xml.target!, amount, currency)
174
+ end
175
+
176
+ def charge_swipe(amount, currency, track_data, encryption_data = nil, gratuity = 0, allow_partial_auth = false, txn_descriptor = nil, request_multi_use_token = false, direct_market_data = nil)
177
+ check_amount(amount)
178
+ check_currency(currency)
179
+
180
+ xml = Builder::XmlMarkup.new
181
+ xml.hps :Transaction do
182
+ xml.hps :CreditSale do
183
+ xml.hps :Block1 do
184
+ xml.hps :AllowDup, "Y"
185
+ xml.hps :Amt, amount
186
+ xml.hps :GratuityAmtInfo, gratuity if gratuity != 0
187
+ xml.hps :TxnDescriptor, txn_descriptor if txn_descriptor
188
+ xml.hps :AllowPartialAuth, allow_partial_auth ? "Y" : "N"
189
+ xml.hps :CardData do
190
+ xml << hydrate_card_track_data(track_data)
191
+ xml << hydrate_encryption_data(encryption_data) if encryption_data
192
+ xml.hps :TokenRequest, request_multi_use_token ? "Y" : "N"
193
+ end
194
+ xml << hydrate_direct_market_data(direct_market_data) if direct_market_data
195
+ end
196
+ end
197
+ end
198
+
199
+ submit_charge(xml.target!, amount, currency)
200
+ end
201
+
202
+ def verify(card, card_holder = nil, request_multi_use_token = false, client_txn_id = nil)
203
+
204
+ xml = Builder::XmlMarkup.new
205
+ xml.hps :Transaction do
206
+ xml.hps :CreditAccountVerify do
207
+ xml.hps :Block1 do
208
+ xml << hydrate_cardholder_data(card_holder) if card_holder
209
+ xml.hps :CardData do
210
+
211
+ # NOTE: Process as Manual Entry if they gave us a Credit Card
212
+ if card.is_a? HpsCreditCard
213
+ xml << hydrate_manual_entry(card)
214
+ # Note: Otherwise, consider it a token
215
+ else
216
+ xml.hps :TokenData do
217
+ xml.hps :TokenValue, card
218
+ end
219
+ end
220
+
221
+ xml.hps :TokenRequest, request_multi_use_token ? "Y" : "N"
222
+
223
+ end
224
+ end
225
+ end
226
+ end
227
+
228
+ submit_verify(xml.target!)
229
+ end
230
+
231
+ def verify_swipe(track_data, card_holder = nil, encryption_data = nil, request_multi_use_token = false, client_txn_id = nil)
232
+
233
+ xml = Builder::XmlMarkup.new
234
+ xml.hps :Transaction do
235
+ xml.hps :CreditAccountVerify do
236
+ xml.hps :Block1 do
237
+ xml << hydrate_cardholder_data(card_holder) if card_holder
238
+ xml.hps :CardData do
239
+ xml << hydrate_card_track_data(track_data)
240
+ xml << hydrate_encryption_data(encryption_data) if encryption_data
241
+
242
+ xml.hps :TokenRequest, request_multi_use_token ? "Y" : "N"
243
+ end
244
+ end
245
+ end
246
+ end
247
+
248
+ submit_verify(xml.target!)
249
+ end
250
+
251
+ def authorize(amount, currency, card, card_holder = nil, request_multi_use_token = false, details = nil, txn_descriptor = nil)
252
+
253
+ check_amount(amount)
254
+ check_currency(currency)
255
+
256
+ xml = Builder::XmlMarkup.new
257
+ xml.hps :Transaction do
258
+ xml.hps :CreditAuth do
259
+ xml.hps :Block1 do
260
+ xml.hps :AllowDup, "Y"
261
+ xml.hps :Amt, amount
262
+ xml << hydrate_cardholder_data(card_holder) if card_holder
263
+ xml << hydrate_additional_txn_fields(details) if details
264
+ xml.hps :TxnDescriptor, txn_descriptor if txn_descriptor
265
+ xml.hps :CardData do
266
+
267
+ # NOTE: Process as Manual Entry if they gave us a Credit Card
268
+ if card.is_a? HpsCreditCard
269
+ xml << hydrate_manual_entry(card)
270
+ # Note: Otherwise, consider it a token
271
+ else
272
+ xml.hps :TokenData do
273
+ xml.hps :TokenValue, card
274
+ end
275
+ end
276
+
277
+ xml.hps :TokenRequest, request_multi_use_token ? "Y" : "N"
278
+
279
+ end
280
+ end
281
+ end
282
+ end
283
+
284
+ submit_authorize(xml.target!, amount, currency)
285
+ end
286
+
287
+ def authorize_swipe(amount, currency, track_data, encryption_data = nil, gratuity = 0, allow_partial_auth = false, txn_descriptor = nil)
288
+ check_amount(amount)
289
+ check_currency(currency)
290
+
291
+ xml = Builder::XmlMarkup.new
292
+ xml.hps :Transaction do
293
+ xml.hps :CreditAuth do
294
+ xml.hps :Block1 do
295
+ xml.hps :AllowDup, "Y"
296
+ xml.hps :Amt, amount
297
+ xml.hps :TxnDescriptor, txn_descriptor if txn_descriptor
298
+ xml.hps :AllowPartialAuth, allow_partial_auth ? "Y" : "N"
299
+ xml.hps :CardData do
300
+ xml << hydrate_card_track_data(track_data)
301
+ xml << hydrate_encryption_data(encryption_data) if encryption_data
302
+ end
303
+ end
304
+ end
305
+ end
306
+
307
+ submit_authorize(xml.target!, amount, currency)
308
+ end
309
+
310
+ def capture(transaction_id, amount = nil)
311
+
312
+ xml = Builder::XmlMarkup.new
313
+ xml.hps :Transaction do
314
+ xml.hps :CreditAddToBatch do
315
+ xml.hps :GatewayTxnId, transaction_id
316
+ xml.hps :Amt, amount if amount
317
+ end
318
+ end
319
+
320
+ response = doTransaction(xml.target!)
321
+ header = response["Header"]
322
+
323
+ raise @exception_mapper.map_gateway_exception(transaction_id, header["GatewayRspCode"], header["GatewayRspMsg"]) unless header["GatewayRspCode"].eql? "0"
324
+
325
+ get(transaction_id)
326
+ end
327
+
328
+ def reverse(card, amount, currency, details = nil)
329
+ check_amount(amount)
330
+ check_currency(currency)
331
+
332
+ xml = Builder::XmlMarkup.new
333
+ xml.hps :Transaction do
334
+ xml.hps :CreditReversal do
335
+ xml.hps :Block1 do
336
+ xml.hps :Amt, amount
337
+ xml << hydrate_additional_txn_fields(details) if details
338
+ xml.hps :CardData do
339
+
340
+ # NOTE: Process as Manual Entry if they gave us a Credit Card
341
+ if card.is_a? HpsCreditCard
342
+ xml << hydrate_manual_entry(card)
343
+ # Note: Otherwise, consider it a token
344
+ else
345
+ xml.hps :TokenData do
346
+ xml.hps :TokenValue, card
347
+ end
348
+ end
349
+
350
+ end
351
+ end
352
+ end
353
+ end
354
+
355
+ submit_reverse(xml.target!)
356
+ end
357
+
358
+ def reverse_transaction(transaction_id, amount, currency, details = nil)
359
+ check_amount(amount)
360
+ check_currency(currency)
361
+
362
+ xml = Builder::XmlMarkup.new
363
+ xml.hps :Transaction do
364
+ xml.hps :CreditReversal do
365
+ xml.hps :Block1 do
366
+ xml.hps :Amt, amount
367
+ xml.hps :GatewayTxnId, transaction_id
368
+ xml << hydrate_additional_txn_fields(details) if details
369
+ end
370
+ end
371
+ end
372
+
373
+ submit_reverse(xml.target!)
374
+ end
375
+
376
+ def refund(amount, currency, card, card_holder = nil, details = nil)
377
+ check_amount(amount)
378
+ check_currency(currency)
379
+
380
+ xml = Builder::XmlMarkup.new
381
+ xml.hps :Transaction do
382
+ xml.hps :CreditReturn do
383
+ xml.hps :Block1 do
384
+ xml.hps :AllowDup, "Y"
385
+ xml.hps :Amt, amount
386
+ xml << hydrate_cardholder_data(card_holder) if card_holder
387
+ xml << hydrate_additional_txn_fields(details) if details
388
+ xml.hps :CardData do
389
+
390
+ # NOTE: Process as Manual Entry if they gave us a Credit Card
391
+ if card.is_a? HpsCreditCard
392
+ xml << hydrate_manual_entry(card)
393
+ # Note: Otherwise, consider it a token
394
+ else
395
+ xml.hps :TokenData do
396
+ xml.hps :TokenValue, card
397
+ end
398
+ end
399
+
400
+ end
401
+ end
402
+ end
403
+ end
404
+
405
+ submit_refund(xml.target!)
406
+ end
407
+
408
+ def refund_transaction(amount, currency, transaction_id, card_holder = nil, details = nil)
409
+ check_amount(amount)
410
+ check_currency(currency)
411
+
412
+ xml = Builder::XmlMarkup.new
413
+ xml.hps :Transaction do
414
+ xml.hps :CreditReturn do
415
+ xml.hps :Block1 do
416
+ xml.hps :AllowDup, "Y"
417
+ xml.hps :Amt, amount
418
+ xml.hps :GatewayTxnId, transaction_id
419
+ xml << hydrate_cardholder_data(card_holder) if card_holder
420
+ xml << hydrate_additional_txn_fields(details) if details
421
+ end
422
+ end
423
+ end
424
+
425
+ submit_refund(xml.target!)
426
+ end
427
+
428
+ def void(transaction_id)
429
+ xml = Builder::XmlMarkup.new
430
+ xml.hps :Transaction do
431
+ xml.hps :CreditVoid do
432
+ xml.hps :GatewayTxnId, transaction_id
433
+ end
434
+ end
435
+
436
+ submit_void(xml.target!)
437
+ end
438
+ private
439
+
440
+ def check_amount(amount)
441
+ raise @exception_mapper.map_sdk_exception(SdkCodes.invalid_amount) if amount.nil? or amount <= 0
442
+ end
443
+
444
+ def check_currency(currency)
445
+ raise @exception_mapper.map_sdk_exception(SdkCodes.missing_currency) if currency.empty?
446
+ raise @exception_mapper.map_sdk_exception(SdkCodes.invalid_currency) unless currency.downcase.eql? "usd"
447
+ end
448
+
449
+ def hydrate_cardholder_data(card_holder)
450
+ xml = Builder::XmlMarkup.new
451
+ xml.hps :CardHolderData do
452
+ xml.hps :CardHolderFirstName, card_holder.first_name
453
+ xml.hps :CardHolderLastName, card_holder.last_name
454
+ xml.hps :CardHolderEmail, card_holder.email_address
455
+ xml.hps :CardHolderPhone, card_holder.phone
456
+ xml.hps :CardHolderAddr, card_holder.address.address
457
+ xml.hps :CardHolderCity, card_holder.address.city
458
+ xml.hps :CardHolderState, card_holder.address.state
459
+ xml.hps :CardHolderZip, card_holder.address.zip
460
+ end
461
+ xml.target!
462
+ end
463
+
464
+ def hydrate_manual_entry(card)
465
+ xml = Builder::XmlMarkup.new
466
+ xml.hps :ManualEntry do
467
+ xml.hps :CardNbr, card.number
468
+ xml.hps :ExpMonth, card.exp_month
469
+ xml.hps :ExpYear, card.exp_year
470
+ xml.hps :CVV2, card.cvv
471
+ xml.hps :CardPresent, card.card_present ? "Y" : "N"
472
+ xml.hps :ReaderPresent, card.reader_present ? "Y" : "N"
473
+ end
474
+ xml.target!
475
+ end
476
+
477
+ def hydrate_card_track_data(track_data)
478
+ xml = Builder::XmlMarkup.new
479
+ xml.hps :TrackData, :method => track_data.method_obtained do
480
+ xml << track_data.value
481
+ end
482
+ xml.target!
483
+ end
484
+
485
+ def hydrate_encryption_data(data)
486
+ xml = Builder::XmlMarkup.new
487
+ xml.hps :EncryptionData do
488
+ xml.hps :EncryptedTrackNumber, data.encrypted_track_number if data.encrypted_track_number
489
+ xml.hps :KSN, data.ksn if data.ksn
490
+ xml.hps :KTB, data.ktb if data.ktb
491
+ xml.hps :Version, data.version if data.version
492
+ end
493
+ xml.target!
494
+ end
495
+
496
+ def hydrate_direct_market_data(data)
497
+ xml = Builder::XmlMarkup.new
498
+ xml.hps :DirectMktData do
499
+ xml.hps :DirectMktInvoideNbr, data.invoice_number
500
+ xml.hps :DirectMktShipMonth, data.ship_month
501
+ xml.hps :DirectMktShipDay, data.ship_day
502
+ end
503
+ xml.target!
504
+ end
505
+
506
+ def hydrate_additional_txn_fields(details)
507
+ xml = Builder::XmlMarkup.new
508
+ xml.hps :AdditionalTxnFields do
509
+ xml.hps :Description, details.memo if details.memo
510
+ xml.hps :InvoiceNbr, details.invoice_number if details.invoice_number
511
+ xml.hps :CustomerID, details.customer_id if details.customer_id
512
+ end
513
+ xml.target!
514
+ end
515
+
516
+ def submit_charge(transaction, amount, currency)
517
+
518
+ response = doTransaction(transaction)
519
+
520
+ header = response["Header"]
521
+ process_charge_gateway_response(header["GatewayRspCode"], header["GatewayRspMsg"], header["GatewayTxnId"], amount, currency)
522
+
523
+ creditSaleRsp = response["Transaction"]["CreditSale"]
524
+ process_charge_issuer_response(creditSaleRsp["RspCode"], creditSaleRsp["RspText"], header["GatewayTxnId"], amount, currency)
525
+
526
+ result = HpsCharge.new(hydrate_transaction_header(header))
527
+ result.transaction_id = header["GatewayTxnId"]
528
+ result.authorized_amount = creditSaleRsp["AuthAmt"]
529
+ result.authorization_code = creditSaleRsp["AuthCode"]
530
+ result.avs_result_code = creditSaleRsp["AVSRsltCode"]
531
+ result.avs_result_text = creditSaleRsp["AVSRsltText"]
532
+ result.card_type = creditSaleRsp["CardType"]
533
+ result.cpc_indicator = creditSaleRsp["CPCInd"]
534
+ result.cvv_result_code = creditSaleRsp["CVVRsltCode"]
535
+ result.cvv_result_text = creditSaleRsp["CVVRsltText"]
536
+ result.reference_number = creditSaleRsp["RefNbr"]
537
+ result.response_code = creditSaleRsp["RspCode"]
538
+ result.response_text = creditSaleRsp["RspText"]
539
+
540
+ unless header["TokenData"].nil?
541
+ result.token_data = HpsTokenData.new()
542
+ result.token_data.response_code = header["TokenData"]["TokenRspCode"];
543
+ result.token_data.response_message = header["TokenData"]["TokenRspMsg"]
544
+ result.token_data.token_value = header["TokenData"]["TokenValue"]
545
+ end
546
+
547
+ result
548
+ end
549
+
550
+ def submit_authorize(transaction, amount, currency)
551
+
552
+ response = doTransaction(transaction)
553
+ header = response["Header"]
554
+ process_charge_gateway_response(header["GatewayRspCode"], header["GatewayRspMsg"], header["GatewayTxnId"], amount, currency)
555
+
556
+ auth_response = response["Transaction"]["CreditAuth"]
557
+ process_charge_issuer_response(auth_response["RspCode"], auth_response["RspText"], header["GatewayTxnId"], amount, currency)
558
+
559
+ result = HpsAuthorization.new(hydrate_transaction_header(header))
560
+ result.transaction_id = header["GatewayTxnId"]
561
+ result.authorized_amount = auth_response["AuthAmt"]
562
+ result.authorization_code = auth_response["AuthCode"]
563
+ result.avs_result_code = auth_response["AVSRsltCode"]
564
+ result.avs_result_text = auth_response["AVSRsltText"]
565
+ result.card_type = auth_response["CardType"]
566
+ result.cpc_indicator = auth_response["CPCInd"]
567
+ result.cvv_result_code = auth_response["CVVRsltCode"]
568
+ result.cvv_result_text = auth_response["CVVRsltText"]
569
+ result.reference_number = auth_response["RefNbr"]
570
+ result.response_code = auth_response["RspCode"]
571
+ result.response_text = auth_response["RspText"]
572
+
573
+ unless header["TokenData"].nil?
574
+ result.token_data = HpsTokenData.new()
575
+ result.token_data.response_code = header["TokenData"]["TokenRspCode"];
576
+ result.token_data.response_message = header["TokenData"]["TokenRspMsg"]
577
+ result.token_data.token_value = header["TokenData"]["TokenValue"]
578
+ end
579
+
580
+ result
581
+ end
582
+
583
+ def submit_refund(transaction)
584
+
585
+ response = doTransaction(transaction)
586
+ header = response["Header"]
587
+
588
+ unless header["GatewayRspCode"].eql? "0"
589
+ raise @exception_mapper.map_gateway_exception(header["GatewayTxnId"], header["GatewayRspCode"], header["GatewayRspMsg"])
590
+ end
591
+
592
+ result = HpsRefund.new(hydrate_transaction_header(header))
593
+ result.transaction_id = header["GatewayTxnId"]
594
+ result.response_code = "00"
595
+ result.response_text = ""
596
+
597
+ result
598
+ end
599
+
600
+ def submit_reverse(transaction)
601
+
602
+ response = doTransaction(transaction)
603
+ header = response["Header"]
604
+
605
+ if !header["GatewayRspCode"].eql? "0"
606
+ raise @exception_mapper.map_gateway_exception(header["GatewayTxnId"], header["GatewayRspCode"], header["GatewayRspMsg"])
607
+ end
608
+
609
+ reversal = response["Transaction"]["CreditReversal"]
610
+ result = HpsReversal.new(hydrate_transaction_header(header))
611
+ result.transaction_id = header["GatewayTxnId"]
612
+ result.avs_result_code = reversal["AVSRsltCode"]
613
+ result.avs_result_text = reversal["AVSRsltText"]
614
+ result.cpc_indicator = reversal["CPCInd"]
615
+ result.cvv_result_code = reversal["CVVRsltCode"]
616
+ result.cvv_result_text = reversal["CVVRsltText"]
617
+ result.reference_number = reversal["RefNbr"]
618
+ result.response_code = reversal["RspCode"]
619
+ result.response_text = reversal["RspText"]
620
+ result
621
+ end
622
+
623
+ def submit_verify(transaction)
624
+ response = doTransaction(transaction)
625
+ header = response["Header"]
626
+
627
+ if !header["GatewayRspCode"].eql? "0"
628
+ raise @exception_mapper.map_gateway_exception(header["GatewayTxnId"], header["GatewayRspCode"], header["GatewayRspMsg"])
629
+ end
630
+
631
+ account_verify = response["Transaction"]["CreditAccountVerify"]
632
+ result = HpsAccountVerify.new(hydrate_transaction_header(header))
633
+ result.transaction_id = header["GatewayTxnId"]
634
+ result.avs_result_code = account_verify["AVSRsltCode"]
635
+ result.avs_result_text = account_verify["AVSRsltText"]
636
+ result.reference_number = account_verify["RefNbr"]
637
+ result.response_code = account_verify["RspCode"]
638
+ result.response_text = account_verify["RspText"]
639
+ result.card_type = account_verify["CardType"]
640
+ result.cpc_indicator = account_verify["CPCInd"]
641
+ result.cvv_result_code = account_verify["CVVRsltCode"]
642
+ result.cvv_result_text = account_verify["CVVRsltText"]
643
+ result.authorization_code = account_verify["AuthCode"]
644
+ result.authorized_amount = account_verify["AuthAmt"]
645
+
646
+ if [ "85", "00" ].include? result.response_code == false
647
+ raise @exception_mapper.map_issuer_exception(result.transaction_id, result.response_code, result.response_text)
648
+ end
649
+
650
+ unless header["TokenData"].nil?
651
+ result.token_data = HpsTokenData.new()
652
+ result.token_data.response_code = header["TokenData"]["TokenRspCode"];
653
+ result.token_data.response_message = header["TokenData"]["TokenRspMsg"]
654
+ result.token_data.token_value = header["TokenData"]["TokenValue"]
655
+ end
656
+
657
+ result
658
+ end
659
+
660
+ def submit_void(transaction)
661
+ response = doTransaction(transaction)
662
+ header = response["Header"]
663
+ unless header["GatewayRspCode"].eql? "0"
664
+ raise @exception_mapper.map_gateway_exception(header["GatewayTxnId"], header["GatewayRspCode"], header["GatewayRspMsg"])
665
+ end
666
+
667
+ result = HpsVoid.new(hydrate_transaction_header(header))
668
+ result.transaction_id = header["GatewayTxnId"]
669
+ result.response_code = "00"
670
+ result.response_text = ""
671
+ result
672
+ end
673
+
674
+ def process_charge_gateway_response(response_code, response_text, transaction_id, amount, currency)
675
+
676
+ if !response_code.eql? "0"
677
+
678
+ if response_code.eql? "30"
679
+
680
+ begin
681
+
682
+ reverse_transaction(transaction_id, amount, currency)
683
+
684
+ rescue => e
685
+ exception = @exception_mapper.map_sdk_exception(SdkCodes.reversal_error_after_gateway_timeout, e)
686
+ exception.response_code = response_code
687
+ exception.response_text = response_text
688
+ raise exception
689
+ end
690
+
691
+ end
692
+
693
+ exception = @exception_mapper.map_gateway_exception(transaction_id, response_code, response_text)
694
+ exception.response_code = response_code
695
+ exception.response_text = response_text
696
+ raise exception
697
+
698
+ end
699
+
700
+ end
701
+
702
+ def process_charge_issuer_response(response_code, response_text, transaction_id, amount, currency)
703
+
704
+ if response_code.eql? "91"
705
+
706
+ begin
707
+
708
+ reverse_transaction(transaction_id, amount, currency)
709
+
710
+ rescue => e
711
+ exception = @exception_mapper.map_sdk_exception(SdkCodes.reversal_error_after_issuer_timeout, e)
712
+ exception.response_code = response_code
713
+ exception.response_text = response_text
714
+ raise exception
715
+ end
716
+
717
+ exception = @exception_mapper.map_sdk_exception(SdkCodes.processing_error)
718
+ exception.response_code = response_code
719
+ exception.response_text = response_text
720
+ raise exception
721
+
722
+ elsif !response_code.eql? "00"
723
+
724
+ exception = @exception_mapper.map_issuer_exception(transaction_id, response_code, response_text)
725
+ exception.response_code = response_code
726
+ exception.response_text = response_text
727
+ raise exception
728
+
729
+ end
730
+
731
+ end
732
+
733
+ end
734
+
735
+ end