Class: Gateway::BalancedGateway

Inherits:
Gateway
  • Object
show all
Defined in:
app/models/spree/gateway/balanced_gateway.rb

Instance Method Summary collapse

Instance Method Details

#authorize(money, creditcard, gateway_options) ⇒ Object



8
9
10
11
12
13
14
# File 'app/models/spree/gateway/balanced_gateway.rb', line 8

def authorize(money, creditcard, gateway_options)
  if token = creditcard.gateway_payment_profile_id
    # The Balanced ActiveMerchant gateway supports passing the token directly as the creditcard parameter
    creditcard = token
  end
  provider.authorize(money, creditcard, gateway_options)
end

#capture(authorization, creditcard, gateway_options) ⇒ Object



16
17
18
19
# File 'app/models/spree/gateway/balanced_gateway.rb', line 16

def capture(authorization, creditcard, gateway_options)
  gateway_options[:on_behalf_of_uri] = self.preferred_on_behalf_of_uri
  provider.capture((authorization.amount * 100).round, authorization.response_code, gateway_options)
end

#create_profile(payment) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/spree/gateway/balanced_gateway.rb', line 21

def create_profile(payment)
  return unless payment.source.gateway_payment_profile_id.nil?

  options = {}
  options[:email] = payment.order.email
  options[:login] = 

  card_uri = provider.store(payment.source, options)

  # A success just returns a string of the token. A failed request returns a bad request response with a message.
  if card_uri.is_a?(String)
    payment.source.update_attributes!(:gateway_payment_profile_id => card_uri)
  else
    payment.send(:gateway_error, card_uri.message)
  end
end

#credit(money, creditcard, response_code, gateway_options) ⇒ Object



59
60
61
# File 'app/models/spree/gateway/balanced_gateway.rb', line 59

def credit(money, creditcard, response_code, gateway_options)
  provider.refund(money, response_code, {})
end

#options_with_test_preferenceObject



38
39
40
# File 'app/models/spree/gateway/balanced_gateway.rb', line 38

def options_with_test_preference
  options_without_test_preference.merge(:test => self.preferred_test_mode)
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/models/spree/gateway/balanced_gateway.rb', line 43

def payment_profiles_supported?
  true
end

#provider_classObject



55
56
57
# File 'app/models/spree/gateway/balanced_gateway.rb', line 55

def provider_class
  ActiveMerchant::Billing::BalancedGateway
end

#purchase(money, creditcard, gateway_options) ⇒ Object



47
48
49
50
51
52
53
# File 'app/models/spree/gateway/balanced_gateway.rb', line 47

def purchase(money, creditcard, gateway_options)
  if token = creditcard.gateway_payment_profile_id
    # The Balanced ActiveMerchant gateway supports passing the token directly as the creditcard parameter
    creditcard = token
  end
  provider.purchase(money, creditcard, gateway_options)
end

#void(response_code, creditcard, gateway_options) ⇒ Object



63
64
65
# File 'app/models/spree/gateway/balanced_gateway.rb', line 63

def void(response_code, creditcard, gateway_options)
  provider.void(response_code)
end