Sha256: bb3a20a78e55f648e8a699b81dbd1641831d0354f2beda3a312140d2e22df995

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Bs2Api
  module Entities
    class Payment
      attr_accessor :id, :merchant_id, :receiver, :payer

      def initialize(args = {})
        @id          = args.fetch(:id, nil)
        @merchant_id = args.fetch(:merchant_id, nil)
        @receiver    = args.fetch(:receiver, nil)
        @payer       = args.fetch(:payer, nil)
      end

      def to_hash
        ActiveSupport::HashWithIndifferentAccess.new(
          {
            "pagamentoId": @id,
            "endToEndId": @merchant_id,
            "recebedor": @receiver.to_hash,
            "pagador": @payer.to_hash
          }
        )
      end

      def self.from_response(hash_payload)
        hash = ActiveSupport::HashWithIndifferentAccess.new(hash_payload)

        Bs2Api::Entities::Payment.new(
          id: hash["pagamentoId"],
          merchant_id: hash["endToEndId"],
          receiver: Bs2Api::Entities::Bank.from_response(hash["recebedor"]),
          payer: Bs2Api::Entities::Bank.from_response(hash["pagador"])
        )
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bs2_api-0.4.0 lib/bs2_api/entities/payment.rb
bs2_api-0.3.4 lib/bs2_api/entities/payment.rb
bs2_api-0.3.3 lib/bs2_api/entities/payment.rb
bs2_api-0.3.2 lib/bs2_api/entities/payment.rb
bs2_api-0.3.1 lib/bs2_api/entities/payment.rb
bs2_api-0.3.0 lib/bs2_api/entities/payment.rb
bs2_api-0.2.1 lib/bs2_api/entities/payment.rb
bs2_api-0.2.0 lib/bs2_api/entities/payment.rb