Class: ActiveMerchant::Billing::WebpayGateway

Inherits:
StripeGateway show all
Defined in:
lib/active_merchant/billing/gateways/webpay.rb

Constant Summary

Constants inherited from StripeGateway

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

Methods inherited from StripeGateway

#application_fee_from_response, #initialize, #purchase, #refund_application_fee, #store, #unstore, #update, #void

Methods inherited from Gateway

#card_brand, card_brand, inherited, #initialize, supports?, #test?

Methods included from CreditCardFormatting

#format

Constructor Details

This class inherits a constructor from ActiveMerchant::Billing::StripeGateway

Instance Method Details

#add_amount(post, money, options) ⇒ Object



46
47
48
49
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 46

def add_amount(post, money, options)
  post[:currency] = (options[:currency] || currency(money)).downcase
  post[:amount] = localized_amount(money, post[:currency].upcase)
end

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

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 16

def authorize(money, credit_card, options = {})
  raise NotImplementedError.new
end

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

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 20

def capture(money, credit_card, options = {})
  raise NotImplementedError.new
end

#headers(options = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 61

def headers(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',
    :uname => (RUBY_PLATFORM =~ /linux|darwin/i ? `uname -a 2>/dev/null`.strip : nil)
  })

  {
    "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" => options[:meta].to_json
  }
end

#json_error(raw_response) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 51

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



42
43
44
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 42

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



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 24

def refund(money, identification, options = {})
  post = {:amount => localized_amount(money)}
  commit_options = generate_meta(options)

  MultiResponse.run do |r|
    r.process { commit(:post, "charges/#{CGI.escape(identification)}/refund", post, commit_options) }

    return r unless options[:refund_fee_amount]

    r.process { fetch_application_fees(identification, commit_options) }
    r.process { refund_application_fee(options[:refund_fee_amount], application_fee_from_response(r), commit_options) }
  end
end

#refund_fee(identification, options, meta) ⇒ Object

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/active_merchant/billing/gateways/webpay.rb', line 38

def refund_fee(identification, options, meta)
  raise NotImplementedError.new
end