Class: DPay::RefundService
- Inherits:
-
Object
- Object
- DPay::RefundService
- Defined in:
- lib/dpay/refund/refund_service.rb,
sig/dpay/refund/refund_service.rbs
Constant Summary collapse
- AVAILABILITY_STATUSES =
[200, 400, 402, 406, 409, 410, 411].freeze
Instance Method Summary collapse
- #availability_outcome?(status, data) ⇒ Boolean
- #check_availability(transaction_id, amount = nil, reason = nil) ⇒ RefundAvailability
- #create(transaction_id, amount = nil, reason = nil) ⇒ Refund
-
#initialize(api) ⇒ RefundService
constructor
A new instance of RefundService.
- #signed_body(transaction_id, amount, reason) ⇒ Hash[String, untyped]
Constructor Details
#initialize(api) ⇒ RefundService
Returns a new instance of RefundService.
7 8 9 |
# File 'lib/dpay/refund/refund_service.rb', line 7 def initialize(api) @api = api end |
Instance Method Details
#availability_outcome?(status, data) ⇒ Boolean
31 32 33 34 35 |
# File 'lib/dpay/refund/refund_service.rb', line 31 def availability_outcome?(status, data) return true if AVAILABILITY_STATUSES.include?(status) status == 401 && data["message"] != "Unauthorized request" end |
#check_availability(transaction_id, amount = nil, reason = nil) ⇒ RefundAvailability
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dpay/refund/refund_service.rb', line 17 def check_availability(transaction_id, amount = nil, reason = nil) body = signed_body(transaction_id, amount, reason) response = @api.send_raw("POST", Internal::BaseUrls::PANEL, "/api/v1/pbl/check-refund-availability", body) data = response.decode_json if data.is_a?(Hash) && data.key?("refund") && availability_outcome?(response.status, data) return RefundAvailability.from_api(data, response.status) end raise @api.map_error(response) end |
#create(transaction_id, amount = nil, reason = nil) ⇒ Refund
11 12 13 14 15 |
# File 'lib/dpay/refund/refund_service.rb', line 11 def create(transaction_id, amount = nil, reason = nil) body = signed_body(transaction_id, amount, reason) Refund.from_api(@api.post_json(Internal::BaseUrls::PANEL, "/api/v1/pbl/refund", body)) end |
#signed_body(transaction_id, amount, reason) ⇒ Hash[String, untyped]
37 38 39 40 41 42 43 44 |
# File 'lib/dpay/refund/refund_service.rb', line 37 def signed_body(transaction_id, amount, reason) body = { "service" => @api.service, "transaction_id" => transaction_id } body["value"] = amount.to_decimal unless amount.nil? body["reason"] = reason unless reason.nil? body["checksum"] = @api.checksum.ordered_body(body.values) body end |