lib/active_merchant/billing/gateways/moneris.rb in tanga_activemerchant-1.37.0 vs lib/active_merchant/billing/gateways/moneris.rb in tanga_activemerchant-1.38.0
- old
+ new
@@ -126,10 +126,11 @@
if source.is_a?(String)
post[:data_key] = source
else
post[:pan] = source.number
post[:expdate] = expdate(source)
+ post[:cvd_value] = source.verification_value if source.verification_value?
end
end
# Common params used amongst the +credit+, +void+ and +capture+ methods
def crediting_params(authorization, options = {})
@@ -153,10 +154,11 @@
def commit(action, parameters = {})
response = parse(ssl_post(test? ? self.test_url : self.live_url, post_data(action, parameters)))
Response.new(successful?(response), message_from(response[:message]), response,
:test => test?,
+ :cvv_result => response[:cvd_result_code].try(:last),
:authorization => authorization_from(response)
)
end
# Generates a Moneris authorization string of the form 'trans_id;receipt_id'.
@@ -190,20 +192,41 @@
def post_data(action, parameters = {})
xml = REXML::Document.new
root = xml.add_element("request")
root.add_element("store_id").text = options[:login]
root.add_element("api_token").text = options[:password]
- transaction = root.add_element(action)
+ root.add_element(transaction_element(action, parameters))
+ xml.to_s
+ end
+
+ def transaction_element(action, parameters)
+ transaction = REXML::Element.new(action)
+
# Must add the elements in the correct order
actions[action].each do |key|
- transaction.add_element(key.to_s).text = parameters[key] unless parameters[key].blank?
+ if key == :cvd_info
+ transaction.add_element(cvd_element(parameters[:cvd_value]))
+ else
+ transaction.add_element(key.to_s).text = parameters[key] unless parameters[key].blank?
+ end
end
- xml.to_s
+ transaction
end
+ def cvd_element(cvd_value)
+ element = REXML::Element.new('cvd_info')
+ if cvd_value
+ element.add_element('cvd_indicator').text = "1"
+ element.add_element('cvd_value').text = cvd_value
+ else
+ element.add_element('cvd_indicator').text = "0"
+ end
+ element
+ end
+
def message_from(message)
return 'Unspecified error' if message.blank?
message.gsub(/[^\w]/, ' ').split.join(" ").capitalize
end
@@ -217,11 +240,11 @@
end
end
def actions
{
- "purchase" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
- "preauth" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
+ "purchase" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type, :cvd_info],
+ "preauth" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type, :cvd_info],
"command" => [:order_id],
"refund" => [:order_id, :amount, :txn_number, :crypt_type],
"indrefund" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
"completion" => [:order_id, :comp_amount, :txn_number, :crypt_type],
"purchasecorrection" => [:order_id, :txn_number, :crypt_type],