lib/bs2_api/entities/payment.rb in bs2_api-1.8.0 vs lib/bs2_api/entities/payment.rb in bs2_api-1.9.0
- old
+ new
@@ -1,33 +1,31 @@
# frozen_string_literal: true
module Bs2Api
module Entities
class Payment
- attr_accessor :payment_id, :end_to_end_id, :receiver, :payer, :status, :error_message, :error_code
+ attr_accessor :payment_id, :end_to_end_id, :receiver, :payer, :status, :error
def initialize(args = {})
@payment_id = args.fetch(:payment_id, nil)
@end_to_end_id = args.fetch(:end_to_end_id, nil)
@receiver = args.fetch(:receiver, nil)
@payer = args.fetch(:payer, nil)
@status = args.fetch(:status, nil)
- @error_code = args.fetch(:error_code, nil)
- @error_message = args.fetch(:error_message, nil)
+ @error = args.fetch(:error, nil)
end
def to_hash
hash_data = {
- "pagamentoId": @payment_id,
- "endToEndId": @end_to_end_id,
- "status": @status,
- "error_code": @error_code,
- "error_message": @error_message
+ "pagamentoId": @payment_id,
+ "endToEndId": @end_to_end_id,
+ "status": @status
}
hash_data.merge!({ "recebedor": @receiver.to_hash } ) if @receiver.present?
hash_data.merge!({ "pagador": @payer.to_hash } ) if @payer.present?
+ hash_data.merge!({ "erro": @error.to_hash } ) if @error.present?
ActiveSupport::HashWithIndifferentAccess.new(hash_data)
end
def self.from_response(hash_payload)
hash = ActiveSupport::HashWithIndifferentAccess.new(hash_payload)
@@ -36,11 +34,10 @@
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"]),
status: hash["status"],
- error_code: hash.dig('erro', 'erroCodigo'),
- error_message: hash.dig('erro', 'erroDescricao')
+ error: Bs2Api::Entities::Error.from_response(hash["erro"])
)
end
end
end
end