lib/active_merchant/billing/gateways/cyber_source.rb in activemerchant-1.59.0 vs lib/active_merchant/billing/gateways/cyber_source.rb in activemerchant-1.60.0

- old
+ new

@@ -118,11 +118,10 @@ # Request an authorization for an amount from CyberSource # # You must supply an :order_id in the options hash def authorize(money, creditcard_or_reference, options = {}) - requires!(options, :order_id) setup_address_hash(options) commit(build_auth_request(money, creditcard_or_reference, options), options ) end def auth_reversal(money, identification, options = {}) @@ -137,11 +136,10 @@ # Purchase is an auth followed by a capture # You must supply an order_id in the options hash # options[:pinless_debit_card] => true # attempts to process as pinless debit card def purchase(money, payment_method_or_reference, options = {}) - requires!(options, :order_id) setup_address_hash(options) commit(build_purchase_request(money, payment_method_or_reference, options), options) end def void(identification, options = {}) @@ -159,19 +157,17 @@ 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 # Stores a customer subscription/profile with type "on-demand". # To charge the card while creating a profile, pass # options[:setup_fee] => money def store(payment_method, options = {}) - requires!(options, :order_id) setup_address_hash(options) commit(build_create_subscription_request(payment_method, options), options) end # Updates a customer subscription/profile @@ -250,19 +246,27 @@ end private # Create all address hash key value pairs so that we still function if we - # were only provided with one or two of them + # were only provided with one or two of them or even none def setup_address_hash(options) - options[:billing_address] = options[:billing_address] || options[:address] || {} + default_address = { + :address1 => 'Unspecified', + :city => 'Unspecified', + :state => 'NC', + :zip => '00000', + :country => 'US' + } + options[:billing_address] = options[:billing_address] || options[:address] || default_address options[:shipping_address] = options[:shipping_address] || {} end 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_decision_manager_fields(xml, options) add_mdd_fields(xml, options) add_auth_service(xml, creditcard_or_reference, options) add_business_rules_data(xml, creditcard_or_reference, options) xml.target! end @@ -290,10 +294,11 @@ 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) + add_decision_manager_fields(xml, options) add_mdd_fields(xml, 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, payment_method_or_reference, options) @@ -433,11 +438,11 @@ end end def add_merchant_data(xml, options) xml.tag! 'merchantID', @options[:login] - xml.tag! 'merchantReferenceCode', options[:order_id] + xml.tag! 'merchantReferenceCode', options[:order_id] || generate_unique_id xml.tag! 'clientLibrary' ,'Ruby Active Merchant' xml.tag! 'clientLibraryVersion', VERSION xml.tag! 'clientEnvironment' , RUBY_PLATFORM end @@ -459,11 +464,11 @@ xml.tag! 'postalCode', address[:zip] xml.tag! 'country', address[:country] xml.tag! 'company', address[:company] unless address[:company].blank? xml.tag! 'companyTaxID', address[:companyTaxID] unless address[:company_tax_id].blank? xml.tag! 'phoneNumber', address[:phone] unless address[:phone].blank? - xml.tag! 'email', options[:email] + xml.tag! 'email', options[:email] || 'null@cybersource.com' xml.tag! 'ipAddress', options[:ip] unless options[:ip].blank? || shipTo xml.tag! 'driversLicenseNumber', options[:drivers_license_number] unless options[:drivers_license_number].blank? xml.tag! 'driversLicenseState', options[:drivers_license_state] unless options[:drivers_license_state].blank? end end @@ -473,9 +478,16 @@ xml.tag! 'accountNumber', creditcard.number xml.tag! 'expirationMonth', format(creditcard.month, :two_digits) xml.tag! 'expirationYear', format(creditcard.year, :four_digits) xml.tag!('cvNumber', creditcard.verification_value) unless (@options[:ignore_cvv] || creditcard.verification_value.blank? ) xml.tag! 'cardType', @@credit_card_codes[card_brand(creditcard).to_sym] + end + end + + def add_decision_manager_fields(xml, options) + xml.tag! 'decisionManager' do + xml.tag! 'enabled', options[:decision_manager_enabled] if options[:decision_manager_enabled] + xml.tag! 'profile', options[:decision_manager_profile] if options[:decision_manager_profile] end end def add_mdd_fields(xml, options) xml.tag! 'merchantDefinedData' do