lib/active_merchant/billing/gateways/card_stream.rb in activemerchant-1.58.0 vs lib/active_merchant/billing/gateways/card_stream.rb in activemerchant-1.59.0
- old
+ new
@@ -73,25 +73,25 @@
@threeds_required = options[:threeDSRequired]
end
super
end
- def authorize(money, creditcard, options = {})
+ def authorize(money, credit_card_or_reference, options = {})
post = {}
add_pair(post, :captureDelay, -1)
add_amount(post, money, options)
- add_invoice(post, creditcard, money, options)
- add_creditcard(post, creditcard)
+ add_invoice(post, credit_card_or_reference, money, options)
+ add_credit_card_or_reference(post, credit_card_or_reference)
add_customer_data(post, options)
commit('SALE', post)
end
- def purchase(money, creditcard, options = {})
+ def purchase(money, credit_card_or_reference, options = {})
post = {}
add_amount(post, money, options)
- add_invoice(post, creditcard, money, options)
- add_creditcard(post, creditcard)
+ add_invoice(post, credit_card_or_reference, money, options)
+ add_credit_card_or_reference(post, credit_card_or_reference)
add_customer_data(post, options)
commit('SALE', post)
end
def capture(money, authorization, options = {})
@@ -110,11 +110,11 @@
end
def void(authorization, options = {})
post = {}
add_pair(post, :xref, authorization)
- commit('REFUND', post)
+ commit('CANCEL', post)
end
def verify(creditcard, options={})
MultiResponse.run(:use_first_response) do |r|
r.process { authorize(100, creditcard, options) }
@@ -147,24 +147,38 @@
add_pair(post, :customerPostCode, address[:zip])
add_pair(post, :customerPhone, options[:phone])
end
end
- def add_invoice(post, credit_card, money, options)
+ def add_invoice(post, credit_card_or_reference, 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))
+ if credit_card_or_reference.respond_to?(:number)
+ if ['american_express', 'diners_club'].include?(card_brand(credit_card_or_reference).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
end
add_pair(post, :type, options[:type] || '1')
add_threeds_required(post, options)
end
- def add_creditcard(post, credit_card)
+ def add_credit_card_or_reference(post, credit_card_or_reference)
+ if credit_card_or_reference.respond_to?(:number)
+ add_credit_card(post, credit_card_or_reference)
+ else
+ add_reference(post, credit_card_or_reference.to_s)
+ end
+ end
+
+ def add_reference(post, reference)
+ add_pair(post, :xref, reference, :required => true)
+ end
+
+ def add_credit_card(post, credit_card)
add_pair(post, :customerName, credit_card.name, :required => true)
add_pair(post, :cardNumber, credit_card.number, :required => true)
add_pair(post, :cardExpiryMonth, format(credit_card.month, :two_digits), :required => true)
add_pair(post, :cardExpiryYear, format(credit_card.year, :two_digits), :required => true)
@@ -181,12 +195,16 @@
def add_threeds_required(post, options)
add_pair(post, :threeDSRequired, (options[:threeds_required] || @threeds_required) ? 'Y' : 'N')
end
+ def normalize_line_endings(str)
+ str.gsub(/%0D%0A|%0A%0D|%0D/, "%0A")
+ end
+
def add_hmac(post)
- result = post.sort.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
+ result = post.sort.collect { |key, value| "#{key}=#{normalize_line_endings(CGI.escape(value.to_s))}" }.join("&")
result = Digest::SHA512.hexdigest("#{result}#{@options[:shared_secret]}")
add_pair(post, :signature, result)
end
@@ -200,10 +218,10 @@
end
result
end
def commit(action, parameters)
- parameters.update(:countryCode => self.supported_countries[0]) unless action == 'CAPTURE'
+ parameters.update(:countryCode => self.supported_countries[0]) unless ['CAPTURE', 'CANCEL'].include?(action)
parameters.update(
:merchantID => @options[:login],
:action => action
)
# adds a signature to the post hash/array