Class: ActiveMerchant::Billing::WebpayGateway
Constant Summary
StripeGateway::AVS_CODE_TRANSLATOR, StripeGateway::CVC_CODE_TRANSLATOR
Constants inherited
from Gateway
Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS
Instance Attribute Summary
Attributes inherited from Gateway
#options
Instance Method Summary
collapse
-
#add_amount(post, money, options) ⇒ Object
-
#add_customer(post, creditcard, options) ⇒ Object
-
#capture(money, authorization, options = {}) ⇒ Object
-
#headers(options = {}) ⇒ Object
-
#json_error(raw_response) ⇒ Object
-
#localized_amount(money, currency = self.default_currency) ⇒ Object
-
#refund(money, identification, options = {}) ⇒ Object
-
#refund_fee(identification, options, meta) ⇒ Object
-
#store(creditcard, options = {}) ⇒ Object
#application_fee_from_response, #authorize, #initialize, #purchase, #refund_application_fee, #unstore, #update, #update_customer, #void
Methods inherited from Gateway
#card_brand, card_brand, inherited, #initialize, supports?, #test?
#format
Instance Method Details
#add_amount(post, money, options) ⇒ Object
43
44
45
46
|
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 43
def add_amount(post, money, options)
post[:currency] = (options[:currency] || currency(money)).downcase
post[:amount] = localized_amount(money, post[:currency].upcase)
end
|
#add_customer(post, creditcard, options) ⇒ Object
48
49
50
|
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 48
def add_customer(post, creditcard, options)
post[:customer] = options[:customer] if options[:customer] && !creditcard.respond_to?(:number)
end
|
#capture(money, authorization, options = {}) ⇒ Object
16
17
18
19
20
|
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 16
def capture(money, authorization, options = {})
post = {:amount => localized_amount(money)}
add_application_fee(post, options)
commit(:post, "charges/#{CGI.escape(authorization)}/capture", post)
end
|
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 81
def (options = {})
@@ua ||= JSON.dump({
:bindings_version => ActiveMerchant::VERSION,
:lang => 'ruby',
:lang_version => "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
:platform => RUBY_PLATFORM,
:publisher => 'active_merchant'
})
{
"Authorization" => "Basic " + Base64.encode64(@api_key.to_s + ":").strip,
"User-Agent" => "Webpay/v1 ActiveMerchantBindings/#{ActiveMerchant::VERSION}",
"X-Webpay-Client-User-Agent" => @@ua,
"X-Webpay-Client-User-Metadata" => {:ip => options[:ip]}.to_json
}
end
|
#json_error(raw_response) ⇒ Object
71
72
73
74
75
76
77
78
79
|
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 71
def json_error(raw_response)
msg = 'Invalid response received from the WebPay API. Please contact [email protected] if you continue to receive this message.'
msg += " (The raw response returned by the API was #{raw_response.inspect})"
{
"error" => {
"message" => msg
}
}
end
|
#localized_amount(money, currency = self.default_currency) ⇒ Object
39
40
41
|
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 39
def localized_amount(money, currency = self.default_currency)
non_fractional_currency?(currency) ? (amount(money).to_f / 100).floor : amount(money)
end
|
#refund(money, identification, options = {}) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 22
def refund(money, identification, options = {})
post = {:amount => localized_amount(money)}
MultiResponse.run do |r|
r.process { commit(:post, "charges/#{CGI.escape(identification)}/refund", post, options) }
return r unless options[:refund_fee_amount]
r.process { fetch_application_fees(identification, options) }
r.process { refund_application_fee(options[:refund_fee_amount], application_fee_from_response(r), options) }
end
end
|
#refund_fee(identification, options, meta) ⇒ Object
35
36
37
|
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 35
def refund_fee(identification, options, meta)
raise NotImplementedError.new
end
|
#store(creditcard, options = {}) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 52
def store(creditcard, options = {})
post = {}
add_creditcard(post, creditcard, options)
post[:description] = options[:description]
post[:email] = options[:email]
if options[:customer]
MultiResponse.run(:first) do |r|
r.process { commit(:post, "customers/#{CGI.escape(options[:customer])}/", post, options) }
return r unless options[:set_default] and r.success? and !r.params["id"].blank?
r.process { update_customer(options[:customer], :default_card => r.params["id"]) }
end
else
commit(:post, 'customers', post, options)
end
end
|