Class: Stall::Payments::Gateway
- Inherits:
-
Object
- Object
- Stall::Payments::Gateway
- Defined in:
- lib/stall/payments/gateway.rb
Constant Summary collapse
- TRANSACTION_ID_FORMAT =
'ESHOP-%{cart_id}-%{transaction_index}'
Instance Attribute Summary collapse
-
#cart ⇒ Object
readonly
Returns the value of attribute cart.
Class Method Summary collapse
- .cart_id_from(_request) ⇒ Object
- .cart_id_from_transaction_id(transaction_id) ⇒ Object
- .register(name) ⇒ Object
Instance Method Summary collapse
-
#initialize(cart) ⇒ Gateway
constructor
A new instance of Gateway.
- #process_payment_for(_request) ⇒ Object
-
#rendering_options ⇒ Object
Defines the arguments passed to the render call in response to the automatic gateway response notification.
- #transaction_id ⇒ Object
Constructor Details
#initialize(cart) ⇒ Gateway
Returns a new instance of Gateway.
8 9 10 |
# File 'lib/stall/payments/gateway.rb', line 8 def initialize(cart) @cart = cart end |
Instance Attribute Details
#cart ⇒ Object (readonly)
Returns the value of attribute cart.
6 7 8 |
# File 'lib/stall/payments/gateway.rb', line 6 def cart @cart end |
Class Method Details
.cart_id_from(_request) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/stall/payments/gateway.rb', line 16 def self.cart_id_from(_request) raise NoMethodError, 'Subclasses must implement the .cart_id_from(request) class method ' \ 'to allow retrieving the cart from the remote gateway notification ' \ 'request object' end |
.cart_id_from_transaction_id(transaction_id) ⇒ Object
23 24 25 |
# File 'lib/stall/payments/gateway.rb', line 23 def self.cart_id_from_transaction_id(transaction_id) transaction_id && transaction_id.split('-')[2].to_i end |
Instance Method Details
#process_payment_for(_request) ⇒ Object
27 28 29 30 31 |
# File 'lib/stall/payments/gateway.rb', line 27 def process_payment_for(_request) raise NoMethodError, 'Subclasses must implement the #process_payment_for(request) ' \ 'method to handle payment verifications and cart payment validation' 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
49 50 51 |
# File 'lib/stall/payments/gateway.rb', line 49 def { text: nil } end |
#transaction_id ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/stall/payments/gateway.rb', line 33 def transaction_id @transaction_id ||= begin unless (id = cart.payment.transaction_id) id = next_transaction_id cart.payment.update_attributes(transaction_id: id) end id end end |