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



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

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

#optionsObject



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

def options
  super().merge(:test => self.preferred_test_mode)
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


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

def payment_profiles_supported?
  true
end

#provider_classObject



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

def provider_class
  ActiveMerchant::Billing::BalancedGateway
end

#purchase(money, creditcard, gateway_options) ⇒ Object



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

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



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

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