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

.cart_id_from(_request) ⇒ Object

Raises:

  • (NoMethodError)


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

.register(name) ⇒ Object



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

def self.register(name)
  Stall::Payments.gateways[name] = self
end

Instance Method Details

#process_payment_for(_request) ⇒ Object

Raises:

  • (NoMethodError)


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_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



49
50
51
# File 'lib/stall/payments/gateway.rb', line 49

def rendering_options
  { text: nil }
end

#transaction_idObject



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