lib/active_merchant/billing/gateways/securion_pay.rb in activemerchant-1.126.0 vs lib/active_merchant/billing/gateways/securion_pay.rb in activemerchant-1.129.0
- old
+ new
@@ -131,17 +131,52 @@
post = {}
add_amount(post, money, options, true)
add_creditcard(post, payment, options)
add_customer(post, payment, options)
add_customer_data(post, options)
+ add_external_three_ds(post, options)
if options[:email]
post[:metadata] = {}
post[:metadata][:email] = options[:email]
end
post
end
+ def add_external_three_ds(post, options)
+ return if options[:three_d_secure].blank?
+
+ post[:threeDSecure] = {
+ external: {
+ version: options[:three_d_secure][:version],
+ authenticationValue: options[:three_d_secure][:cavv],
+ acsTransactionId: options[:three_d_secure][:acs_transaction_id],
+ status: options[:three_d_secure][:authentication_response_status],
+ eci: options[:three_d_secure][:eci]
+ }.merge(xid_or_ds_trans_id(options[:three_d_secure]))
+ }
+ end
+
+ def xid_or_ds_trans_id(three_ds)
+ if three_ds[:version].to_f >= 2.0
+ { dsTransactionId: three_ds[:ds_transaction_id] }
+ else
+ { xid: three_ds[:xid] }
+ end
+ end
+
+ def validate_three_ds_params(three_ds)
+ errors = {}
+ supported_version = %w{1.0.2 2.1.0 2.2.0}.include?(three_ds[:version])
+ supported_auth_response = ['Y', 'N', 'U', 'R', 'E', 'A', nil].include?(three_ds[:status])
+
+ errors[:three_ds_version] = 'ThreeDs version not supported' unless supported_version
+ errors[:auth_response] = 'Authentication response value not supported' unless supported_auth_response
+ errors.compact!
+
+ errors.present? ? Response.new(false, 'ThreeDs data is invalid', errors) : nil
+ end
+
def add_amount(post, money, options, include_currency = false)
currency = (options[:currency] || default_currency)
post[:amount] = localized_amount(money, currency)
post[:currency] = currency.downcase if include_currency
end
@@ -180,9 +215,14 @@
def parse(body)
JSON.parse(body)
end
def commit(url, parameters = nil, options = {}, method = nil)
+ if parameters.present? && parameters[:threeDSecure].present?
+ three_ds_errors = validate_three_ds_params(parameters[:threeDSecure][:external])
+ return three_ds_errors if three_ds_errors
+ end
+
response = api_request(url, parameters, options, method)
success = !response.key?('error')
Response.new(success,
(success ? 'Transaction approved' : response['error']['message']),