Class: Nihaopay::Transactions::Refund

Inherits:
Base
  • Object
show all
Defined in:
lib/nihaopay/transactions/refund.rb

Constant Summary collapse

VALID_OPTIONS =
%i(reason).freeze

Constants included from Api

Api::LIVE_HOST, Api::TEST_HOST, Api::VERSION

Instance Attribute Summary collapse

Attributes inherited from Base

#amount, #captured, #currency, #note, #reference, #status, #time, #token, #transaction_id, #type

Class Method Summary collapse

Methods inherited from Base

build, build_from_response!, #cancel, #capture, #initialize, #partial_capture, #partial_refund, #refund, #release, request_body, request_headers

Methods included from Queryable

included

Methods included from Api

included

Constructor Details

This class inherits a constructor from Nihaopay::Transactions::Base

Instance Attribute Details

#refund_transaction_idObject

Returns the value of attribute refund_transaction_id.



6
7
8
# File 'lib/nihaopay/transactions/refund.rb', line 6

def refund_transaction_id
  @refund_transaction_id
end

#refundedObject

Returns the value of attribute refunded.



6
7
8
# File 'lib/nihaopay/transactions/refund.rb', line 6

def refunded
  @refunded
end

Class Method Details

.request_url(transaction_id) ⇒ Object



17
18
19
# File 'lib/nihaopay/transactions/refund.rb', line 17

def request_url(transaction_id)
  "#{base_url}/transactions/#{transaction_id}/refund"
end

.response_keys_mapObject



25
26
27
# File 'lib/nihaopay/transactions/refund.rb', line 25

def response_keys_map
  { id: :transaction_id, transaction_id: :refund_transaction_id }
end

.start(transaction_id, amount, currency, options = {}) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/nihaopay/transactions/refund.rb', line 9

def start(transaction_id, amount, currency, options = {})
  @token = options.delete(:token)
  url = request_url(transaction_id)
  params = Nihaopay::HashUtil.slice(options, *VALID_OPTIONS).merge(amount: amount, currency: currency)
  response = HTTParty.post(url, headers: request_headers, body: request_body(params))
  build_from_response!(response)
end

.valid_attributesObject



21
22
23
# File 'lib/nihaopay/transactions/refund.rb', line 21

def valid_attributes
  %i(transaction_id status refunded refund_transaction_id)
end