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::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, #scrub, #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 = {}) ⇒ 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



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

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



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

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
56
# 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



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

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



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

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



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

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