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

Parameters:

  • options (Hash)

    options hash



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

def initialize(options)
  @pos_id        = options[:pos_id].to_i
  @pos_auth_key  = options[:pos_auth_key]
  @key1          = options[:key1]
  @key2          = options[:key2]
  @gateway_url   = options[:gateway_url] || 'www.platnosci.pl'
  @variant       = options[:variant] || 'default'
  @encoding      = options[:encoding] || 'UTF'
  @test_payment  = options.fetch(:test_payment, false)
  @add_signature = options.fetch(:add_signature, true)

  validate_options!
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

#gateway_urlObject (readonly)

Returns the value of attribute gateway_url.



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

def gateway_url
  @gateway_url
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

Returns:

  • (Boolean)


77
78
79
# File 'lib/payu/pos.rb', line 77

def add_signature?
  @add_signature
end

#cancel(session_id) ⇒ Object



73
74
75
# File 'lib/payu/pos.rb', line 73

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

#confirm(session_id) ⇒ Object



69
70
71
# File 'lib/payu/pos.rb', line 69

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

#get(session_id) ⇒ Object



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

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

#new_transaction(options = {}) ⇒ Object

Creates new transaction

Parameters:

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

    options hash for new transaction

Returns:

  • (Object)

    Transaction object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/payu/pos.rb', line 42

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

  options.merge!({
    :pos_id => @pos_id,
    :pos_auth_key => @pos_auth_key,
    :gateway_url => options[:gateway_url] || @gateway_url,
    :key1 => @key1,
    :encoding => encoding,
    :variant => variant
  })

  if !options.has_key?(:add_signature)
    options[:add_signature] = add_signature?
  end

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

  Transaction.new(options)
end

#validate_options!Object

Raises:



30
31
32
33
34
35
36
37
# File 'lib/payu/pos.rb', line 30

def validate_options!
  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