Class: Payments::Pos
- Inherits:
-
Object
- Object
- Payments::Pos
- Defined in:
- lib/payments_pl/pos.rb
Instance Attribute Summary collapse
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
-
#key1 ⇒ Object
readonly
Returns the value of attribute key1.
-
#key2 ⇒ Object
readonly
Returns the value of attribute key2.
-
#pos_auth_key ⇒ Object
readonly
Returns the value of attribute pos_auth_key.
-
#pos_id ⇒ Object
readonly
Returns the value of attribute pos_id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #cancel(session_id) ⇒ Object
- #confirm(session_id) ⇒ Object
- #get(session_id) ⇒ Object
-
#initialize(options) ⇒ Object
constructor
Creates new Pos instance.
-
#new_transaction(options = {}) ⇒ Object
Creates new transaction.
-
#new_transaction_url ⇒ String
Returns new transaction url, depending on Pos type.
Constructor Details
#initialize(options) ⇒ Object
Creates new Pos instance
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() .symbolize_keys! @pos_id = [:pos_id] @pos_auth_key = [:pos_auth_key] @key1 = [:key1] @key2 = [:key2] @type = [:type] || 'default' @encoding = [:encoding] || 'UTF' @test_payment = !![:test_payment] || false @add_sig = !![: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
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
5 6 7 |
# File 'lib/payments_pl/pos.rb', line 5 def encoding @encoding end |
#key1 ⇒ Object (readonly)
Returns the value of attribute key1.
5 6 7 |
# File 'lib/payments_pl/pos.rb', line 5 def key1 @key1 end |
#key2 ⇒ Object (readonly)
Returns the value of attribute key2.
5 6 7 |
# File 'lib/payments_pl/pos.rb', line 5 def key2 @key2 end |
#pos_auth_key ⇒ Object (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_id ⇒ Object (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 |
#type ⇒ Object (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
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( = {}) = .dup.symbolize_keys! [:pos_id] = @pos_id [:pos_auth_key] = @pos_auth_key [:session_id] ||= (Time.now.to_f * 100).to_i [:pay_type] = 't' if @test_payment && @type == 'default' if @add_sig ts, sig = generate_sig() [:ts] = ts [:sig] = sig end Transaction.new() end |
#new_transaction_url ⇒ String
Returns new transaction url, depending on Pos type
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 |