Sha256: f5f456d5f87dec5e79d0de548edb919f9250bc64fc0030e2b90a6b606a61d35c

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require 'faraday'
require 'json'

module Fawry
  class Connection
    FAWRY_BASE_URL = 'https://www.atfawry.com/ECommerceWeb/Fawry/payments/'

    FAWRY_SANDBOX_BASE_URL = 'https://atfawry.fawrystaging.com//ECommerceWeb/Fawry/payments/'

    class << self
      def post(path, params, body, options)
        conn = options[:sandbox] ? sandbox_connection : connection

        conn.post(path) do |request|
          request.params = params
          request.body = body.to_json
        end
      end

      private

      def connection
        @connection ||= Faraday.new(url: FAWRY_BASE_URL, headers: { 'Content-Type': 'application/json',
                                                                    'Accept': 'application/json' })
      end

      def sandbox_connection
        @sandbox_connection ||= Faraday.new(url: FAWRY_SANDBOX_BASE_URL, headers: { 'Content-Type': 'application/json',
                                                                                    'Accept': 'application/json' })
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fawry-0.1.0 lib/fawry/connection.rb