Class: PrismPay::PrismPayReports

Inherits:
Object
  • Object
show all
Defined in:
lib/prismpay/prismpay_reports.rb

Constant Summary collapse

WSDL =

this class will manage the connection to the gateway and handle transactions

File.expand_path("../ReportingService.xml", __FILE__)
TRANS_TYPES =
["ccpreauths", "ccpostauthsales", "ccvoids",
"ccrefunds", "ccchargebacks", "achpreauths",
"achsettlements", "achreturns", "achnocs",
"achvoids", "achcreditsauth",
"achcreditsmerchantdebit", "achcreditsdebitreturn",
"achcreditsmerchantsettle",
"achcreditspaymentsettle", "achcreditsreturn",
"debitsales", "debitrefunds", "achlatereturns",
"extachpreauths", "extachsettlements",
"extachreturns", "extachnocs", "extachvoids",
"extachcreditsauth", "extachcreditssettle",
"extachcreditsreturn", "extachck21_auth ",
"extachck21_void", "extachck21_return",
"verfication", "ccincremental", "ccreversal"]
CARD_TYPES =
["visa", "mastercard", "amex", "discovernetwork",
"jcb", "diners", "debit", "flyingj", "cfna",
"gemoney", "fleetone", "fuellnk", "fuelman",
"mastercardfleet", "visafleet", "voyager",
"wrightexpress"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PrismPayReports

Returns a new instance of PrismPayReports.



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/prismpay/prismpay_reports.rb', line 38

def initialize(options = {})

  merchant_info = options

  merchant_info.merge!({:login => 'TEST0'}) unless merchant_info[:login]

  @login = merchant_info[:login]
  @key = hexstr_to_str(options[:key])
  @account_key = options[:account_key]

  @client = Savon::Client.new(WSDL) # initialize savon client
end

Instance Attribute Details

#acctidObject

Returns the value of attribute acctid.



34
35
36
# File 'lib/prismpay/prismpay_reports.rb', line 34

def acctid
  @acctid
end

#clientObject (readonly)

Returns the value of attribute client.



35
36
37
# File 'lib/prismpay/prismpay_reports.rb', line 35

def client
  @client
end

#passwordObject

Returns the value of attribute password.



34
35
36
# File 'lib/prismpay/prismpay_reports.rb', line 34

def password
  @password
end

Instance Method Details

#account_keyObject



52
53
54
# File 'lib/prismpay/prismpay_reports.rb', line 52

def 
  @account_key
end

#ampm_hour(hour) ⇒ Object



57
58
59
60
61
# File 'lib/prismpay/prismpay_reports.rb', line 57

def ampm_hour(hour)
  hour %= 12
  return 12 if hour == 0 
  hour
end

#create_sessionkeyObject



411
412
413
414
415
416
417
418
419
# File 'lib/prismpay/prismpay_reports.rb', line 411

def create_sessionkey
  # this needs to be of the form Acctid:UnixTime and then
  # encrypted with @key

  unix_time = Time.now.to_i
  string = "#{@login}:#{unix_time}"
  
  encrypt_string(string)
end

#decrypt_string(hexstr) ⇒ Object

openssl methods for encrypting



424
425
426
427
428
429
430
431
432
433
434
# File 'lib/prismpay/prismpay_reports.rb', line 424

def decrypt_string(hexstr)
  # maybe pass the need to convert from the hexstr
  str = hexstr_to_str(hexstr)
  retstr = ""
  cipher = OpenSSL::Cipher.new('des-ede3')
  cipher.decrypt
  cipher.key = @key
  retstr << cipher.update(str)
  retstr << cipher.final
  return retstr
end

#encrypt_string(str) ⇒ Object



436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/prismpay/prismpay_reports.rb', line 436

def encrypt_string(str)
  # returns the hexstr for the url
  # TODO: need to uri escape the string before encrypting
  retstr = ""
  cipher = OpenSSL::Cipher.new("des-ede3")
  cipher.encrypt
  cipher.key = @key
  retstr << cipher.update(str)
  retstr << cipher.final
  retstr = str_to_hexstr(retstr)
  return retstr
end

#get_ach_credits_auth(start_date, end_date) ⇒ Object



176
177
178
179
# File 'lib/prismpay/prismpay_reports.rb', line 176

def get_ach_credits_auth(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['achcreditsauth']})
end

