Class: Payments::Pos

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Object

Creates new Pos instance

Parameters:

  • options (Hash)

    options hash

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/payments_pl/pos.rb', line 10

def initialize(options)
  options.symbolize_keys!

  @pos_id       = options[:pos_id]
  @pos_auth_key = options[:pos_auth_key]
  @key1         = options[:key1]
  @key2         = options[:key2]
  @type         = options[:type] || 'default'
  @encoding     = options[:encoding] || 'UTF'
  @test_payment = !!options[:test_payment] || false
  @add_sig      = !!options[:add_sig] || false

  raise PosInvalid.new('Missing pos_id parameter') if @pos_id.nil? || @pos_id == ''
  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 type parameter, expected one of these: #{Payments::POS_TYPES.join(', ')}") unless Payments::POS_TYPES.include?(@type)
  raise PosInvalid.new("Invalid encoding parameter, expected one of these: #{Payments::ENCODINGS.join(', ')}") unless Payments::ENCODINGS.include?(@encoding)
end

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



5
6
7
# File 'lib/payments_pl/pos.rb', line 5

def encoding
  @encoding
end

#key1Object (readonly)

Returns the value of attribute key1.



5
6
7
# File 'lib/payments_pl/pos.rb', line 5

def key1
  @key1
end

#key2Object (readonly)

Returns the value of attribute key2.



5
6
7
# File 'lib/payments_pl/pos.rb', line 5

def key2
  @key2
end

#pos_auth_keyObject (readonly)

Returns the value of attribute pos_auth_key.



5
6
7
# File 'lib/payments_pl/pos.rb', line 5

def pos_auth_key
  @pos_auth_key
end

#pos_idObject (readonly)

Returns the value of attribute pos_id.



5
6
7
# File 'lib/payments_pl/pos.rb', line 5

def pos_id
  @pos_id
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/payments_pl/pos.rb', line 5

def type
  @type
end

Instance Method Details

#cancel(session_id) ⇒ Object



68
69
70
# File 'lib/payments_pl/pos.rb', line 68

def cancel(session_id)
  send_request(:cancel, session_id)
end

#confirm(session_id) ⇒ Object



64
65
66
# File 'lib/payments_pl/pos.rb', line 64

def confirm(session_id)
  send_request(:confirm, session_id)
end

#get(session_id) ⇒ Object



60
61
62
# File 'lib/payments_pl/pos.rb', line 60

def get(session_id)
  send_request(: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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/payments_pl/pos.rb', line 33

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

  options[:pos_id]        = @pos_id
  options[:pos_auth_key]  = @pos_auth_key
  options[:session_id]    ||= (Time.now.to_f * 100).to_i
  options[:pay_type]      = 't' if @test_payment && @type == 'default'

  if @add_sig
    ts, sig = generate_sig(options)
    options[:ts] = ts
    options[:sig] = sig
  end

  Transaction.new(options)
end

#new_transaction_urlString

Returns new transaction url, depending on Pos type

Returns:

  • (String)

    new transaction url



52
53
54
55
56
57
58
# File 'lib/payments_pl/pos.rb', line 52

def new_transaction_url
  if @type == 'sms_premium'
    return "https://www.platnosci.pl/paygw/#{@encoding}/NewSMS"
  else
    return "https://www.platnosci.pl/paygw/#{@encoding}/NewPayment"
  end
end