lib/active_merchant/billing/gateways/card_stream.rb in activemerchant-1.52.0 vs lib/active_merchant/billing/gateways/card_stream.rb in activemerchant-1.53.0

- old
+ new

@@ -1,8 +1,11 @@ module ActiveMerchant #:nodoc: module Billing #:nodoc: class CardStreamGateway < Gateway + + THREEDSECURE_REQUIRED_DEPRECATION_MESSAGE = "Specifying the :threeDSRequired initialization option is deprecated. Please use the `:threeds_required => true` *transaction* option instead." + self.test_url = self.live_url = 'https://gateway.cardstream.com/direct/' self.money_format = :cents self.default_currency = 'GBP' self.supported_countries = ['GB', 'US', 'CH', 'SE', 'SG', 'NO', 'JP', 'IS', 'HK', 'NL', 'CZ', 'CA', 'AU'] self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover, :jcb, :maestro, :solo, :switch] @@ -59,34 +62,32 @@ "8" => "N" } def initialize(options = {}) requires!(options, :login, :shared_secret) + @threeds_required = false if (options[:threeDSRequired]) - @threeDSRequired = options[:threeDSRequired] - else - @threeDSRequired = 'N' + ActiveMerchant.deprecated(THREEDSECURE_REQUIRED_DEPRECATION_MESSAGE) + @threeds_required = options[:threeDSRequired] end super end def authorize(money, creditcard, options = {}) post = {} add_amount(post, money, options) add_invoice(post, creditcard, money, options) add_creditcard(post, creditcard) - add_address(post, creditcard, options) add_customer_data(post, options) commit('PREAUTH', post) end def purchase(money, creditcard, options = {}) post = {} add_amount(post, money, options) add_invoice(post, creditcard, money, options) add_creditcard(post, creditcard) - add_address(post, creditcard, options) add_customer_data(post, options) commit('SALE', post) end def capture(money, authorization, options = {}) @@ -133,33 +134,29 @@ add_pair(post, :amount, amount(money), :required => true) add_pair(post, :currencyCode, currency_code(options[:currency] || currency(money)) || currency_code(self.default_currency)) end def add_customer_data(post, options) - address = options[:billing_address] || options[:address] - add_pair(post, :customerPostCode, address[:zip]) add_pair(post, :customerEmail, options[:email]) - add_pair(post, :customerPhone, options[:phone]) + if (address = options[:billing_address] || options[:address]) + add_pair(post, :customerAddress, "#{address[:address1]} #{address[:address2]}".strip) + add_pair(post, :customerPostCode, address[:zip]) + add_pair(post, :customerPhone, options[:phone]) + end end - def add_address(post, creditcard, options) - address = options[:billing_address] || options[:address] - - return if address.nil? - - add_pair(post, :customerAddress, address[:address1] + " " + (address[:address2].nil? ? "" : address[:address2])) - add_pair(post, :customerPostCode, address[:zip]) - end - def add_invoice(post, credit_card, money, options) add_pair(post, :transactionUnique, options[:order_id], :required => true) add_pair(post, :orderRef, options[:description] || options[:order_id], :required => true) if ['american_express', 'diners_club'].include?(card_brand(credit_card).to_s) add_pair(post, :item1Quantity, 1) add_pair(post, :item1Description, (options[:description] || options[:order_id]).slice(0, 15)) add_pair(post, :item1GrossValue, amount(money)) end + + add_pair(post, :threeDSRequired, (options[:threeds_required] || @threeds_required) ? 'Y' : 'N') + add_pair(post, :type, options[:type] || '1') end def add_creditcard(post, credit_card) add_pair(post, :customerName, credit_card.name, :required => true) add_pair(post, :cardNumber, credit_card.number, :required => true) @@ -198,12 +195,10 @@ def commit(action, parameters) parameters.update( :merchantID => @options[:login], :action => action, - :type => '1', #Ecommerce :countryCode => self.supported_countries[0], - :threeDSRequired => @threeDSRequired #Disable 3d secure by default ) # adds a signature to the post hash/array add_hmac(parameters) response = parse(ssl_post(self.live_url, post_data(action, parameters)))