lib/active_merchant/billing/gateways/conekta.rb in activemerchant-1.43.3 vs lib/active_merchant/billing/gateways/conekta.rb in activemerchant-1.44.0
- old
+ new
@@ -10,11 +10,11 @@
self.money_format = :cents
self.default_currency = 'MXN'
def initialize(options = {})
requires!(options, :key)
- options[:version] ||= '0.2.0'
+ options[:version] ||= '0.3.0'
super
end
def purchase(money, payment_source, options = {})
post = {}
@@ -53,144 +53,119 @@
add_order(post, money, options)
commit(:post, "charges/#{identifier}/refund", post)
end
- def store(creditcard, options = {})
- post = {}
- add_payment_source(post, creditcard, options)
- post[:name] = options[:name]
- post[:email] = options[:email]
-
- path = if options[:customer]
- "customers/#{CGI.escape(options[:customer])}"
- else
- 'customers'
- end
-
- commit(:post, path, post)
- end
-
- def unstore(customer_id, options = {})
- commit(:delete, "customers/#{CGI.escape(customer_id)}", nil)
- end
-
private
def add_order(post, money, options)
post[:description] = options[:description] || "Active Merchant Purchase"
- post[:reference_id] = options[:order_id]
+ post[:reference_id] = options[:order_id] if options[:order_id]
post[:currency] = (options[:currency] || currency(money)).downcase
post[:amount] = amount(money)
end
def add_details_data(post, options)
details = {}
- details[:name] = options[:customer]
- details[:email] = options[:email]
- details[:phone] = options[:phone]
- details[:device_fingerprint] = options[:device_fingerprint]
- details[:ip] = options[:ip]
+ details[:name] = options[:customer] if options[:customer]
+ details[:email] = options[:email] if options[:email]
+ details[:phone] = options[:phone] if options[:phone]
+ details[:device_fingerprint] = options[:device_fingerprint] if options[:device_fingerprint]
+ details[:ip] = options[:ip] if options[:ip]
add_billing_address(details, options)
add_line_items(details, options)
add_shipment(details, options)
post[:details] = details
end
def add_shipment(post, options)
shipment = {}
- shipment[:carrier] = options[:carrier]
- shipment[:service] = options[:service]
- shipment[:tracking_number] = options[:tracking_number]
- shipment[:price] = options[:price]
+ shipment[:carrier] = options[:carrier] if options[:carrier]
+ shipment[:service] = options[:service] if options[:service]
+ shipment[:tracking_number] = options[:tracking_number] if options[:tracking_number]
+ shipment[:price] = options[:price] if options[:price]
add_shipment_address(shipment, options)
post[:shipment] = shipment
end
def add_shipment_address(post, options)
- address = {}
- address[:street1] = options[:address1]
- address[:street2] = options[:address2]
- address[:street3] = options[:address3]
- address[:city] = options[:city]
- address[:state] = options[:state]
- address[:country] = options[:country]
- address[:zip] = options[:zip]
- post[:address] = address
+ if(address = options[:shipping_address])
+ post[:address] = {}
+ post[:address][:street1] = address[:address1] if address[:address1]
+ post[:address][:street2] = address[:address2] if address[:address2]
+ post[:address][:street3] = address[:address3] if address[:address3]
+ post[:address][:city] = address[:city] if address[:city]
+ post[:address][:state] = address[:state] if address[:state]
+ post[:address][:country] = address[:country] if address[:country]
+ post[:address][:zip] = address[:zip] if address[:zip]
+ end
end
def add_line_items(post, options)
post[:line_items] = (options[:line_items] || []).collect do |line_item|
line_item
end
end
def add_billing_address(post, options)
- address = {}
- address[:street1] = options[:address1]
- address[:street2] = options[:address2]
- address[:street3] = options[:address3]
- address[:city] = options[:city]
- address[:state] = options[:state]
- address[:country] = options[:country]
- address[:zip] = options[:zip]
- address[:company_name] = options[:company_name]
- address[:tax_id] = options[:tax_id]
- address[:name] = options[:name]
- address[:phone] = options[:phone]
- address[:email] = options[:email]
- post[:billing_address] = address
+ if(address = (options[:billing_address] || options[:address]))
+ post[:billing_address] = {}
+ post[:billing_address][:street1] = address[:address1] if address[:address1]
+ post[:billing_address][:street2] = address[:address2] if address[:address2]
+ post[:billing_address][:street3] = address[:address3] if address[:address3]
+ post[:billing_address][:city] = address[:city] if address[:city]
+ post[:billing_address][:state] = address[:state] if address[:state]
+ post[:billing_address][:country] = address[:country] if address[:country]
+ post[:billing_address][:zip] = address[:zip] if address[:zip]
+ post[:billing_address][:company_name] = address[:company_name] if address[:company_name]
+ post[:billing_address][:tax_id] = address[:tax_id] if address[:tax_id]
+ post[:billing_address][:name] = address[:name] if address[:name]
+ post[:billing_address][:phone] = address[:phone] if address[:phone]
+ post[:billing_address][:email] = address[:email] if address[:email]
+ end
end
def add_address(post, options)
- address = {}
- address[:street1] = options[:address1]
- address[:street2] = options[:address2]
- address[:street3] = options[:address3]
- address[:city] = options[:city]
- address[:state] = options[:state]
- address[:country] = options[:country]
- address[:zip] = options[:zip]
- post[:address] = address
+ if(address = (options[:billing_address] || options[:address]))
+ post[:address] = {}
+ post[:address][:street1] = address[:address1] if address[:address1]
+ post[:address][:street2] = address[:address2] if address[:address2]
+ post[:address][:street3] = address[:address3] if address[:address3]
+ post[:address][:city] = address[:city] if address[:city]
+ post[:address][:state] = address[:state] if address[:state]
+ post[:address][:country] = address[:country] if address[:country]
+ post[:address][:zip] = address[:zip] if address[:zip]
+ end
end
def add_payment_source(post, payment_source, options)
if payment_source.kind_of?(String)
post[:card] = payment_source
elsif payment_source.respond_to?(:number)
- card = {}
- card[:name] = payment_source.name
- card[:cvc] = payment_source.verification_value
- card[:number] = payment_source.number
- card[:exp_month] = "#{sprintf("%02d", payment_source.month)}"
- card[:exp_year] = "#{"#{payment_source.year}"[-2, 2]}"
- post[:card] = card
+ post[:card] = {}
+ post[:card][:name] = payment_source.name
+ post[:card][:cvc] = payment_source.verification_value
+ post[:card][:number] = payment_source.number
+ post[:card][:exp_month] = "#{sprintf("%02d", payment_source.month)}"
+ post[:card][:exp_year] = "#{"#{payment_source.year}"[-2, 2]}"
add_address(post[:card], options)
end
end
def parse(body)
return {} unless body
JSON.parse(body)
end
def headers(meta)
- @@ua ||= JSON.dump({
- :bindings_version => ActiveMerchant::VERSION,
- :lang => 'ruby',
- :lang_version => "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
- :platform => RUBY_PLATFORM,
- :publisher => 'active_merchant'
- })
-
{
"Accept" => "application/vnd.conekta-v#{options[:version]}+json",
"Authorization" => "Basic " + Base64.encode64("#{options[:key]}:"),
"RaiseHtmlError" => "false",
- "User-Agent" => "Conekta ActiveMerchantBindings/#{ActiveMerchant::VERSION}",
- "X-Conekta-Client-User-Agent" => @@ua,
+ "Conekta-Client-User-Agent" => {"agent"=>"Conekta ActiveMerchantBindings/#{ActiveMerchant::VERSION}"}.to_json,
+ "X-Conekta-Client-User-Agent" => user_agent,
"X-Conekta-Client-User-Metadata" => meta.to_json
}
end
def commit(method, url, parameters, options = {})
@@ -206,11 +181,11 @@
Response.new(
success,
raw_response["message"],
raw_response,
- :test => test?,
- :authorization => raw_response["id"]
+ test: test?,
+ authorization: raw_response["id"]
)
end
def response_error(raw_response)
begin