Class: Payu::Pos

Inherits:
Object
  • Object
show all
Defined in:
lib/payu/pos.rb

Constant Summary collapse

TYPES =
['default', 'sms']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Object

Creates new Pos instance

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/payu/pos.rb', line 15

def initialize(options)
  @pos_id        = options[:pos_id].to_i
  @pos_auth_key  = options[:pos_auth_key]
  @key1          = options[:key1]
  @key2          = options[:key2]
  @variant       = options[:variant] || 'default'
  @encoding      = options[:encoding] || 'UTF'
  @test_payment  = options[:test_payment] || false
  @add_signature = options[:add_signature] || false

  raise PosInvalid.new('Missing pos_id parameter') if pos_id.nil? || pos_id == 0
  raise PosInvalid.new('Missing pos_auth_key parameter') if pos_auth_key.nil? || pos_auth_key == ''
  raise PosInvalid.new('Missing key1 parameter') if key1.nil? || key1 == ''
  raise PosInvalid.new('Missing key2 parameter') if key2.nil? || key2 == ''
  raise PosInvalid.new("Invalid variant parameter, expected one of these: #{TYPES.join(', ')}") unless TYPES.include?(variant)
  raise PosInvalid.new("Invalid encoding parameter, expected one of these: #{ENCODINGS.join(', ')}") unless ENCODINGS.include?(encoding)
end

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



10
11
12
# File 'lib/payu/pos.rb', line 10

def encoding
  @encoding
end

#key1Object (readonly)

Returns the value of attribute key1.



10
11
12
# File 'lib/payu/pos.rb', line 10

def key1
  @key1
end

#key2Object (readonly)

Returns the value of attribute key2.



10
11
12
# File 'lib/payu/pos.rb', line 10

def key2
  @key2
end

#pos_auth_keyObject (readonly)

Returns the value of attribute pos_auth_key.



10
11
12
# File 'lib/payu/pos.rb', line 10

def pos_auth_key
  @pos_auth_key
end

#pos_idObject (readonly)

Returns the value of attribute pos_id.



10
11
12
# File 'lib/payu/pos.rb', line 10

def pos_id
  @pos_id
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/payu/pos.rb', line 10

def type
  @type
end

#variantObject (readonly)

Returns the value of attribute variant.



10
11
12
# File 'lib/payu/pos.rb', line 10

def variant
  @variant
end

Instance Method Details

#add_signature?Boolean



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

def add_signature?
  @add_signature
end

#cancel(session_id) ⇒ Object



63
64
65
# File 'lib/payu/pos.rb', line 63

def cancel(session_id)
  get_gateway.cancel(session_id)
end

#confirm(session_id) ⇒ Object



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

def confirm(session_id)
  get_gateway.confirm(session_id)
end

#get(session_id) ⇒ Object



55
56
57
# File 'lib/payu/pos.rb', line 55

def get(session_id)
  get_gateway.get(session_id)
end

#new_transaction(options = {}) ⇒ Object

Creates new transaction



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/payu/pos.rb', line 36

def new_transaction(options = {})
  options = options.dup

  options.merge!({
    :pos_id => @pos_id,
    :pos_auth_key => @pos_auth_key,
    :key1 => @key1,
    :add_signature => add_signature?,
    :encoding => encoding,
    :variant => variant
  })

  if !options.has_key?(:pay_type)
    options[:pay_type] = test_payment? ? 't' : nil
  end

  Transaction.new(options)
end