Class: Gateway::BalancedGateway
- Inherits:
-
Gateway
- Object
- Gateway
- Gateway::BalancedGateway
- Defined in:
- app/models/spree/gateway/balanced_gateway.rb
Instance Method Summary collapse
- #authorize(money, creditcard, gateway_options) ⇒ Object
- #capture(authorization, creditcard, gateway_options) ⇒ Object
- #create_profile(payment) ⇒ Object
- #credit(money, creditcard, response_code, gateway_options) ⇒ Object
- #options ⇒ Object
- #payment_profiles_supported? ⇒ Boolean
- #provider_class ⇒ Object
- #purchase(money, creditcard, gateway_options) ⇒ Object
- #void(response_code, creditcard, gateway_options) ⇒ Object
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 (money, creditcard, ) if token = creditcard.gateway_payment_profile_id # The Balanced ActiveMerchant gateway supports passing the token directly as the creditcard parameter creditcard = token end provider.(money, creditcard, ) end |
#capture(authorization, creditcard, gateway_options) ⇒ Object
14 15 16 17 |
# File 'app/models/spree/gateway/balanced_gateway.rb', line 14 def capture(, creditcard, ) [:on_behalf_of_uri] = self.preferred_on_behalf_of_uri provider.capture((.amount * 100).round, .response_code, ) 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? = {} [:email] = payment.order.email [:login] = preferred_login card_store_response = provider.store(payment.source, ) card_uri = card_store_response..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!(:gateway_payment_profile_id => card_uri) rescue Error => ex payment.send(:gateway_error, ex.) 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, ) provider.refund(money, response_code, {}) end |
#options ⇒ Object
35 36 37 |
# File 'app/models/spree/gateway/balanced_gateway.rb', line 35 def super().merge(:test => self.preferred_test_mode) end |
#payment_profiles_supported? ⇒ Boolean
39 40 41 |
# File 'app/models/spree/gateway/balanced_gateway.rb', line 39 def payment_profiles_supported? true end |
#provider_class ⇒ Object
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, ) 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, ) 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, ) provider.void(response_code) end |