lib/active_merchant/billing/gateways/cyber_source.rb in activemerchant-1.107.3 vs lib/active_merchant/billing/gateways/cyber_source.rb in activemerchant-1.107.4
- old
+ new
@@ -32,10 +32,11 @@
master: 'spa',
american_express: 'aesk',
jcb: 'js',
discover: 'pb',
}.freeze
+ DEFAULT_COLLECTION_INDICATOR = 2
self.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners_club, :jcb, :dankort, :maestro, :elo]
self.supported_countries = %w(US BR CA CN DK FI FR DE IN JP MX NO SE GB SG LB PK)
self.default_currency = 'USD'
@@ -324,11 +325,13 @@
else
add_purchase_service(xml, payment_method_or_reference, options)
add_threeds_services(xml, options)
add_payment_network_token(xml) if network_tokenization?(payment_method_or_reference)
add_business_rules_data(xml, payment_method_or_reference, options) unless options[:pinless_debit_card]
+ add_stored_credential_options(xml, options)
end
+
add_issuer_additional_data(xml, options)
add_merchant_description(xml, options)
add_partner_solution_id(xml)
xml.target!
@@ -622,16 +625,17 @@
def add_threeds_2_ucaf_data(xml, payment_method, options)
return unless options[:three_d_secure] && card_brand(payment_method).to_sym == :master
xml.tag! 'ucaf' do
xml.tag!('authenticationData', options[:three_d_secure][:cavv])
- xml.tag!('collectionIndicator', options[:collection_indicator]) if options[:collection_indicator]
+ xml.tag!('collectionIndicator', options[:collection_indicator] || DEFAULT_COLLECTION_INDICATOR)
end
end
def stored_credential_commerce_indicator(options)
return unless options[:stored_credential]
+
return if options[:stored_credential][:initial_transaction]
case options[:stored_credential][:reason_type]
when 'installment' then 'install'
when 'recurring' then 'recurring'
@@ -642,10 +646,11 @@
payment_method.is_a?(NetworkTokenizationCreditCard)
end
def add_auth_network_tokenization(xml, payment_method, options)
return unless network_tokenization?(payment_method)
+
brand = card_brand(payment_method).to_sym
case brand
when :visa
xml.tag! 'ccAuthService', {'run' => 'true'} do
@@ -654,11 +659,11 @@
xml.tag!('xid', payment_method.payment_cryptogram)
end
when :master
xml.tag! 'ucaf' do
xml.tag!('authenticationData', payment_method.payment_cryptogram)
- xml.tag!('collectionIndicator', '2')
+ xml.tag!('collectionIndicator', DEFAULT_COLLECTION_INDICATOR)
end
xml.tag! 'ccAuthService', {'run' => 'true'} do
xml.tag!('commerceIndicator', ECI_BRAND_MAPPING[brand])
end
when :american_express
@@ -813,19 +818,14 @@
country_code&.code(:alpha2)
end
def add_stored_credential_options(xml, options={})
return unless options[:stored_credential]
-
- if options[:stored_credential][:initial_transaction]
- xml.tag! 'subsequentAuthFirst', 'true'
- elsif options[:stored_credential][:reason_type] == 'unscheduled'
- xml.tag! 'subsequentAuth', 'true'
- xml.tag! 'subsequentAuthTransactionID', options[:stored_credential][:network_transaction_id]
- else
- xml.tag! 'subsequentAuthTransactionID', options[:stored_credential][:network_transaction_id]
- end
+ xml.tag! 'subsequentAuth', 'true' if options[:stored_credential][:initiator] == 'merchant'
+ xml.tag! 'subsequentAuthFirst', 'true' if options[:stored_credential][:initial_transaction]
+ xml.tag! 'subsequentAuthTransactionID', options[:stored_credential][:network_transaction_id] if options[:stored_credential][:initiator] == 'merchant'
+ xml.tag! 'subsequentAuthStoredCredential', 'true' if options[:stored_credential][:initiator] == 'cardholder' && !options[:stored_credential][:initial_transaction] || options[:stored_credential][:initiator] == 'merchant' && options[:stored_credential][:reason_type] == 'unscheduled'
end
def add_partner_solution_id(xml)
return unless application_id
@@ -871,11 +871,11 @@
rescue REXML::ParseException => e
response = { message: e.to_s }
end
success = success?(response)
- message = response[:message]
+ message = message_from(response)
authorization = success ? authorization_from(response, action, amount, options) : nil
Response.new(success, message, response,
test: test?,
@@ -937,9 +937,19 @@
response[:decision] == @@decision_codes[:review]
end
def success?(response)
response[:decision] == @@decision_codes[:accept]
+ end
+
+ def message_from(response)
+ if response[:reasonCode] == '101' && response[:missingField]
+ "#{response[:message]}: #{response[:missingField]}"
+ elsif response[:reasonCode] == '102' && response[:invalidField]
+ "#{response[:message]}: #{response[:invalidField]}"
+ else
+ response[:message]
+ end
end
end
end
end