Class: Omnipay::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/omnipay/adapter.rb

Overview

Wrapper around an actual adapter implementation. Responsible mainly for handling its initialization with a static or dynamic (block) configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uid, callback_url, config, dynamic_config) ⇒ Adapter

Parameters:

  • uid (String)

    The adapter’s unique identifier

  • callback_url (String)

    The absolute URL to be used for the user redirection after the payment

  • config (Hash)

    A static adapter configuration

  • dynamic_config (String => Hash)

    A dynamic config block. Takes the uid as an input and returns the adapter’s configuration



16
17
18
19
20
21
22
23
# File 'lib/omnipay/adapter.rb', line 16

def initialize(uid, callback_url, config, dynamic_config)
  @uid = uid
  @callback_url = callback_url
  @config = config
  @dynamic_config = dynamic_config

  @strategy = build_strategy
end

Instance Attribute Details

#uidObject (readonly)

The adapter’s unique identifier. Will be passed to the dynamic configuration block.



8
9
10
# File 'lib/omnipay/adapter.rb', line 8

def uid
  @uid
end

Instance Method Details

#callback_hash(params) ⇒ Hash

Proxy to the adapter’s implementation’s callback_phase method

Parameters:

  • params (Hash)

    The GET/POST params sent by the payment gateway to the callback url

Returns:

  • (Hash)

    The omnipay response environment. Contains the response success status, the amount payed, the error message if any, …



42
43
44
# File 'lib/omnipay/adapter.rb', line 42

def callback_hash(params)
  @strategy.callback_hash(params)
end

#request_phase(amount, opts = {}) ⇒ Array

Proxy to the adapter’s implementation’s request_phase method

Parameters:

  • amount (Integer)

    The amount to pay, in cents

  • opts (Hash) (defaults to: {})

    The custom GET parameters sent to the omnipay payment url

Returns:

  • (Array)

    The array containing the redirection method (GET or POST), its url, its get or post params, and the unique associated transaction id



35
36
37
# File 'lib/omnipay/adapter.rb', line 35

def request_phase(amount, opts = {})
  @strategy.request_phase(amount, opts)
end

#valid?Boolean

Is there a valid adapter configuration for the given parameters. Checks notably if the given uid is valid in case of a dyncamic configuration.

Returns:

  • (Boolean)


27
28
29
# File 'lib/omnipay/adapter.rb', line 27

def valid?
  @strategy != nil
end