Class: Stall::Payments::Gateway
- Inherits:
-
Object
- Object
- Stall::Payments::Gateway
- Defined in:
- lib/stall/payments/gateway.rb
Instance Attribute Summary collapse
-
#cart ⇒ Object
readonly
Returns the value of attribute cart.
Class Method Summary collapse
- .for(payment_method) ⇒ Object
- .register(name) ⇒ Object
- .request(cart) ⇒ Object
- .response(_request) ⇒ Object
Instance Method Summary collapse
-
#initialize(cart) ⇒ Gateway
constructor
A new instance of Gateway.
- #payment_urls ⇒ Object
-
#rendering_options ⇒ Object
Defines the arguments passed to the render call in response to the automatic gateway response notification.
-
#synchronous_payment_notification? ⇒ Boolean
Override this method and retrun true if the gateway payment notification should be taken into account to determine wether the payment has been successful or not when returning from the gateway.
- #transaction_id(refresh: false) ⇒ Object
Constructor Details
#initialize(cart) ⇒ Gateway
Returns a new instance of Gateway.
6 7 8 |
# File 'lib/stall/payments/gateway.rb', line 6 def initialize(cart) @cart = cart end |
Instance Attribute Details
#cart ⇒ Object (readonly)
Returns the value of attribute cart.
4 5 6 |
# File 'lib/stall/payments/gateway.rb', line 4 def cart @cart end |
Class Method Details
.for(payment_method) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/stall/payments/gateway.rb', line 14 def self.for(payment_method) identifier = case payment_method when String, Symbol then payment_method.to_s else payment_method.identifier end gateway = Stall::Payments.gateways[identifier] String === gateway ? gateway.constantize : gateway end |
.register(name) ⇒ Object
10 11 12 |
# File 'lib/stall/payments/gateway.rb', line 10 def self.register(name) Stall.config.payment.register_gateway(name, self) end |
.request(cart) ⇒ Object
24 25 26 27 |
# File 'lib/stall/payments/gateway.rb', line 24 def self.request(cart) raise NoMethodError, 'Subclasses must implement the .request(cart) class method ' end |
.response(_request) ⇒ Object
29 30 31 32 |
# File 'lib/stall/payments/gateway.rb', line 29 def self.response(_request) raise NoMethodError, 'Subclasses must implement the .response(request) class method ' end |
Instance Method Details
#payment_urls ⇒ Object
54 55 56 |
# File 'lib/stall/payments/gateway.rb', line 54 def payment_urls @payment_urls ||= Stall::Payments::UrlsConfig.new(cart) end |
#rendering_options ⇒ Object
Defines the arguments passed to the render call in response to the automatic gateway response notification
Most of the gateways expect some specific return, so this is to be overriden by subclasses
50 51 52 |
# File 'lib/stall/payments/gateway.rb', line 50 def { nothing: false } end |
#synchronous_payment_notification? ⇒ Boolean
Override this method and retrun true if the gateway payment notification should be taken into account to determine wether the payment has been successful or not when returning from the gateway.
62 63 64 |
# File 'lib/stall/payments/gateway.rb', line 62 def synchronous_payment_notification? false end |
#transaction_id(refresh: false) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/stall/payments/gateway.rb', line 34 def transaction_id(refresh: false) @transaction_id ||= begin if refresh || !(id = cart.payment.transaction_id) id = next_transaction_id cart.payment.update_attributes(transaction_id: id) end id end end |