lib/active_merchant/billing/gateways/cyber_source.rb in activemerchant-1.29.3 vs lib/active_merchant/billing/gateways/cyber_source.rb in activemerchant-1.30.0

- old
+ new

@@ -11,10 +11,11 @@ # transaction information from a general transaction search inside the # CyberSource Business Center for the full error messages including field # names. # # Important Notes + # * For checks you can purchase and store. # * AVS and CVV only work against the production server. You will always # get back X for AVS and no response for CVV against the test server. # * Nexus is the list of states or provinces where you have a physical # presence. Nexus is used to calculate tax. Leave blank to tax everyone. # * If you want to calculate VAT for overseas customers you must supply a @@ -129,14 +130,14 @@ commit(build_capture_request(money, authorization, options), options) end # Purchase is an auth followed by a capture # You must supply an order_id in the options hash - def purchase(money, creditcard_or_reference, options = {}) + def purchase(money, payment_method_or_reference, options = {}) requires!(options, :order_id) setup_address_hash(options) - commit(build_purchase_request(money, creditcard_or_reference, options), options) + commit(build_purchase_request(money, payment_method_or_reference, options), options) end def void(identification, options = {}) commit(build_void_request(identification, options), options) end @@ -152,14 +153,14 @@ 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(creditcard, options = {}) + def store(payment_method, options = {}) requires!(options, :order_id) setup_address_hash(options) - commit(build_create_subscription_request(creditcard, options), options) + commit(build_create_subscription_request(payment_method, options), options) end # Updates a customer subscription/profile def update(reference, creditcard, options = {}) requires!(options, :order_id) @@ -220,11 +221,11 @@ options[:shipping_address] = options[:shipping_address] || {} end def build_auth_request(money, creditcard_or_reference, options) xml = Builder::XmlMarkup.new :indent => 2 - add_creditcard_or_subscription(xml, money, creditcard_or_reference, options) + add_payment_method_or_subscription(xml, money, creditcard_or_reference, options) add_auth_service(xml) add_business_rules_data(xml) xml.target! end @@ -248,15 +249,19 @@ add_capture_service(xml, request_id, request_token) add_business_rules_data(xml) xml.target! end - def build_purchase_request(money, creditcard_or_reference, options) + def build_purchase_request(money, payment_method_or_reference, options) xml = Builder::XmlMarkup.new :indent => 2 - add_creditcard_or_subscription(xml, money, creditcard_or_reference, options) - add_purchase_service(xml, options) - add_business_rules_data(xml) + add_payment_method_or_subscription(xml, money, payment_method_or_reference, options) + if(payment_method_or_reference.respond_to?(:check?) && payment_method_or_reference.check?) + add_check_service(xml) + else + add_purchase_service(xml, options) + add_business_rules_data(xml) + end xml.target! end def build_void_request(identification, options) order_id, request_id, request_token = identification.split(";") @@ -295,20 +300,26 @@ add_credit_service(xml) xml.target! end - def build_create_subscription_request(creditcard, options) + def build_create_subscription_request(payment_method, options) options[:subscription] = (options[:subscription] || {}).merge(:frequency => "on-demand", :amount => 0, :automatic_renew => false) xml = Builder::XmlMarkup.new :indent => 2 - add_address(xml, creditcard, options[:billing_address], options) + add_address(xml, payment_method, options[:billing_address], options) add_purchase_data(xml, options[:setup_fee] || 0, true, options) - add_creditcard(xml, creditcard) - add_creditcard_payment_method(xml) + if payment_method.check? + add_check(xml, payment_method) + add_check_payment_method(xml) + add_check_service(xml, options) if options[:setup_fee] + else + add_creditcard(xml, payment_method) + add_creditcard_payment_method(xml) + add_purchase_service(xml, options) if options[:setup_fee] + end add_subscription(xml, options) - add_purchase_service(xml, options) if options[:setup_fee] add_subscription_create_service(xml, options) add_business_rules_data(xml) xml.target! end @@ -370,16 +381,16 @@ xml.tag! 'currency', options[:currency] || currency(money) xml.tag!('grandTotalAmount', amount(money)) if include_grand_total end end - def add_address(xml, creditcard, address, options, shipTo = false) + def add_address(xml, payment_method, address, options, shipTo = false) requires!(options, :email) xml.tag! shipTo ? 'shipTo' : 'billTo' do - xml.tag! 'firstName', creditcard.first_name if creditcard - xml.tag! 'lastName', creditcard.last_name if creditcard + xml.tag! 'firstName', payment_method.first_name if payment_method + xml.tag! 'lastName', payment_method.last_name if payment_method xml.tag! 'street1', address[:address1] xml.tag! 'street2', address[:address2] unless address[:address2].blank? xml.tag! 'city', address[:city] xml.tag! 'state', address[:state] xml.tag! 'postalCode', address[:zip] @@ -401,10 +412,18 @@ 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_check(xml, check) + xml.tag! 'check' do + xml.tag! 'accountNumber', check.account_number + xml.tag! 'accountType', check.account_type[0] + xml.tag! 'bankTransitNumber', check.routing_number + end + end + def add_tax_service(xml) xml.tag! 'taxService', {'run' => 'true'} do xml.tag!('nexus', @options[:nexus]) unless @options[:nexus].blank? xml.tag!('sellerRegistration', @options[:vat_reg_number]) unless @options[:vat_reg_number].blank? end @@ -445,10 +464,14 @@ xml.tag! 'captureRequestID', request_id if request_id xml.tag! 'captureRequestToken', request_token if request_token end end + def add_check_service(xml) + xml.tag! 'ecDebitService', {'run' => 'true'} + end + def add_subscription_create_service(xml, options) xml.tag! 'paySubscriptionCreateService', {'run' => 'true'} end def add_subscription_update_service(xml, options) @@ -489,17 +512,27 @@ xml.tag! 'subscription' do xml.tag! 'paymentMethod', "credit card" end end - def add_creditcard_or_subscription(xml, money, creditcard_or_reference, options) - if creditcard_or_reference.is_a?(String) + def add_check_payment_method(xml) + xml.tag! 'subscription' do + xml.tag! 'paymentMethod', "check" + end + end + + def add_payment_method_or_subscription(xml, money, payment_method_or_reference, options) + if payment_method_or_reference.is_a?(String) add_purchase_data(xml, money, true, options) - add_subscription(xml, options, creditcard_or_reference) + add_subscription(xml, options, payment_method_or_reference) + elsif payment_method_or_reference.check? + add_address(xml, payment_method_or_reference, options[:billing_address], options) + add_purchase_data(xml, money, true, options) + add_check(xml, payment_method_or_reference) else - add_address(xml, creditcard_or_reference, options[:billing_address], options) + add_address(xml, payment_method_or_reference, options[:billing_address], options) add_purchase_data(xml, money, true, options) - add_creditcard(xml, creditcard_or_reference) + add_creditcard(xml, payment_method_or_reference) end end # Where we actually build the full SOAP request using builder def build_request(body, options)