Class: ParichkiBg::Request::Transaction

Inherits:
Base
  • Object
show all
Defined in:
lib/parichki_bg/request/transaction.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#amount, #pin, #user_id

Instance Method Summary collapse

Methods inherited from Base

#checksum, #encoded_checksum, #encoded_data, #https, #result, #send, #signed_request

Constructor Details

#initialize(attributes = {}) ⇒ Transaction

Returns a new instance of Transaction.



8
9
10
11
# File 'lib/parichki_bg/request/transaction.rb', line 8

def initialize(attributes = {})
  super
  @request_id = attributes.fetch :request_id
end

Instance Attribute Details

#request_idObject (readonly)

Returns the value of attribute request_id.



5
6
7
# File 'lib/parichki_bg/request/transaction.rb', line 5

def request_id
  @request_id
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/parichki_bg/request/transaction.rb', line 6

def type
  @type
end

Instance Method Details

#paid?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/parichki_bg/request/transaction.rb', line 40

def paid?
  result["error"].nil? 
end

#pay_with_cashObject



26
27
28
29
# File 'lib/parichki_bg/request/transaction.rb', line 26

def pay_with_cash
  @type = "cash"
  send
end

#pay_with_pointsObject



31
32
33
34
# File 'lib/parichki_bg/request/transaction.rb', line 31

def pay_with_points
  @type = "points"
  send
end

#success?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/parichki_bg/request/transaction.rb', line 36

def success?
  @response.code == "200" && !@response.body.match(/error/)
end

#to_jsonObject



17
18
19
20
21
22
23
24
# File 'lib/parichki_bg/request/transaction.rb', line 17

def to_json
  {
    amount:     amount.to_s,
    request_id: request_id.to_s,
    type:       type,
    pin:        pin
  }.to_json
end

#uriObject



13
14
15
# File 'lib/parichki_bg/request/transaction.rb', line 13

def uri
  URI "#{ParichkiBg::main_api_url}/#{user_id}/transactions?vendor_id=#{ParichkiBg::vendor_id}&signed_request=#{signed_request}"
end