Sha256: 53a3c19c06e1bebda10346a33bf2da72a98e61b216feed51d914ef9f2ea5efd7

Contents?: true

Size: 958 Bytes

Versions: 3

Compression:

Stored size: 958 Bytes

Contents

# frozen_string_literal: true

module Fawry
  class FawryRequest
    DEFAULT_OPTIONS = { sandbox: false }.freeze

    attr_reader :action, :params, :request, :options

    def initialize(action, params, opts)
      @action = action
      @params = params
      @options = DEFAULT_OPTIONS.merge(opts)

      build_request
    end

    private

    # rubocop:disable Metrics/MethodLength
    def build_request
      case action
      when 'charge'
        self.class.include Requests::ChargeRequest
        validate_charge_params!
        @request = build_charge_request
      when 'refund'
        self.class.include Requests::RefundRequest
        validate_refund_params!
        @request = build_refund_request
      when 'payment_status'
        self.class.include Requests::PaymentStatusRequest
        validate_payment_status_params!
        @request = build_payment_status_request
      end
      # rubocop:enable Metrics/MethodLength
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fawry-1.0.0 lib/fawry/fawry_request.rb
fawry-0.3.0 lib/fawry/fawry_request.rb
fawry-0.2.0 lib/fawry/fawry_request.rb