lib/bs2_api/entities/payment.rb in bs2_api-1.0.3 vs lib/bs2_api/entities/payment.rb in bs2_api-1.1.0

- old
+ new

@@ -11,24 +11,24 @@ @receiver = args.fetch(:receiver, nil) @payer = args.fetch(:payer, nil) end def to_hash - ActiveSupport::HashWithIndifferentAccess.new( - { - "pagamentoId": @payment_id, - "endToEndId": @end_to_end_id, - "recebedor": @receiver.to_hash, - "pagador": @payer.to_hash - } - ) + hash_data = { + "pagamentoId": @payment_id, + "endToEndId": @end_to_end_id + } + + hash_data.merge!({ "recebedor": @receiver.to_hash } ) if @receiver.present? + hash_data.merge!({ "pagador": @payer.to_hash } ) if @payer.present? + ActiveSupport::HashWithIndifferentAccess.new(hash_data) end def self.from_response(hash_payload) hash = ActiveSupport::HashWithIndifferentAccess.new(hash_payload) Bs2Api::Entities::Payment.new( - payment_id: hash["pagamentoId"], + payment_id: hash["pagamentoId"] || hash["cobranca"]["id"], end_to_end_id: hash["endToEndId"], receiver: Bs2Api::Entities::Bank.from_response(hash["recebedor"]), payer: Bs2Api::Entities::Bank.from_response(hash["pagador"]) ) end \ No newline at end of file