module Klarna::Checkout::Operations::Refund

Public Instance Methods

refund_order(amount: nil, description: nil) click to toggle source
# File lib/klarna/checkout/operations/refund.rb, line 7
def refund_order(amount: nil, description: nil)
  response = execute_refund_request(amount, description)

  unless response.status == 201
    raise Klarna::Checkout::Errors::OrderRefundError.new(@status, 'refund_not_allowed')
  end

  @status = 'REFUNDED'
  response
end

Private Instance Methods

execute_refund_request(amount, description = nil) click to toggle source
# File lib/klarna/checkout/operations/refund.rb, line 20
def execute_refund_request(amount, description = nil)
  https_connection.post do |req|
    req.url "/ordermanagement/v1/orders/#{@reference}/refunds"
    req.options.timeout = 10

    req.headers['Authorization'] = authorization
    req.headers['Content-Type']  = 'application/json'
    req.body = {
      'refunded_amount': amount.nil? ? @klarna_response['order_amount'] : amount,
      'description': description.nil? ? '' : description,
      'order_lines': @items
    }.to_json
  end
end