#get_ach_credits_debit_return(start_date, end_date) ⇒ Object



186
187
188
189
# File 'lib/prismpay/prismpay_reports.rb', line 186

def get_ach_credits_debit_return(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['achcreditsdebitreturn']})
end

#get_ach_credits_merchant_debit(start_date, end_date) ⇒ Object



181
182
183
184
# File 'lib/prismpay/prismpay_reports.rb', line 181

def get_ach_credits_merchant_debit(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['achcreditsmerchantdebit']})
end

#get_ach_credits_merchant_settle(start_date, end_date) ⇒ Object



191
192
193
194
# File 'lib/prismpay/prismpay_reports.rb', line 191

def get_ach_credits_merchant_settle(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['achcreditsmerchantsettle']})
end

#get_ach_credits_payment_settle(start_date, end_date) ⇒ Object



196
197
198
199
# File 'lib/prismpay/prismpay_reports.rb', line 196

def get_ach_credits_payment_settle(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['achcreditspaymentsettle']})
end

#get_ach_credits_return(start_date, end_date) ⇒ Object



201
202
203
204
# File 'lib/prismpay/prismpay_reports.rb', line 201

def get_ach_credits_return(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['achcreditsreturn']})
end

#get_ach_late_returns(start_date, end_date) ⇒ Object



216
217
218
219
# File 'lib/prismpay/prismpay_reports.rb', line 216

def get_ach_late_returns(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['achlatereturns']})
end

#get_ach_nocs(start_date, end_date) ⇒ Object



166
167
168
169
# File 'lib/prismpay/prismpay_reports.rb', line 166

def get_ach_nocs(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['achnocs']})
end

#get_ach_preauths(start_date, end_date) ⇒ Object



151
152
153
154
# File 'lib/prismpay/prismpay_reports.rb', line 151

def get_ach_preauths(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['achpreauths']})
end

#get_ach_returns(start_date, end_date) ⇒ Object



161
162
163
164
# File 'lib/prismpay/prismpay_reports.rb', line 161

def get_ach_returns(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['achreturns']})
end

#get_ach_settlements(start_date, end_date) ⇒ Object



156
157
158
159
# File 'lib/prismpay/prismpay_reports.rb', line 156

def get_ach_settlements(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['achsettlements']})
end

#get_ach_voids(start_date, end_date) ⇒ Object



171
172
173
174
# File 'lib/prismpay/prismpay_reports.rb', line 171

def get_ach_voids(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['achvoids']})
end

#get_cc_chargebacks(start_date, end_date) ⇒ Object



90
91
92
93
# File 'lib/prismpay/prismpay_reports.rb', line 90

def get_cc_chargebacks(start_date, end_date)
  get_transactions(start_date, end_date, {:trans_types => 
                     ['ccchargebacks']})
end

#get_cc_incremental(start_date, end_date) ⇒ Object



246
247
248
249
250
# File 'lib/prismpay/prismpay_reports.rb', line 246

def get_cc_incremental(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['ccincremental']})

end

#get_cc_preauths(start_date, end_date) ⇒ Object

The remaining transactions for testing purposes



146
147
148
149
# File 'lib/prismpay/prismpay_reports.rb', line 146

def get_cc_preauths(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['ccpreauths']})
end

#get_cc_refunds(start_date, end_date) ⇒ Object



118
119
120
121
122
# File 'lib/prismpay/prismpay_reports.rb', line 118

def get_cc_refunds(start_date, end_date)
  get_transactions(start_date, end_date, {:trans_types =>
                     ['ccrefunds']})

end

#get_cc_reversals(start_date, end_date) ⇒ Object



95
96
97
98
# File 'lib/prismpay/prismpay_reports.rb', line 95

def get_cc_reversals(start_date, end_date)
  get_transactions(start_date, end_date, {:trans_types =>
                     ['ccreversal']})
end

#get_cc_sales(start_date, end_date) ⇒ Object

These transactions are the ones our system currently makes use of. The only other transactions currently wrapped by prismpay.rb would be of type ccpreauths. We are not presently making any calls to that though



107
108
109
110
# File 'lib/prismpay/prismpay_reports.rb', line 107

def get_cc_sales(start_date, end_date)
  get_transactions(start_date, end_date, {:trans_types =>
                     ['ccpostauthsales']})
