Class: Transbank::Onepay::Refund

Inherits:
Object
  • Object
show all
Extended by:
Utils::NetHelper, Utils::RequestBuilder
Defined in:
lib/transbank/sdk/onepay/models/refund.rb

Constant Summary collapse

REFUND_TRANSACTION =

Manages Refunds

'nullifytransaction'.freeze
TRANSACTION_BASE_PATH =
'/ewallet-plugin-api-services/services/transactionservice/'.freeze

Class Method Summary collapse

Methods included from Utils::NetHelper

http_delete, http_get, http_post, http_put, keys_to_camel_case, patpass_comercio_headers, snake_to_camel_case, webpay_headers

Class Method Details

.create(amount:, occ:, external_unique_number:, authorization_code:, options: nil) ⇒ Object

Create a request for a Refund

Transaction

to be refunded

will be refunded is successfully committed (with the #commit method of [Transaction])

Parameters:

  • amount (Integer)

    Amount to be refunded. Must be the full amount of the

  • occ (String)

    Merchant purchase order

  • external_unique_number (String)

    Unique identifier (per Merchant) of the [Transaction] that

  • authorization_code (String)

    Authorization code. This is given when the [Transaction]

  • options (Hash, nil) (defaults to: nil)

    an optional Hash with configuration overrides

Raises:

  • (RefundCreateError)

    if the response is nil or has no response code

  • (RefundCreateError)

    if response from the service is not equal to ‘OK’



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/transbank/sdk/onepay/models/refund.rb', line 21

def create(amount:, occ:, external_unique_number:, authorization_code:, options: nil)
  refund_request = refund_transaction(refund_amount: amount,
                                      occ: occ,
                                      external_unique_number: external_unique_number,
                                      authorization_code: authorization_code,
                                      options: options)
  response = http_post(uri_string: refund_path, body: refund_request.to_h)
  if response.nil? || !JSON.parse(response.body)['responseCode']
    raise Errors::RefundCreateError, 'Could not obtain a response from the service.'
  end

  refund_create_response = RefundCreateResponse.new(JSON.parse(response.body))

  unless refund_create_response.response_ok?
    raise Errors::RefundCreateError, refund_create_response.full_description
  end

  refund_create_response
end

.refund_pathString

Return the string url to POST to

Returns:

  • (String)

    the url to POST to



43
44
45
# File 'lib/transbank/sdk/onepay/models/refund.rb', line 43

def refund_path
  Base.current_integration_type_url + TRANSACTION_BASE_PATH + REFUND_TRANSACTION
end