lib/active_merchant/billing/gateways/cyber_source.rb in activemerchant-1.45.0 vs lib/active_merchant/billing/gateways/cyber_source.rb in activemerchant-1.46.0

- old
+ new

@@ -148,10 +148,17 @@ def refund(money, identification, options = {}) commit(build_refund_request(money, identification, options), options) end + def verify(payment, options = {}) + MultiResponse.run(:use_first_response) do |r| + r.process { authorize(100, payment, options) } + r.process(:ignore_result) { void(r.authorization, options) } + end + end + # Adds credit to a subscription (stand alone credit). def credit(money, reference, options = {}) requires!(options, :order_id) commit(build_credit_request(money, reference, options), options) end @@ -233,44 +240,44 @@ def build_auth_request(money, creditcard_or_reference, options) xml = Builder::XmlMarkup.new :indent => 2 add_payment_method_or_subscription(xml, money, creditcard_or_reference, options) add_auth_service(xml) - add_business_rules_data(xml) + add_business_rules_data(xml, options) xml.target! end def build_tax_calculation_request(creditcard, options) xml = Builder::XmlMarkup.new :indent => 2 add_address(xml, creditcard, options[:billing_address], options, false) add_address(xml, creditcard, options[:shipping_address], options, true) add_line_item_data(xml, options) add_purchase_data(xml, 0, false, options) add_tax_service(xml) - add_business_rules_data(xml) + add_business_rules_data(xml, options) xml.target! end def build_capture_request(money, authorization, options) order_id, request_id, request_token = authorization.split(";") options[:order_id] = order_id xml = Builder::XmlMarkup.new :indent => 2 add_purchase_data(xml, money, true, options) add_capture_service(xml, request_id, request_token) - add_business_rules_data(xml) + add_business_rules_data(xml, options) xml.target! end def build_purchase_request(money, payment_method_or_reference, options) xml = Builder::XmlMarkup.new :indent => 2 add_payment_method_or_subscription(xml, money, payment_method_or_reference, options) if !payment_method_or_reference.is_a?(String) && card_brand(payment_method_or_reference) == 'check' add_check_service(xml) else add_purchase_service(xml, options) - add_business_rules_data(xml) unless options[:pinless_debit_card] + add_business_rules_data(xml, options) unless options[:pinless_debit_card] end xml.target! end def build_void_request(identification, options) @@ -335,11 +342,11 @@ else add_purchase_service(xml, options) end end add_subscription_create_service(xml, options) - add_business_rules_data(xml) + add_business_rules_data(xml, options) xml.target! end def build_update_subscription_request(reference, creditcard, options) xml = Builder::XmlMarkup.new :indent => 2 @@ -347,11 +354,11 @@ add_purchase_data(xml, options[:setup_fee], true, options) unless options[:setup_fee].blank? add_creditcard(xml, creditcard) if creditcard add_creditcard_payment_method(xml) if creditcard add_subscription(xml, options, reference) add_subscription_update_service(xml, options) - add_business_rules_data(xml) + add_business_rules_data(xml, options) xml.target! end def build_delete_subscription_request(reference, options) xml = Builder::XmlMarkup.new :indent => 2 @@ -372,14 +379,23 @@ add_creditcard(xml, creditcard) add_validate_pinless_debit_service(xml) xml.target! end - def add_business_rules_data(xml) + def add_business_rules_data(xml, options) + prioritized_options = [options, @options] + xml.tag! 'businessRules' do - xml.tag!('ignoreAVSResult', 'true') if @options[:ignore_avs] - xml.tag!('ignoreCVResult', 'true') if @options[:ignore_cvv] + xml.tag!('ignoreAVSResult', 'true') if extract_option(prioritized_options, :ignore_avs) + xml.tag!('ignoreCVResult', 'true') if extract_option(prioritized_options, :ignore_cvv) end + end + + def extract_option prioritized_options, option_name + options_matching_key = prioritized_options.detect do |options| + options.has_key? option_name + end + options_matching_key[option_name] if options_matching_key end def add_line_item_data(xml, options) options[:line_items].each_with_index do |value, index| xml.tag! 'item', {'id' => index} do