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



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

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



14
15
16
17
# File 'app/models/spree/gateway/balanced_gateway.rb', line 14

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



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

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

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

  card_store_response = provider.store(payment.source, options)
  card_uri = card_store_response.authorization.split(';').first

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

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



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

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

#options_with_test_preferenceObject



35
36
37
# File 'app/models/spree/gateway/balanced_gateway.rb', line 35

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

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/spree/gateway/balanced_gateway.rb', line 40

def payment_profiles_supported?
  true
end

#provider_classObject



52
53
54
# File 'app/models/spree/gateway/balanced_gateway.rb', line 52

def provider_class
  ActiveMerchant::Billing::BalancedGateway
end

#purchase(money, creditcard, gateway_options) ⇒ Object



44
45
46
47
48
49
50
# File 'app/models/spree/gateway/balanced_gateway.rb', line 44

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



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

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