end

#get_cc_voids(start_date, end_date) ⇒ Object



112
113
114
115
116
# File 'lib/prismpay/prismpay_reports.rb', line 112

def get_cc_voids(start_date, end_date)
  get_transactions(start_date, end_date, {:trans_types =>
                     ['ccvoids']})

end

#get_debit_refunds(start_date, end_date) ⇒ Object



211
212
213
214
# File 'lib/prismpay/prismpay_reports.rb', line 211

def get_debit_refunds(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['debitrefunds']})
end

#get_debit_sales(start_date, end_date) ⇒ Object



206
207
208
209
# File 'lib/prismpay/prismpay_reports.rb', line 206

def get_debit_sales(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['debitsales']})
end

#get_ext_ach_auths(start_date, end_date) ⇒ Object



124
125
126
127
128
# File 'lib/prismpay/prismpay_reports.rb', line 124

def get_ext_ach_auths(start_date, end_date)
  get_transactions(start_date, end_date, {:trans_types =>
                     ['extachpreauths']})

end

#get_ext_ach_ck21_auth(start_date, end_date) ⇒ Object



226
227
228
229
# File 'lib/prismpay/prismpay_reports.rb', line 226

def get_ext_ach_ck21_auth(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['extachck21_auth']})
end

#get_ext_ach_ck21_return(start_date, end_date) ⇒ Object



236
237
238
239
# File 'lib/prismpay/prismpay_reports.rb', line 236

def get_ext_ach_ck21_return(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['extachck21_return']})
end

#get_ext_ach_ck21_void(start_date, end_date) ⇒ Object



231
232
233
234
# File 'lib/prismpay/prismpay_reports.rb', line 231

def get_ext_ach_ck21_void(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['extachck21_void']})
end

#get_ext_ach_credit_auths(start_date, end_date) ⇒ Object



130
131
132
133
134
# File 'lib/prismpay/prismpay_reports.rb', line 130

def get_ext_ach_credit_auths(start_date, end_date)
  get_transactions(start_date, end_date, {:trans_types =>
                     ['extachcreditsauth']})

end

#get_ext_ach_credits_returned(start_date, end_date) ⇒ Object



85
86
87
88
# File 'lib/prismpay/prismpay_reports.rb', line 85

def get_ext_ach_credits_returned(start_date, end_date)
  get_transactions(start_date, end_date, {:trans_types => 
                     ['extachcreditsreturn']})
end

#get_ext_ach_credits_settled(start_date, end_date) ⇒ Object



80
81
82
83
# File 'lib/prismpay/prismpay_reports.rb', line 80

def get_ext_ach_credits_settled(start_date, end_date)
  get_transactions(start_date, end_date, {:trans_types => 
                     ['extachcreditssettle']})
end

#get_ext_ach_nocs(start_date, end_date) ⇒ Object



221
222
223
224
# File 'lib/prismpay/prismpay_reports.rb', line 221

def get_ext_ach_nocs(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['extachnocs']})
end

#get_ext_ach_returned(start_date, end_date) ⇒ Object



75
76
77
78
# File 'lib/prismpay/prismpay_reports.rb', line 75

def get_ext_ach_returned(start_date, end_date)
  get_transactions(start_date, end_date, {:trans_types => 
                     ['extachreturns']})
end

#get_ext_ach_settled(start_date, end_date) ⇒ Object

These transactions are the ones that happen outside of our system that we must know about and make relationships to transactions that are in our system



70
71
72
73
# File 'lib/prismpay/prismpay_reports.rb', line 70

def get_ext_ach_settled(start_date, end_date)
  get_transactions(start_date, end_date, {:trans_types => 
                     ['extachsettlements']})
end

#get_ext_ach_voids(start_date, end_date) ⇒ Object



136
137
138
139
140
# File 'lib/prismpay/prismpay_reports.rb', line 136

def get_ext_ach_voids(start_date, end_date)
  get_transactions(start_date, end_date, {:trans_types =>
                     ['extachvoids']})

end

#get_transactions(start_date, end_date, options = {}) ⇒ Object

The main method. Takes two Time objects for a start and an end. Also takes a hash of options which act as flags or variables to affect the report.



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/prismpay/prismpay_reports.rb', line 259

def get_transactions(start_date, end_date, options = {})

  #variables to handle return max of sample sets
  max_rows = (options[:max_rows]) ? options[:max_rows] : 4096
  num_rows = (options[:num_rows]) ? options[:num_rows] : max_rows
  start_row = (options[:start_row]) ? options[:start_row] : 1

  # set up the flags to initially include everything
  accepted = declined = childsubids = initial_flag = 
    recurring_flag = recurringretries = sort = 1

  accepted = 0 if options[:not_accepted]
  declined = 0 if options[:not_declined]
  childsubids = 0 if options[:no_childsubids]
  initial_flag = 0 if options[:no_initials]
  recurring_flag = 0 if options[:no_recurrings]
  recurringretries = 0 if options[:no_recurring_retries]
  sort = 0 if options[:no_sort]

  # sets the test flag acceptable values are:
  # 0 = Include Live and Test Transactions.  
  # 1 = Include Live Transactions Only.  
  # 2 = Include Test Transactions Only.
  if options[:test_only] == true
    test_flag = 2
  elsif options[:test_only] == false 
    test_flag = 1
  else
    test_flag = 0
  end

  # sets the recurring_only flag... it overrides all others if true
  options[:recurring_only] ? recurring_only = 1 : recurring_only = 0


  if options[:card_types] 
    card_types = options[:card_types]
  else 
    card_types = CARD_TYPES
  end

  if options[:trans_types] 
    transaction_types = options[:trans_types]
  else 
    transaction_types = TRANS_TYPES
  end
  

  response = @client.request "TransactionReportInfo" do 
    http.auth.ssl.verify_mode = :none
    soap.body do |xml|

      xml.accountkey 
      xml.sessionkey create_sessionkey
      xml.subid options[:subid]

      xml.startdate { |ixml|
        ixml.month "%.2d" % start_date.mon
        ixml.day "%.2d" % start_date.day
        ixml.year start_date.year
        ixml.hour "%.2d" % ampm_hour(start_date.hour)
        ixml.minute "%.2d" % start_date.mon
        ixml.second "%.2d" % start_date.sec
        ixml.ampm((start_date.hour > 11) ? "PM" : "AM" )
      }

      xml.enddate { |ixml|
        ixml.month "%.2d" % end_date.mon
        ixml.day "%.2d" % end_date.day
        ixml.year end_date.year
        ixml.hour "%.2d" % ampm_hour(end_date.hour)
        ixml.minute "%.2d" % end_date.mon
        ixml.second "%.2d" % end_date.sec
        ixml.ampm((end_date.hour > 11) ? "PM" : "AM" )
      }

      xml.cardtypes { |ixml|
        ixml.visa(card_types.include?("visa") ? 1 : 0)
        ixml.mastercard(card_types.include?("mastercard") ? 1 : 0)
        ixml.amex(card_types.include?("amex") ? 1 : 0)
        ixml.discovernetwork(card_types.include?("discovernetwork") ? 1 : 0)
        ixml.jcb(card_types.include?("jcb") ? 1 : 0)
        ixml.diners(card_types.include?("diners") ? 1 : 0)
        ixml.debit(card_types.include?("debit") ? 1 : 0)
        ixml.flyingj(card_types.include?("flyingj") ? 1 : 0)
        ixml.cfna(card_types.include?("cfna") ? 1 : 0)
        ixml.gemoney(card_types.include?("gemoney") ? 1 : 0)
        ixml.fleetone(card_types.include?("fleetone") ? 1 : 0)
        ixml.fuellnk(card_types.include?("fuellnk") ? 1 : 0)
        ixml.fuelman(card_types.include?("fuelman") ? 1 : 0)
        ixml.mastercardfleet(card_types.include?("mastercardfleet") ? 1 : 0)
        ixml.visafleet(card_types.include?("visafleet") ? 1 : 0)
        ixml.voyager(card_types.include?("voyager") ? 1 : 0)
        ixml.wrightexpress(card_types.include?("wrightexpress") ? 1 : 0)
      }

      xml.transactiontypes { |ixml|
        ixml.ccpreauths(transaction_types.include?("ccpreauths") ? 1 : 0)
        ixml.ccpostauthsales(transaction_types.include?("ccpostauthsales") ? 1 : 0)
        ixml.ccvoids(transaction_types.include?("ccvoids") ? 1 : 0)
        ixml.ccrefunds(transaction_types.include?("ccrefunds") ? 1 : 0)
        ixml.ccchargebacks(transaction_types.include?("ccchargebacks") ? 1 : 0)
        ixml.achpreauths(transaction_types.include?("achpreauths") ? 1 : 0)
        ixml.achsettlements(transaction_types.include?("achsettlements") ? 1 : 0)
        ixml.achreturns(transaction_types.include?("achreturns") ? 1 : 0)
        ixml.achnocs(transaction_types.include?("achnocs") ? 1 : 0)
        ixml.achvoids(transaction_types.include?("achvoids") ? 1 : 0)
        ixml.achcreditsauth(transaction_types.include?("achcreditsauth") ? 1 : 0)
        ixml.achcreditsmerchantdebit(transaction_types.include?("achcreditsmerchantdebit") ? 1 : 0)
        ixml.achcreditsdebitreturn(transaction_types.include?("achcreditsdebitreturn") ? 1 : 0)
        ixml.achcreditsmerchantsettle(transaction_types.include?("achcreditsmerchantsettle") ? 1 : 0)
        ixml.achcreditspaymentsettle(transaction_types.include?("achcreditspaymentsettle") ? 1 : 0)
        ixml.achcreditsreturn(transaction_types.include?("achcreditsreturn") ? 1 : 0)
        ixml.debitsales(transaction_types.include?("debitsales") ? 1 : 0)
        ixml.debitrefunds(transaction_types.include?("debitrefunds") ? 1 : 0)
        ixml.achlatereturns(transaction_types.include?("achlatereturns") ? 1 : 0)
        ixml.extachpreauths(transaction_types.include?("extachpreauths") ? 1 : 0)
        ixml.extachsettlements(transaction_types.include?("extachsettlements") ? 1 : 0)
        ixml.extachreturns(transaction_types.include?("extachreturns") ? 1 : 0)
        ixml.extachnocs(transaction_types.include?("extachnocs") ? 1 : 0)
        ixml.extachvoids(transaction_types.include?("extachvoids") ? 1 : 0)
        ixml.extachcreditsauth(transaction_types.include?("extachcreditsauth") ? 1 : 0)
        ixml.extachcreditssettle(transaction_types.include?("extachcreditssettle") ? 1 : 0)
        ixml.extachcreditsreturn(transaction_types.include?("extachcreditsreturn") ? 1 : 0)
        ixml.extachck21_auth(transaction_types.include?("extachck21_auth") ? 1 : 0)
        ixml.extachck21_void(transaction_types.include?("extachck21_void") ? 1 : 0)
        ixml.extachck21_return(transaction_types.include?("extachck21_return") ? 1 : 0)
        ixml.verfication(transaction_types.include?("verfication") ? 1 : 0)
        ixml.ccincremental(transaction_types.include?("ccincremental") ? 1 : 0)
        ixml.ccreversal(transaction_types.include?("ccreversal") ? 1 : 0)
      }

      xml.limitbycard((card_types.sort == CARD_TYPES.sort) ? 0 : 1 )
      xml.limitbytranstypes((transaction_types.sort == TRANS_TYPES.sort) ? 0 : 1)
      xml.childsubids(childsubids)
      xml.accepted(accepted)
      xml.declined(declined)
      xml.test(test_flag)
      xml.initial(initial_flag)
      xml.recurring(recurring_flag)
      xml.recurringonly(recurring_only)
      xml.recurringretries (recurringretries)
      xml.sort(sort)
      xml.maxrows max_rows
      xml.startrow start_row
      xml.numrows num_rows
      xml.currency('')
    end
  end
end

#get_verification(start_date, end_date) ⇒ Object



241
242
243
244
# File 'lib/prismpay/prismpay_reports.rb', line 241

def get_verification(start_date, end_date)
  get_transactions(start_date, end_date,{:trans_types =>
                     ['verfication']})
end

#hexstr_to_str(str) ⇒ Object



454
455
456
# File 'lib/prismpay/prismpay_reports.rb', line 454

def hexstr_to_str(str)
  [str].pack 'H*'
end

#str_to_hexstr(hexstr) ⇒ Object



449
450
451
# File 'lib/prismpay/prismpay_reports.rb', line 449

def str_to_hexstr(hexstr)
  hexstr.unpack('H*').first
end