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::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, 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

#scrub(transcript) ⇒ Object



97
98
99
100
101
102
103
104
105
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 97

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
    gsub(%r((card_number\\?":\\?")[^"\\]*)i, '\1[FILTERED]').
    gsub(%r((cvv2\\?":\\?")\d+[^"\\]*)i, '\1[FILTERED]').
    gsub(%r((cvv2\\?":)null), '\1[BLANK]').
    gsub(%r((cvv2\\?":\\?")\\?"), '\1[BLANK]"').
    gsub(%r((cvv2\\?":\\?")\s+), '\1[BLANK]')
end

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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 62

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

#supports_scrubbingObject



93
94
95
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 93

def supports_scrubbing
  true
end

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



85
86
87
88
89
90
91
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 85

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

#verify(credit_card, options = {}) ⇒ Object



55
56
57
58
59
60
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 55

def verify(credit_card, options = {})
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(100, credit_card, options) }
    r.process(:ignore_result) { void(r.authorization, 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