Module: Payu

Defined in:
lib/payu.rb,
lib/payu/pos.rb,
lib/payu/errors.rb,
lib/payu/gateway.rb,
lib/payu/helpers.rb,
lib/payu/version.rb,
lib/payu/response.rb,
lib/payu/signature.rb,
lib/payu/timestamp.rb,
lib/payu/transaction.rb

Defined Under Namespace

Modules: Helpers Classes: Gateway, Pos, PosInvalid, PosNotFound, RequestFailed, Response, Signature, SignatureInvalid, Timestamp, Transaction, TransactionInvalid

Constant Summary collapse

ENCODINGS =
['ISO', 'WIN', 'UTF']
ERRORS =
{
  100 => 'Missing parameter pos_id',
  101 => 'Missing parameter session_id',
  102 => 'Missing parameter ts',
  103 => 'Missing parameter sig',
  104 => 'Missing parameter desc',
  105 => 'Missing parameter client_ip',
  106 => 'Missing parameter first_name',
  107 => 'Missing parameter last_name',
  108 => 'Missing parameter street',
  109 => 'Missing parameter city',
  110 => 'Missing parameter post_code',
  111 => 'Missing parameter amount',
  112 => 'Invalid bank account number',
  113 => 'Missing parameter email',
  114 => 'Missing parameter phone',
  200 => 'Temporary error',
  201 => 'Temporary database error',
  202 => 'POS blocked',
  203 => 'Invalid pay_type value for provided pos_id',
  204 => 'Selected payment method (pay_type value) is temporary unavailable for provided pos_id',
  205 => 'Provided amount is smaller than minimal amount',
  206 => 'Provided amount is larger than maximal amount',
  207 => 'Transaction limit exceeded',
  208 => 'ExpressPayment has not been activated',
  209 => 'Invalid pos_id or pos_auth_key',
  500 => 'Transaction does not exist',
  501 => 'Unauthorized for this transaction',
  502 => 'Transaction already started',
  503 => 'Transaction already authorized',
  504 => 'Transaction already canceled',
  505 => 'Confirm order already sent',
  506 => 'Transaction already confirmed',
  507 => 'Error while returning funds to client',
  599 => 'Invalid transaction status. Please contact PayU support',
  999 => 'Critical error'
}
VERSION =
'0.7.4'
@@pos_table =
{}

Class Method Summary collapse

Class Method Details

.[](name_or_id) ⇒ Object

Combined accessor, returns Pos object with given pos_id or name

Parameters:

  • name_or_id (String, Integer)

    name or pos_id of Pos

Returns:

  • (Object)

    the Pos object



58
59
60
# File 'lib/payu.rb', line 58

def [](name_or_id)
  get_pos_by_name(name_or_id) || get_pos_by_id(name_or_id) || raise(PosNotFound)
end

.add_pos(name, pos) ⇒ Object



50
51
52
# File 'lib/payu.rb', line 50

def add_pos(name, pos)
  @@pos_table[name.to_s] = pos
end

.get_error_description(code) ⇒ Object



43
44
45
# File 'lib/payu/errors.rb', line 43

def get_error_description(code)
  return ERRORS[code.to_i]
end

.get_pos_by_id(pos_id) ⇒ Object

Returns Pos object with given pos_id, the same as in payments.yml file

Parameters:

  • id (Integer)

    pos_id of Pos

Returns:

  • (Object)

    the Pos object



74
75
76
77
78
79
80
# File 'lib/payu.rb', line 74

def get_pos_by_id(pos_id)
  pos_id = pos_id.to_i rescue 0
  @@pos_table.each do |k, v|
    return v if v.pos_id == pos_id
  end
  nil
end

.get_pos_by_name(name) ⇒ Object

Returns Pos object with given name, the same as in payments.yml file

Parameters:

  • name (String)

    name of Pos

Returns:

  • (Object)

    the Pos object



66
67
68
# File 'lib/payu.rb', line 66

def get_pos_by_name(name)
  @@pos_table[name.to_s]
end

.load_pos_from_yaml(filename) ⇒ Object

Loads configuration from specified YAML file creates Pos objects



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/payu.rb', line 27

def load_pos_from_yaml(filename)
  if File.exist?(filename)
    config = YAML.load_file(filename)
    config.each do |name, config|
      pos = Pos.new(
        :pos_id => config['pos_id'],
        :pos_auth_key => config['pos_auth_key'],
        :key1 => config['key1'],
        :key2 => config['key2'],
        :gateway_url => config['gateway_url'],
        :variant => config['variant'],
        :add_signature => config['add_signature'],
        :test_payment => config['test_payment']
      )
      @@pos_table[name] = pos
    end

    true
  else
    false
  end
end