prismpay 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,14 +14,14 @@ module PrismPay
14
14
  WSDL = File.expand_path("../TransactionService.xml", __FILE__)
15
15
 
16
16
  ACH_CHECK_ACCT_TYPE = {"checking" => 1, "savings" => 2}
17
- ACH_SEC_CODES = %w(POP, ARC, TEL, PPD, ICL, RCK, BOC)
17
+ ACH_SEC_CODES = %w(POP, ARC, TEL, PPD, ICL, RCK, BOC, CCDN)
18
18
 
19
19
  attr_accessor :acctid, :password
20
20
  attr_reader :client
21
21
 
22
22
  def initialize(options = {})
23
23
  merchant_info = options
24
- merchant_info = {:login => 'TEST0'} unless merchant_info[:login]
24
+ merchant_info.merge!({:login => 'TEST0'}) unless merchant_info[:login]
25
25
 
26
26
  if merchant_info.respond_to?("has_key?")
27
27
  @acctid = merchant_info[:login] if merchant_info.has_key?(:login)
@@ -128,11 +128,23 @@ module PrismPay
128
128
  # coming from a client into a prismpay vendor.
129
129
  ############################################################
130
130
 
131
- def ach_sale
132
- end
131
+ # def ach_sale(amount, bank_account, options ={})
132
+ # response = @client.request :process_ach_sale do
133
+ # http.auth.ssl.verify_mode = :none
134
+ # soap.body &build_ach_sale()
135
+ # end
133
136
 
134
- def ach_credit
135
- end
137
+ # PrismCreditResponse.new(response)
138
+ # end
139
+
140
+ # def ach_credit(amount, auth, pp_txn_id, options = {})
141
+ # response = @client.request :process_ach_credit do
142
+ # http.auth.ssl.verify_mode = :none
143
+ # soap.body &build_ach_credit()
144
+ # end
145
+
146
+ # PrismCreditResponse.new(response)
147
+ # end
136
148
 
137
149
 
138
150
  ############################################################
@@ -142,18 +154,50 @@ module PrismPay
142
154
  # disbursments to a third party as well
143
155
  ############################################################
144
156
 
145
- def ext_ach_sale()
146
- end
157
+ def ext_ach_sale(amount, bank_account, options = {})
158
+ response = @client.request :process_ext_ach_sale do
159
+ http.auth.ssl.verify_mode = :none
160
+ soap.body &build_ext_ach_sale_disburse(amount, bank_account, options)
161
+ end
147
162
 
148
- def ext_ach_void
163
+ PrismCreditResponse.new(response)
149
164
  end
150
165
 
151
- def ext_ach_refund
166
+ ############################################################
167
+ # ext_ach_void doesn't work in generic testing accounts
168
+ ############################################################
169
+ # def ext_ach_void(identification, pp_txn_id, options = {})
170
+ # response = @client.request :process_ext_ach_void do
171
+ # http.auth.ssl.verify_mode = :none
172
+ # soap.body &build_ext_ach_refund_void(nil, identification,
173
+ # pp_txn_id, options)
174
+ # end
175
+
176
+ # PrismCreditResponse.new(response)
177
+ # end
178
+
179
+ def ext_ach_refund(amount, identification, pp_txn_id, options = {})
180
+ response = @client.request :process_ext_ach_credit do
181
+ http.auth.ssl.verify_mode = :none
182
+ soap.body &build_ext_ach_refund_void(amount, identification,
183
+ pp_txn_id, options)
184
+ end
185
+
186
+ PrismCreditResponse.new(response)
152
187
  end
153
188
 
154
- def ext_ach_consumer_disbursement
189
+ def ext_ach_consumer_disbursement(amount, bank_account, options = {})
190
+ response = @client.request :process_ext_ach_consumer_disbursement do
191
+ http.auth.ssl.verify_mode = :none
192
+ soap.body &build_ext_ach_sale_disburse(amount, bank_account, options)
193
+ end
194
+
195
+ PrismCreditResponse.new(response)
155
196
  end
156
197
 
198
+
199
+
200
+ # helper methods
157
201
  private
158
202
 
159
203
  def build_address(addr, type= "bill")
