Class: Stall::Payments::Gateway

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

Constant Summary collapse

TRANSACTION_ID_FORMAT =
'ESHOP-%{cart_id}-%{transaction_index}'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

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

.for(payment_method) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/stall/payments/gateway.rb', line 16

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



12
13
14
# File 'lib/stall/payments/gateway.rb', line 12

def self.register(name)
  Stall.config.payment.register_gateway(name, self)
end

.request(cart) ⇒ Object

Raises:

  • (NoMethodError)


26
27
28
29
# File 'lib/stall/payments/gateway.rb', line 26

def self.request(cart)
  raise NoMethodError,
    'Subclasses must implement the .request(cart) class method '
end

.response(_request) ⇒ Object

Raises:

  • (NoMethodError)


31
32
33
34
# File 'lib/stall/payments/gateway.rb', line 31

def self.response(_request)
  raise NoMethodError,
    'Subclasses must implement the .response(request) class method '
end

Instance Method Details

#payment_urlsObject



56
57
58
# File 'lib/stall/payments/gateway.rb', line 56

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



52
53
54
# File 'lib/stall/payments/gateway.rb', line 52

def rendering_options
  { text: nil }
end

#transaction_idObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/stall/payments/gateway.rb', line 36

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