Class: ActiveMerchant::Billing::BalancedGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/balanced.rb

Overview

For more information on Balanced visit www.balancedpayments.com or visit #balanced on irc.freenode.net

Instantiate a instance of BalancedGateway by passing through your Balanced API key secret.

To obtain an API key of your own

  1. Visit www.balancedpayments.com

  2. Click “Get started”

  3. The next screen will give you a test API key of your own

  4. When you're ready to generate a production API key click the “Go live” button on the Balanced dashboard and fill in your marketplace details.

Constant Summary collapse

VERSION =
"2.0.0"

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, 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, non_fractional_currency?, #scrub, supported_countries, #supported_countries, supported_countries=, supports?, #supports_scrubbing?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Constructor Details

#initialize(options = {}) ⇒ BalancedGateway

Creates a new BalancedGateway

Options

  • :login – The Balanced API Secret (REQUIRED)


35
36
37
38
# File 'lib/active_merchant/billing/gateways/balanced.rb', line 35

def initialize(options = {})
  requires!(options, :login)
  super
end

Instance Method Details

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


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/active_merchant/billing/gateways/balanced.rb', line 57

def authorize(money, payment_method, options = {})
  post = {}
  add_amount(post, money)
  post[:description] = options[:description]
  add_common_params(post, options)

  MultiResponse.run do |r|
    identifier = if(payment_method.respond_to?(:number))
      r.process{store(payment_method, options)}
      r.authorization
    else
      payment_method
    end
    r.process{commit("card_holds", "cards/#{card_identifier_from(identifier)}/card_holds", post)}
  end
end

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


74
75
76
77
78
79
80
81
# File 'lib/active_merchant/billing/gateways/balanced.rb', line 74

def capture(money, identifier, options = {})
  post = {}
  add_amount(post, money)
  post[:description] = options[:description] if options[:description]
  add_common_params(post, options)

  commit("debits", "card_holds/#{reference_identifier_from(identifier)}/debits", post)
end

#purchase(money, payment_method, options = {}) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/active_merchant/billing/gateways/balanced.rb', line 40

def purchase(money, payment_method, options = {})
  post = {}
  add_amount(post, money)
  post[:description] = options[:description]
  add_common_params(post, options)

  MultiResponse.run do |r|
    identifier = if(payment_method.respond_to?(:number))
      r.process{store(payment_method, options)}
      r.authorization
    else
      payment_method
    end
    r.process{commit("debits", "cards/#{card_identifier_from(identifier)}/debits", post)}
  end
end

#refund(money, identifier, options = {}) ⇒ Object


91
92
93
94
95
96
97
98
# File 'lib/active_merchant/billing/gateways/balanced.rb', line 91

def refund(money, identifier, options = {})
  post = {}
  add_amount(post, money)
  post[:description] = options[:description]
  add_common_params(post, options)

  commit("refunds", "debits/#{reference_identifier_from(identifier)}/refunds", post)
end

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


100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/active_merchant/billing/gateways/balanced.rb', line 100

def store(credit_card, options={})
  post = {}

  post[:number] = credit_card.number
  post[:expiration_month] = credit_card.month
  post[:expiration_year] = credit_card.year
  post[:cvv] = credit_card.verification_value if credit_card.verification_value?
  post[:name] = credit_card.name if credit_card.name

  add_address(post, options)

  commit("cards", "cards", post)
end

#void(identifier, options = {}) ⇒ Object


83
84
85
86
87
88
89
# File 'lib/active_merchant/billing/gateways/balanced.rb', line 83

def void(identifier, options = {})
  post = {}
  post[:is_void] = true
  add_common_params(post, options)

  commit("card_holds", "card_holds/#{reference_identifier_from(identifier)}", post, :put)
end