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_with_test_preference ⇒ 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
8 9 10 11 12 13 14 |
# File 'app/models/spree/gateway/balanced_gateway.rb', line 8 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
16 17 18 19 |
# File 'app/models/spree/gateway/balanced_gateway.rb', line 16 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
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? = {} [:email] = payment.order.email [:login] = preferred_login card_uri = provider.store(payment.source, ) # 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.) 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, ) provider.refund(money, response_code, {}) end |
#options_with_test_preference ⇒ Object
38 39 40 |
# File 'app/models/spree/gateway/balanced_gateway.rb', line 38 def .merge(:test => self.preferred_test_mode) end |
#payment_profiles_supported? ⇒ Boolean
43 44 45 |
# File 'app/models/spree/gateway/balanced_gateway.rb', line 43 def payment_profiles_supported? true end |
#provider_class ⇒ Object
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, ) 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
63 64 65 |
# File 'app/models/spree/gateway/balanced_gateway.rb', line 63 def void(response_code, creditcard, ) provider.void(response_code) end |