Class: ParichkiBg::Request::Query

Inherits:
Base
  • Object
show all
Defined in:
lib/parichki_bg/request/query.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, #signed_request

Constructor Details

#initialize(attributes = {}) ⇒ Query

status 0 unused request_id status 1 used request_id



13
14
15
16
17
# File 'lib/parichki_bg/request/query.rb', line 13

def initialize(attributes = {})
  super
  @pin = attributes[:pin]
  @status = 0
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#build_transactionObject

Raises:



42
43
44
45
46
# File 'lib/parichki_bg/request/query.rb', line 42

def build_transaction
  raise UsedRequestId if @status == 1
  used_request_id
  Transaction.new(amount: amount, request_id: result["request_id"], user_id: user_id, pin: pin)
end

#can_pay?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/parichki_bg/request/query.rb', line 34

def can_pay?
  !!result["allow_virtual"]        
end

#make_cash_transactionObject



48
49
50
# File 'lib/parichki_bg/request/query.rb', line 48

def make_cash_transaction
  build_transaction.tap {|x| x.pay_with_cash}
end

#make_point_transactionObject



52
53
54
# File 'lib/parichki_bg/request/query.rb', line 52

def make_point_transaction
  build_transaction.tap {|x| x.pay_with_points}
end

#sendObject



23
24
25
26
# File 'lib/parichki_bg/request/query.rb', line 23

def send
  @status = 0
  super
end

#success?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/parichki_bg/request/query.rb', line 38

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

#to_jsonObject



28
29
30
31
32
# File 'lib/parichki_bg/request/query.rb', line 28

def to_json
  {
    amount: "#{amount}"
  }.to_json
end

#uriObject



19
20
21
# File 'lib/parichki_bg/request/query.rb', line 19

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