./lib/ews/transaction/request.rb in exact4r-0.9 vs ./lib/ews/transaction/request.rb in exact4r-0.9.1
- old
+ new
@@ -48,13 +48,28 @@
include Validator
# yeah, it's ugly, but otherwise RDoc won't pick them up
attr_accessor :errors
attr_accessor :gateway_id, :password, :transaction_type, :amount, :surcharge_amount, :cc_number, :transaction_tag, :track1, :track2, :pan, :authorization_num, :cc_expiry, :cardholder_name
- attr_accessor :cc_verification_str1, :cc_verification_str2, :cvd_presence_ind, :tax1_amount, :tax1_number, :tax2_amount, :tax2_number, :secure_auth_required, :secure_auth_result
+ attr_accessor :cc_verification_str2, :cvd_presence_ind, :tax1_amount, :tax1_number, :tax2_amount, :tax2_number, :secure_auth_required, :secure_auth_result
+
+ # AVS - Address Verification,
+ attr_accessor :cc_verification_str1
+ [:avs_test_flag, :avs_street_address, :avs_unit_no, :avs_po_box, :avs_postal_code].each { |m|
+ class_eval <<-METHOD_EOS
+ def #{m.to_s}
+ @#{m.to_s}
+ end
+ def #{m.to_s}=(v)
+ @#{m.to_s} = v
+ calculate_verification_str1
+ end
+ METHOD_EOS
+ }
+
attr_accessor :ecommerce_flag, :xid, :cavv, :cavv_algorithm, :reference_no, :customer_ref, :reference_3, :language, :client_ip, :client_email, :zip_code
-
+
# Initialize a Request with a hash of values
def initialize(hash = {})
hash.each {|k,v| self.send "#{k.to_s}=", v}
@errors = {}
end
@@ -102,9 +117,23 @@
:idebit_refund => '54',
:secure_storage => '60',
:secure_storage_eft => '61',
:transaction_details => 'CR'
}.freeze unless defined?(@@transaction_codes)
-
+
+ # Calculate verification str1, callback method invoked after the avs_*= methods
+ def calculate_verification_str1
+ self.cc_verification_str1 = ''
+ self.cc_verification_str1 << (self.avs_test_flag || '')
+ unless self.avs_street_address.nil?
+ self.cc_verification_str1 << (self.avs_street_address || '')
+ self.cc_verification_str1 << (self.avs_unit_no || '')
+ else
+ self.cc_verification_str1 << (self.avs_po_box || '')
+ end
+ unless self.avs_postal_code.nil?
+ self.cc_verification_str1 << '|' << self.avs_postal_code
+ end
+ end
end
end
-end
\ No newline at end of file
+end