@@ -180,8 +224,8 @@ module PrismPay
180
224
  xml_block = Proc.new { |xml|
181
225
  xml.miscprocess("xsi:type" => "urn:ProfileRetrieve"){
182
226
  xml.acctid @acctid
227
+ xml.merchantpin @password if @password
183
228
  xml.subid options[:subid] if options[:subid]
184
- xml.accountkey @password if @password
185
229
  xml.last4digits options[:last_four]
186
230
  xml.userprofileid options[:profileid]
187
231
  xml.merchantpin options[:merchantpin] if options[:merchantpin]
@@ -196,6 +240,7 @@ module PrismPay
196
240
  xml_block = Proc.new { |xml|
197
241
  xml.miscprocess("xsi:type" => "urn:VoidCreditPost"){
198
242
  xml.acctid @acctid
243
+ xml.merchantpin @password if @password
199
244
  xml.amount amount
200
245
  xml.orderid pp_txn_id
201
246
  xml.historyid id
@@ -211,6 +256,7 @@ module PrismPay
211
256
  xml_block = Proc.new {|xml|
212
257
  xml.miscprocess("xsi:type" => "urn:VoidCreditPost"){
213
258
  xml.acctid @acctid
259
+ xml.merchantpin @password if @password
214
260
  xml.amount amount
215
261
  xml.orderid pp_txn_id
216
262
  # xml.customizedfields{
@@ -234,6 +280,7 @@ module PrismPay
234
280
  xml_block = Proc.new {|xml|
235
281
  xml.miscprocess("xsi:type" => "urn:VoidCreditPost"){
236
282
  xml.acctid @acctid
283
+ xml.merchantpin @password if @password
237
284
  xml.amount amount
238
285
  xml.orderid pp_txn_id
239
286
  xml.historyid auth
@@ -251,7 +298,7 @@ module PrismPay
251
298
 
252
299
  missing_fields_for_options = {
253
300
  :acctid => '',
254
- :accountkey => '',
301
+ :merchantpin => '',
255
302
  :subid => ''
256
303
  }
257
304
 
@@ -311,7 +358,8 @@ module PrismPay
311
358
  xml_block = Proc.new{ |xml|
312
359
  xml.ccinfo("xsi:type" => "urn:CreditCardInfo") {
313
360
  xml.acctid @acctid
314
- xml.accountkey options[:password] if options.has_key?(:password)
361
+ xml.merchantpin @password if @password
362
+ # xml.merchantpin options[:password] if options.has_key?(:password)
315
363
  # xml.subid "xsi:nil" => "true"
316
364
  xml.ccname "#{credit_card.first_name} #{credit_card.last_name}"
317
365
  # xml.swipedata "xsi:nil" => "true"
@@ -365,12 +413,14 @@ module PrismPay
365
413
  return xml_block
366
414
  end
367
415
 
416
+
368
417
  def build_profile_sale(amount, profile_id, last_four, options)
369
418
  # as of now auth is historyid and we need :orderid set in options
370
419
 
371
420
  xml_block = Proc.new {|xml|
372
421
  xml.miscprocess("xsi:type" => "urn:MPTransProcess"){
373
422
  xml.acctid @acctid
423
+ xml.merchantpin @password if @password
374
424
  xml.last4digits last_four
375
425
  xml.userprofileid profile_id
376
426
  xml.amount amount
@@ -381,9 +431,102 @@ module PrismPay
381
431
  end
382
432
 
383
433
 
434
+ def build_ext_ach_sale_disburse(amount, bank_account, options)
435
+ # should probably pass in the companyname under options
436
+ acct_type = "#{bank_account.account_holder_type} " +
437
+ "#{bank_account.account_type}"
438
+
439
+ xml_block = Proc.new { |xml|
440
+ xml.ckinfo("xsi:type" => "urn:ACHInfo"){
441
+ xml.acctid @acctid
442
+ xml.merchantpin(@password) if @password
443
+ xml.ckname bank_account.name
444
+ xml.ckaba bank_account.routing_number
445
+ xml.ckacct bank_account.account_number
446
+ xml.ckno(bank_account.cknumber) if bank_account.number
447
+ xml.amount amount
448
+ if bank_account.account_holder_type =~ /business/i
449
+ xml.cktype('CCD')
450
+ else
451
+ xml.cktype('PPD')
452
+ end
453
+ xml.ckaccttypedesc acct_type
454
+ xml.companyname options[:companyname]
455
+ xml.ipaddress
456
+ }
457
+ }
458
+
459
+ return xml_block
460
+ end
461
+
462
+ def build_ext_ach_refund_void(amount, auth, pp_txn_id, options)
463
+ # should probably pass in the companyname under options
464
+
465
+ xml_block = Proc.new { |xml|
466
+ xml.ckinfo("xsi:type" => "urn:ACHInfo"){
467
+ xml.acctid @acctid
468
+ xml.merchantpin(@password) if @password
469
+ xml.orderid pp_txn_id
470
+ xml.historyid auth
471
+ xml.amount amount if amount
472
+ xml.ipaddress
473
+ }
474
+ }
475
+
476
+ return xml_block
477
+ end
478
+
479
+
480
+
384
481
  end # class PrismPay
385
482
 
386
483
 
484
+ class BankAccount
485
+ # mimic ActiveMerchant check object for compatibility, tesing, and
486
+ # stand alone purposes
487
+
488
+ attr_accessor :first_name, :last_name, :account_number, :routing_number,
489
+ :account_holder_type, :account_type, :cknumber
490
+
491
+ def number=(n)
492
+ @cknumber = n
493
+ end
494
+
495
+ def number
496
+ @cknumber
497
+ end
498
+
499
+ def [](method)
500
+ eval ("self.#{method}")
501
+ end
502
+
503
+ def []=(method, rval)
504
+ eval ("self.#{method} = rval")
505
+ end
506
+
507
+ def name
508
+ [@first_name, @last_name].join(' ')
509
+ end
510
+
511
+ def name=(n)
512
+ names = n.split(' ')
513
+ @first_name = names[0]
514
+ @last_name = names[1]
515
+ end
516
+
517
+ def initialize(checkinfo = {})
518
+ if checkinfo.respond_to?("has_key?")
519
+ @account_number = checkinfo[:account_number] if checkinfo.has_key?(:account_number)
520
+ @name = checkinfo[:name] if checkinfo.has_key?(:name)
521
+ @routing_number = checkinfo[:routing_number] if checkinfo.has_key?(:routing_number)
522
+ @cknumber = checkinfo[:number] if checkinfo.has_key?(:number)
523
+ @account_type = checkinfo[:account_type] if checkinfo.has_key?(:account_type)
524
+ @account_holder_type = checkinfo[:account_holder_type] if checkinfo.has_key?(:account_holder_type)
525
+ end
526
+ end
527
+
528
+ end # BankAccount
529
+
387
530
  class CreditCard
388
531
  # credit card information... mimic ActiveMerchant
389
532
  attr_accessor :number, :month, :year, :first_name,
@@ -407,7 +550,7 @@ module PrismPay
407
550
  eval ("self.#{method} = rval")
408
551
  end
409
552
 
410
- def initialize(ccinfo)
553
+ def initialize(ccinfo = {})
411
554
  if ccinfo.respond_to?("has_key?")
412
555
  @number = ccinfo[:number] if ccinfo.has_key?(:number)
413
556
  @month = ccinfo[:month] if ccinfo.has_key?(:month)
@@ -21,21 +21,26 @@ module ActiveMerchant
21
21
  super
22
22
  end
23
23
 
24
-
25
24
  # Transactions
26
- def check_purchase
25
+ def check_purchase(amount, check, options = {})
26
+ result = @gateway.ext_ach_sale(amount, check, options)
27
+ result.active_merchant_response
28
+ end
29
+
30
+ def check_refund(amount, identification, pp_txn_id, options = {})
31
+
32
+ result = @gateway.ext_ach_refund(amount, identification,
33
+ pp_txn_id, options)
34
+
35
+ result.active_merchant_response
27
36
  end
28
37
 
29
- def check_refund
38
+ def check_consumer_disbursement(amount, check, options = {})
39
+ result = @gateway.ext_ach_consumer_disbursement(amount, check, options)
40
+ result.active_merchant_response
30
41
  end
31
42
 
32
43
  def profile_sale(amount, profile_id, last_four, options = {})
33
- Rails.logger.info "########################################"
34
- Rails.logger.info "# I am getting called"
35
- Rails.logger.info "# amount #{amount}"
36
- Rails.logger.info "# pofile Id #{profile_id}"
37
- Rails.logger.info "# last four #{last_four}"
38
- Rails.logger.info "########################################"
39
44
  result = @gateway.profile_sale(amount, profile_id, last_four, options)
40
45
  result.active_merchant_response
41
46
  end
@@ -56,12 +61,12 @@ module ActiveMerchant
56
61
  end
57
62
 
58
63
  def void(amount, identification, pp_txn_id, options = {})
59
- result = @gateway.cc_void(identification, options)
64
+ result = @gateway.cc_void(amount, identification, pp_txn_id, options)
60
65
  result.active_merchant_response
61
66
  end
62
67
 
63
68
  def refund(amount, identification, pp_txn_id, options ={ })
64
- result = @gateway.credit(amount, identification, options)
69
+ result = @gateway.credit(amount, identification, pp_txn_id, options)
65
70
  result.active_merchant_response
66
71
  end
67
72
  end
@@ -351,3 +351,87 @@ describe PrismPay::PrismPay, "credit" do
351
351
  end
352
352
  end
353
353
 
354
+ describe PrismPay::PrismPay, "ext_ach_sale", :bfd => true do
355
+
356
+ ba = PrismPay::BankAccount.new
357
+ ba[:name] = "George Jones"
358
+ ba[:account_number] = "9999999999"
359
+ ba[:routing_number] = "9999999999"
360
+ ba[:account_holder_type] = 'personal'
361
+ ba[:account_type] = 'checking'
362
+
363
+ amount = "1.22"
364
+
365
+ options = {
366
+ :login => "TEST0",
367
+ :order_id => Time.now.strftime("%y%m%d%H%M%S"),
368
+ }
369
+
370
+ gateway = PrismPay::PrismPay.new(options)
371
+
372
+
373
+ it "should transact sale with a call to ext_ach_sale" do
374
+
375
+ response = gateway.ext_ach_sale(amount, ba, options).soap_response
376
+ response.body[:multi_ref][:status].should =~ /Approved/
377
+
378
+ save_refund_trans(response.body[:multi_ref][:orderid],
379
+ response.body[:multi_ref][:historyid],
380
+ amount)
381
+
382
+ amount2 = 5.55
383
+
384
+ response = gateway.ext_ach_sale(amount, ba, options).soap_response
385
+
386
+ save_void_trans(response.body[:multi_ref][:orderid],
387
+ response.body[:multi_ref][:historyid],
388
+ amount)
389
+
390
+
391
+ end
392
+
393
+
394
+ it "should transact an ext_ach_consumer_disbursement" do
395
+
396
+ response = gateway.ext_ach_consumer_disbursement(amount, ba, options).soap_response
397
+ response.body[:multi_ref][:status].should =~ /Approved/
398
+
399
+
400
+ end
401
+
402
+
403
+ it "should void a previous transaction" do
404
+ values = get_last_trans("./void~")
405
+
406
+ orderid = values[:order_id]
407
+ authcode = values[:historyid]
408
+ amount = values[:amount]
409
+
410
+ response = gateway.ext_ach_void(amount, authcode, orderid).soap_response
411
+ response.body[:multi_ref][:status].should =~ /Approved/
412
+
413
+ if response.body[:multi_ref][:status] =~ /Approved/
414
+ processed_trans "#{orderid}:#{authcode}:#{amount}\n", "./void~"
415
+ end
416
+
417
+ end
418
+
419
+
420
+ it "should refund a transaction" do
421
+ values = get_last_trans("./credit~")
422
+
423
+ orderid = values[:order_id]
424
+ authcode = values[:historyid]
425
+ amount = values[:amount]
426
+
427
+ response = gateway.ext_ach_refund(amount, authcode, orderid).soap_response
428
+ response.body[:multi_ref][:status].should =~ /Approved/
429
+
430
+ if response.body[:multi_ref][:status] =~ /Approved/
431
+ processed_trans "#{orderid}:#{authcode}:#{amount}\n", "./credit~"
432
+ end
433
+
434
+ end
435
+
436
+ end
437
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prismpay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: