lib/active_merchant/billing/gateways/openpay.rb in activemerchant-1.126.0 vs lib/active_merchant/billing/gateways/openpay.rb in activemerchant-1.129.0

- old
+ new

@@ -1,11 +1,18 @@ module ActiveMerchant #:nodoc: module Billing #:nodoc: class OpenpayGateway < Gateway - self.live_url = 'https://api.openpay.mx/v1/' - self.test_url = 'https://sandbox-api.openpay.mx/v1/' + class_attribute :mx_live_url, :mx_test_url + class_attribute :co_live_url, :co_test_url + self.co_live_url = 'https://api.openpay.co/v1/' + self.co_test_url = 'https://sandbox-api.openpay.co/v1/' + self.mx_live_url = 'https://api.openpay.mx/v1/' + self.mx_test_url = 'https://sandbox-api.openpay.mx/v1/' + self.live_url = self.co_live_url + self.test_url = self.co_test_url + self.supported_countries = %w(CO MX) self.supported_cardtypes = %i[visa master american_express carnet] self.homepage_url = 'http://www.openpay.mx/' self.display_name = 'Openpay' self.default_currency = 'MXN' @@ -22,10 +29,20 @@ @api_key = options[:key] @merchant_id = options[:merchant_id] super end + def gateway_url(options = {}) + country = options[:merchant_country] || @options[:merchant_country] + + if country == 'MX' + test? ? mx_test_url : mx_live_url + else + test? ? co_test_url : co_live_url + end + end + def purchase(money, creditcard, options = {}) post = create_post_for_auth_or_purchase(money, creditcard, options) commit(:post, 'charges', post, options) end @@ -190,10 +207,10 @@ test: test?, authorization: response['id']) end def http_request(method, resource, parameters = {}, options = {}) - url = (test? ? self.test_url : self.live_url) + @merchant_id + '/' + resource + url = gateway_url(options) + @merchant_id + '/' + resource raw_response = nil begin raw_response = ssl_request(method, url, (parameters ? parameters.to_json : nil), headers(options)) parse(raw_response) rescue ResponseError => e