Class: Vpago::VattanacMiniApp::RefundIssuer
- Inherits:
-
Base
- Object
- Base
- Vpago::VattanacMiniApp::RefundIssuer
show all
- Defined in:
- lib/vpago/vattanac_mini_app/refund_issuer.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#amount, #currency, #encrypt_data, #expired_at, #initialize, #partner_code, #payload, #payment_id, #refund_url, #transaction_id
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
4
5
6
|
# File 'lib/vpago/vattanac_mini_app/refund_issuer.rb', line 4
def response
@response
end
|
Instance Method Details
#call ⇒ Object
6
7
8
9
|
# File 'lib/vpago/vattanac_mini_app/refund_issuer.rb', line 6
def call
raw_response = send_refund_request
@response = handle_response(raw_response)
end
|
#handle_response(response) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/vpago/vattanac_mini_app/refund_issuer.rb', line 25
def handle_response(response)
body = parse_json(response.body)
if body['status'] == 'SUCCESS'
json = Vpago::VattanacMiniAppDataHandler.new.decrypt_data(body['data'])
@success = true
json
else
@success = false
body
end
end
|
#parse_json(raw) ⇒ Object
47
48
49
50
51
|
# File 'lib/vpago/vattanac_mini_app/refund_issuer.rb', line 47
def parse_json(raw)
JSON.parse(raw)
rescue JSON::ParserError => e
raise StandardError, "Invalid JSON: #{e.message}"
end
|
#refund_payload ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/vpago/vattanac_mini_app/refund_issuer.rb', line 38
def refund_payload
{
transactionId: @payment.transaction_response["transactionId"],
paymentId: @payment.transaction_response["paymentId"],
amount: @payment.transaction_response["amount"],
currency: 'USD'
}
end
|
#send_refund_request ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/vpago/vattanac_mini_app/refund_issuer.rb', line 15
def send_refund_request
Faraday.post(refund_url) do |req|
req.['Content-Type'] = 'application/json'
req.['Partner-Code'] = partner_code
req.body = {
data: Vpago::VattanacMiniAppDataHandler.new.encrypted_data(refund_payload)
}.to_json
end
end
|
#success? ⇒ Boolean
11
12
13
|
# File 'lib/vpago/vattanac_mini_app/refund_issuer.rb', line 11
def success?
@success
end
|