Sha256: 84567f3a1f52e12fc9d750224db067cd5f187259f3c83cd07d88356b458994fc

Contents?: true

Size: 1.05 KB

Versions: 10

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module SolidusBolt
  module Transactions
    class CaptureService < 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
        capture
      end

      private

      def capture
        options = build_options
        handle_result(
          HTTParty.post(
            "#{api_base_url}/#{api_version}/merchant/transactions/capture",
            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/capture_service.rb
solidus_bolt-0.7.1 app/services/solidus_bolt/transactions/capture_service.rb
solidus_bolt-0.7.0 app/services/solidus_bolt/transactions/capture_service.rb
solidus_bolt-0.6.0 app/services/solidus_bolt/transactions/capture_service.rb
solidus_bolt-0.5.0 app/services/solidus_bolt/transactions/capture_service.rb
solidus_bolt-0.4.0 app/services/solidus_bolt/transactions/capture_service.rb
solidus_bolt-0.3.0 app/services/solidus_bolt/transactions/capture_service.rb
solidus_bolt-0.2.0 app/services/solidus_bolt/transactions/capture_service.rb
solidus_bolt-0.1.0 app/services/solidus_bolt/transactions/capture_service.rb
solidus_bolt-0.0.1 app/services/solidus_bolt/transactions/capture_service.rb