class Stall::Payments::Gateway
Attributes
cart[R]
Public Class Methods
for(payment_method)
click to toggle source
# 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
new(cart)
click to toggle source
# File lib/stall/payments/gateway.rb, line 6 def initialize(cart) @cart = cart end
register(name)
click to toggle source
# File lib/stall/payments/gateway.rb, line 10 def self.register(name) Stall.config.payment.register_gateway(name, self) end
request(cart)
click to toggle source
# 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)
click to toggle source
# File lib/stall/payments/gateway.rb, line 29 def self.response(_request) raise NoMethodError, 'Subclasses must implement the .response(request) class method ' end
Public Instance Methods
payment_urls()
click to toggle source
# File lib/stall/payments/gateway.rb, line 54 def payment_urls @payment_urls ||= Stall::Payments::UrlsConfig.new(cart) end
rendering_options()
click to toggle source
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
# File lib/stall/payments/gateway.rb, line 50 def rendering_options { nothing: false } end
synchronous_payment_notification?()
click to toggle source
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.
# File lib/stall/payments/gateway.rb, line 62 def synchronous_payment_notification? false end
transaction_id(refresh: false)
click to toggle source
# 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
Private Instance Methods
next_transaction_id()
click to toggle source
# File lib/stall/payments/gateway.rb, line 68 def next_transaction_id if (last_transaction = Payment.order("data->>'transaction_id' DESC").select(:data).first) if (id = last_transaction.transaction_id) index = id.split('-').pop.to_i + 1 return transaction_id_for(index) end end transaction_id_for(1) end
transaction_id_for(index)
click to toggle source
# File lib/stall/payments/gateway.rb, line 79 def transaction_id_for(index) transaction_id_format .gsub('%{cart_id}', cart.reference) .gsub('%{transaction_index}', ('%05d' % index)) end
transaction_id_format()
click to toggle source
# File lib/stall/payments/gateway.rb, line 85 def transaction_id_format 'ESHOP-%{cart_id}-%{transaction_index}' end