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::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#add_field_to_post_if_present, #add_fields_to_post_if_present, #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
43
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 38

def capture(money, authorization, options = {})
  post = {}
  post[:amount] = amount(money) if money
  post[:payments] = options[:payments] if options[:payments]
  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



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

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



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

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



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

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



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

def supports_scrubbing
  true
end

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



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

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



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

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



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

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