Class: ActiveMerchant::Billing::OpenpayGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/openpay.rb

Constant Summary

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, #generate_unique_id, inherited, non_fractional_currency?, #scrub, supported_countries, #supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #supports_scrubbing?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ OpenpayGateway

Instantiate a instance of OpenpayGateway by passing through your merchant id and private api key.

To obtain your own credentials

  1. Visit openpay.mx

  2. Sign up

  3. Activate your account clicking on the email confirmation



20
21
22
23
24
25
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 20

def initialize(options = {})
  requires!(options, :key, :merchant_id)
  @api_key = options[:key]
  @merchant_id = options[:merchant_id]
  super
end

Instance Method Details

#authorize(money, creditcard, options = {}) ⇒ Object



32
33
34
35
36
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 32

def authorize(money, creditcard, options = {})
  post = create_post_for_auth_or_purchase(money, creditcard, options)
  post[:capture] = false
  commit(:post, 'charges', post, options)
end

#capture(money, authorization, options = {}) ⇒ Object



38
39
40
41
42
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 38

def capture(money, authorization, options = {})
  post = {}
  post[:amount] = amount(money) if money
  commit(:post, "charges/#{CGI.escape(authorization)}/capture", post, options)
end

#purchase(money, creditcard, options = {}) ⇒ Object



27
28
29
30
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 27

def purchase(money, creditcard, options = {})
  post = create_post_for_auth_or_purchase(money, creditcard, options)
  commit(:post, 'charges', post, options)
end

#refund(money, identification, options = {}) ⇒ Object



48
49
50
51
52
53
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 48

def refund(money, identification, options = {})
  post = {}
  post[:description] = options[:description]
  post[:amount] = amount(money)
  commit(:post, "charges/#{CGI.escape(identification)}/refund", post, options)
end

#store(creditcard, options = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 55

def store(creditcard, options = {})
  card_params = {}
  add_creditcard(card_params, creditcard, options)
  card = card_params[:card]

  if options[:customer].present?
    commit(:post, "customers/#{CGI.escape(options[:customer])}/cards", card, options)
  else
    requires!(options, :email, :name)
    post = {}
    post[:name] = options[:name]
    post[:email] = options[:email]
    MultiResponse.run(:first) do |r|
      r.process { commit(:post, 'customers', post, options) }

      if(r.success? && !r.params['id'].blank?)
        customer_id = r.params['id']
        r.process { commit(:post, "customers/#{customer_id}/cards", card, options) }
      end
    end
  end
end

#unstore(customer_id, card_id = nil, options = {}) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 78

def unstore(customer_id, card_id = nil, options = {})
  if card_id.nil?
    commit(:delete, "customers/#{CGI.escape(customer_id)}", nil, options)
  else
    commit(:delete, "customers/#{CGI.escape(customer_id)}/cards/#{CGI.escape(card_id)}", nil, options)
  end
end

#void(identification, options = {}) ⇒ Object



44
45
46
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 44

def void(identification, options = {})
  commit(:post, "charges/#{CGI.escape(identification)}/refund", nil, options)
end