Class: ParichkiBg::Request::Query
- Inherits:
-
Base
- Object
- Base
- ParichkiBg::Request::Query
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
#status ⇒ Object
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_transaction ⇒ Object
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
34
35
36
|
# File 'lib/parichki_bg/request/query.rb', line 34
def can_pay?
!!result["allow_virtual"]
end
|
#make_cash_transaction ⇒ Object
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_transaction ⇒ Object
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
|
#send ⇒ Object
23
24
25
26
|
# File 'lib/parichki_bg/request/query.rb', line 23
def send
@status = 0
super
end
|
#success? ⇒ 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_json ⇒ Object
28
29
30
31
32
|
# File 'lib/parichki_bg/request/query.rb', line 28
def to_json
{
amount: "#{amount}"
}.to_json
end
|