Sha256: 2a98610d0578a4cba5797bd02d9135842641cbd178f14f936b173a32a3ae6803

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

module Bs2Api
  module Payment
    class Base
      attr_reader :payment

      def initialize
        raise NoMethodError, "Missing #{__method__} to #{self.class}"
      end

      def call
        response = post_request
        raise Bs2Api::Errors::BadRequest, ::Util::Response.parse_error(response) unless response.created?
        
        @payment = Bs2Api::Entities::Payment.from_response(response)
        self
      end

      private
        def post_request
          HTTParty.post(url, headers: headers, body: payload.to_json)
        end

        def headers
          {
            "Content-Type": "application/json",
            "Accept": "application/json",
            "Authorization": "Bearer #{bearer_token}"
          }
        end

        def bearer_token
          Bs2Api::Request::Auth.token
        end

        def payload
          raise NoMethodError, "Missing #{__method__} to #{self.class}"
        end
        
        def url
          raise NoMethodError, "Missing #{__method__} to #{self.class}"
        end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bs2_api-1.0.0 lib/bs2_api/payment/base.rb
bs2_api-0.4.0 lib/bs2_api/payment/base.rb
bs2_api-0.3.4 lib/bs2_api/payment/base.rb