Class: Pagseguro::Charge::ChargeResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/pagseguro/charge/charge_response.rb

Constant Summary collapse

STATUS_AUTHORIZED =
'AUTHORIZED'.freeze
STATUS_DECLINED =
'DECLINED'.freeze
STATUS_PAID =
'PAID'.freeze
STATUS_CANCELED =
'CANCELED'.freeze
STATUS_PENDING =
'WAITING'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChargeResponse

Returns a new instance of ChargeResponse.



22
23
# File 'lib/pagseguro/charge/charge_response.rb', line 22

def initialize
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



5
6
7
# File 'lib/pagseguro/charge/charge_response.rb', line 5

def amount
  @amount
end

#created_atObject

Returns the value of attribute created_at.



5
6
7
# File 'lib/pagseguro/charge/charge_response.rb', line 5

def created_at
  @created_at
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/pagseguro/charge/charge_response.rb', line 5

def description
  @description
end

#error_messagesObject

Returns the value of attribute error_messages.



5
6
7
# File 'lib/pagseguro/charge/charge_response.rb', line 5

def error_messages
  @error_messages
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/pagseguro/charge/charge_response.rb', line 5

def id
  @id
end

Returns the value of attribute links.



5
6
7
# File 'lib/pagseguro/charge/charge_response.rb', line 5

def links
  @links
end

#payment_methodObject

Returns the value of attribute payment_method.



5
6
7
# File 'lib/pagseguro/charge/charge_response.rb', line 5

def payment_method
  @payment_method
end

#payment_responseObject

Returns the value of attribute payment_response.



5
6
7
# File 'lib/pagseguro/charge/charge_response.rb', line 5

def payment_response
  @payment_response
end

#reference_idObject

Returns the value of attribute reference_id.



5
6
7
# File 'lib/pagseguro/charge/charge_response.rb', line 5

def reference_id
  @reference_id
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/pagseguro/charge/charge_response.rb', line 5

def status
  @status
end

Class Method Details

.fill_from_json(data) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pagseguro/charge/charge_response.rb', line 31

def self.fill_from_json(data)
  return if data.nil?

  charge_response = new

  charge_response.reference_id = data["reference_id"]
  charge_response.id = data["id"]
  charge_response.status = data["status"]
  charge_response.amount = Amount.fill_from_json(data["amount"])
  charge_response.created_at = data["created_at"]
  charge_response.description = data["description"]
  charge_response.payment_response = PaymentResponse.fill_from_json(data["payment_response"])
  charge_response.payment_method = PaymentMethod.fill_from_json(data["payment_method"])

  charge_response.error_messages = data["error_messages"].map{|a| ErrorMessage.fill_from_json(a)} unless data["error_messages"].blank?
  charge_response.links = data["links"].map{|a| Link.fill_from_json(a)} unless data["links"].blank?

  charge_response
end

Instance Method Details

#as_json(options = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pagseguro/charge/charge_response.rb', line 52

def as_json(options={})
  {
    id: @id,
    reference_id: @reference_id,
    status: @status,
    amount: @amount,
    created_at: @created_at,
    description: @description,
    payment_response: @payment_response,
    payment_method: @payment_method,
    error_messages: @error_messages,
    links: @links
  }
end

#authorized?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/pagseguro/charge/charge_response.rb', line 70

def authorized?
  @status == STATUS_AUTHORIZED
end

#canceled?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/pagseguro/charge/charge_response.rb', line 82

def canceled?
  @status == STATUS_CANCELED
end

#captured?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/pagseguro/charge/charge_response.rb', line 78

def captured?
  @status == STATUS_PAID
end

#declined?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/pagseguro/charge/charge_response.rb', line 74

def declined?
  @status == STATUS_DECLINED
end

#paid?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/pagseguro/charge/charge_response.rb', line 67

def paid?
  @status == STATUS_PAID
end

#to_json(*options) ⇒ Object



25
26
27
28
29
# File 'lib/pagseguro/charge/charge_response.rb', line 25

def to_json(*options)
  hash = as_json(*options)
  hash.reject! {|k,v| v.nil?}
  hash.to_json(*options)
end