Class: Bs2Api::Entities::Payment

Inherits:
Object
  • Object
show all
Defined in:
lib/bs2_api/entities/payment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Payment

Returns a new instance of Payment.



8
9
10
11
12
13
14
15
# File 'lib/bs2_api/entities/payment.rb', line 8

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         = args.fetch(:error, nil)
end

Instance Attribute Details

#end_to_end_idObject

Returns the value of attribute end_to_end_id.



6
7
8
# File 'lib/bs2_api/entities/payment.rb', line 6

def end_to_end_id
  @end_to_end_id
end

#errorObject

Returns the value of attribute error.



6
7
8
# File 'lib/bs2_api/entities/payment.rb', line 6

def error
  @error
end

#payerObject

Returns the value of attribute payer.



6
7
8
# File 'lib/bs2_api/entities/payment.rb', line 6

def payer
  @payer
end

#payment_idObject

Returns the value of attribute payment_id.



6
7
8
# File 'lib/bs2_api/entities/payment.rb', line 6

def payment_id
  @payment_id
end

#receiverObject

Returns the value of attribute receiver.



6
7
8
# File 'lib/bs2_api/entities/payment.rb', line 6

def receiver
  @receiver
end

#statusObject

Returns the value of attribute status.



6
7
8
# File 'lib/bs2_api/entities/payment.rb', line 6

def status
  @status
end

Class Method Details

.from_response(hash_payload) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bs2_api/entities/payment.rb', line 30

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

  Bs2Api::Entities::Payment.new(
    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:         Bs2Api::Entities::Error.from_response(hash["erro"])
  )
end

Instance Method Details

#to_hashObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bs2_api/entities/payment.rb', line 17

def to_hash
  hash_data = {
    "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