Class: Stall::Payments::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/stall/payments/gateway.rb

Direct Known Subclasses

ManualPaymentGateway

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#cartObject (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

Raises:

  • (NoMethodError)


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

Raises:

  • (NoMethodError)


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_urlsObject



54
55
56
# File 'lib/stall/payments/gateway.rb', line 54

def payment_urls
  @payment_urls ||= Stall::Payments::UrlsConfig.new(cart)
end

#rendering_optionsObject

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 rendering_options
  { 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.

Returns:

  • (Boolean)


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