Sha256: 51b4aa02892a32ee56a1085dace95554e4ea6a9383ff5de23b559be993b9c938

Contents?: true

Size: 1.05 KB

Versions: 10

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module SolidusBolt
  module Transactions
    class RefundService < SolidusBolt::Transactions::BaseService
      attr_reader :transaction_reference, :amount, :currency

      def initialize(transaction_reference:, amount:, currency:, payment_method:)
        @transaction_reference = transaction_reference
        @amount = amount
        @currency = currency
        super
      end

      def call
        refund
      end

      private

      def refund
        options = build_options
        handle_result(
          HTTParty.post(
            "#{api_base_url}/#{api_version}/merchant/transactions/credit",
            options
          )
        )
      end

      def build_options
        {
          body: {
            transaction_reference: transaction_reference,
            amount: amount,
            currency: currency
          }.to_json,
          headers: {
            'X-Nonce' => generate_nonce,
            'Content-Type' => 'application/json'
          }.merge(authentication_header)
        }
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
solidus_bolt-0.7.2 app/services/solidus_bolt/transactions/refund_service.rb
solidus_bolt-0.7.1 app/services/solidus_bolt/transactions/refund_service.rb
solidus_bolt-0.7.0 app/services/solidus_bolt/transactions/refund_service.rb
solidus_bolt-0.6.0 app/services/solidus_bolt/transactions/refund_service.rb
solidus_bolt-0.5.0 app/services/solidus_bolt/transactions/refund_service.rb
solidus_bolt-0.4.0 app/services/solidus_bolt/transactions/refund_service.rb
solidus_bolt-0.3.0 app/services/solidus_bolt/transactions/refund_service.rb
solidus_bolt-0.2.0 app/services/solidus_bolt/transactions/refund_service.rb
solidus_bolt-0.1.0 app/services/solidus_bolt/transactions/refund_service.rb
solidus_bolt-0.0.1 app/services/solidus_bolt/transactions/refund_service.rb