Class: ActiveMerchant::Billing::OpenpayGateway
- Inherits:
-
Gateway
- Object
- Gateway
- ActiveMerchant::Billing::OpenpayGateway
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
-
#authorize(money, creditcard, options = {}) ⇒ Object
-
#capture(money, authorization, options = {}) ⇒ Object
-
#gateway_url(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ OpenpayGateway
constructor
Instantiate a instance of OpenpayGateway by passing through your merchant id and private api key.
-
#purchase(money, creditcard, options = {}) ⇒ Object
-
#refund(money, identification, options = {}) ⇒ Object
-
#scrub(transcript) ⇒ Object
-
#store(creditcard, options = {}) ⇒ Object
-
#supports_scrubbing ⇒ Object
-
#unstore(customer_id, card_id = nil, options = {}) ⇒ Object
-
#verify(credit_card, options = {}) ⇒ Object
-
#void(identification, options = {}) ⇒ Object
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?
#expdate, #format
Methods included from PostsData
included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request
Constructor Details
Instantiate a instance of OpenpayGateway by passing through your merchant id and private api key.
To obtain your own credentials
-
Visit openpay.mx
-
Sign up
-
Activate your account clicking on the email confirmation
27
28
29
30
31
32
|
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 27
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
49
50
51
52
53
|
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 49
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
55
56
57
58
59
60
|
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 55
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
|
#gateway_url(options = {}) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 34
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
|
#purchase(money, creditcard, options = {}) ⇒ Object
44
45
46
47
|
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 44
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
66
67
68
69
70
71
|
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 66
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
115
116
117
118
119
120
121
122
123
|
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 115
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 80
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_scrubbing ⇒ Object
111
112
113
|
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 111
def supports_scrubbing
true
end
|
#unstore(customer_id, card_id = nil, options = {}) ⇒ Object
103
104
105
106
107
108
109
|
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 103
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
73
74
75
76
77
78
|
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 73
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
62
63
64
|
# File 'lib/active_merchant/billing/gateways/openpay.rb', line 62
def void(identification, options = {})
commit(:post, "charges/#{CGI.escape(identification)}/refund", nil, options)
end
|