Class: Conexa::Charge

Inherits:
Model show all
Defined in:
lib/conexa/resources/charge.rb

Overview

Charge resource for billing/invoices

Examples:

Retrieve a charge

charge = Conexa::Charge.find(789)
charge.status  # => "pending"

List charges

charges = Conexa::Charge.all(customer_id: [127], status: 'pending', limit: 50)

Settle (pay) a charge

Conexa::Charge.settle(789)

Constant Summary collapse

STATUSES =

The values status can take on a charge, per the collection's field table for GET /charge/:id.

excluded is here but not in FILTERABLE_STATUSES. The two lists are not the same thing: a charge can hold a status you cannot query by. This constant shipped with nine values in 0.2.1 because it was built from the filter's rejection message rather than from the field table.

%w[unpaid paid negotiated generatedByNegotiation cancelled
denied thirdPartyCompany protested juridical excluded].freeze
FILTERABLE_STATUSES =

What GET /charges?status= accepts. The API names them in the 400 it returns for an unrecognised value, so this list is the API's own:

status=zzz -> 400 "Status is not on the list (unpaid, negotiated,
            generatedByNegotiation, cancelled, paid, denied,
            thirdPartyCompany, protested, juridical)"

pending and overdue are in neither list, which is why the predicates built on them never matched.

(STATUSES - %w[excluded]).freeze

Constants inherited from ConexaObject

Conexa::ConexaObject::RESOURCES

Instance Attribute Summary collapse

Attributes inherited from ConexaObject

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

all, #class_name, class_name, #create, create, #destroy, destroy, extract_page_size_or_params, #fetch, find_by, find_by_id, #id, #primary_key, primary_key_attribute, #primary_key_name, #save, #set_primary_key, show_url, underscored_class_name, url

Methods included from Deprecatable

#deprecate

Methods inherited from ConexaObject

#==, #[]=, convert, #empty?, #initialize, #respond_to_missing?, #to_hash, #unsaved_attributes

Constructor Details

This class inherits a constructor from Conexa::ConexaObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Conexa::ConexaObject

Instance Attribute Details

#amountFloat (readonly)

Returns Charge amount.

Returns:

  • (Float)

    Charge amount



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/conexa/resources/charge.rb', line 29

class Charge < Model
  primary_key_attribute :charge_id

  # The values `status` can take on a charge, per the collection's field table
  # for `GET /charge/:id`.
  #
  # **`excluded` is here but not in {FILTERABLE_STATUSES}.** The two lists are
  # not the same thing: a charge can hold a status you cannot query by. This
  # constant shipped with nine values in 0.2.1 because it was built from the
  # filter's rejection message rather than from the field table.
  STATUSES = %w[unpaid paid negotiated generatedByNegotiation cancelled
                denied thirdPartyCompany protested juridical excluded].freeze

  # What `GET /charges?status=` accepts. The API names them in the 400 it
  # returns for an unrecognised value, so this list is the API's own:
  #
  #   status=zzz -> 400 "Status is not on the list (unpaid, negotiated,
  #                 generatedByNegotiation, cancelled, paid, denied,
  #                 thirdPartyCompany, protested, juridical)"
  #
  # `pending` and `overdue` are in neither list, which is why the predicates
  # built on them never matched.
  FILTERABLE_STATUSES = (STATUSES - %w[excluded]).freeze

  # @return [Boolean]
  def paid?
    status == 'paid'
  end

  # Is this charge still open?
  # @return [Boolean]
  def unpaid?
    status == 'unpaid'
  end

  # @return [Boolean]
  def cancelled?
    status == 'cancelled'
  end

  # @deprecated The API has no `pending` status; the open state is `unpaid`.
  #   This alias only exists so callers written against the old, never-matching
  #   predicate keep working while they migrate.
  # @return [Boolean]
  def pending?
    self.class.deprecate(:pending?,
                         "`Charge#pending?` foi renomeado para `unpaid?` em conexa 0.2.1 — " \
                         "a API v2 não tem status `pending`, o estado em aberto chama-se " \
                         "`unpaid`. O alias será removido em 0.3.0.")
    unpaid?
  end

  # @deprecated The API has no `overdue` status. An overdue charge is `unpaid`
  #   with a `due_date` in the past; compare the date yourself.
  # @return [Boolean] always false
  def overdue?
    self.class.deprecate(:overdue?,
                         "`Charge#overdue?` sempre devolveu false — a API v2 não tem status " \
                         "`overdue`. Use `unpaid?` e compare `due_date`. O método será " \
                         "removido em 0.3.0.")
    false
  end

  # Settle (pay) this charge
  #
  # Moves money and, on a configured tenant, issues an NF-e. Not safe to retry
  # blindly: a second attempt on a settled charge answers 422 CHARGE_11.
  #
  # The API answers 204 with an empty body on success.
  #
  # @param params [Hash] settlement details
  # @option params [String] :settlement_date required, yyyy-MM-dd
  # @option params [Hash] :receiving_method required, {id:, installments_quantity:}
  # @option params [Integer] :account_id required
  # @option params [Float] :paid_amount defaults to the charge amount, without interest
  # @option params [Boolean] :send_email defaults to false
  # @return [self]
  def settle(params = {})
    Conexa::Request.patch(self.class.show_url("settle", primary_key), params: params).call(class_name)
    self
  end

  # Get PIX QR Code for this charge
  # @return [ConexaObject] PIX data including qr_code and qr_code_base64
  def pix
    Conexa::Request.get(self.class.show_url("pix", primary_key)).call("pix")
  end

  # Cancel this charge
  # @return [self]
  def cancel
    Conexa::Request.post(self.class.show_url("cancel", primary_key)).call(class_name)
    self
  end

  # Send charge notification by email
  # @return [self]
  def send_email
    Conexa::Request.post(self.class.show_url("sendEmail", primary_key)).call(class_name)
    self
  end

  class << self
    # Settle a charge by ID
    # @param id [Integer, String] charge ID
    # @param params [Hash] optional payment details
    # @return [Charge]
    def settle(id, params = {})
      find(id).settle(params)
    end

    # Cancel a charge by ID
    # @param id [Integer, String] charge ID
    # @return [Charge]
    def cancel(id)
      find(id).cancel
    end

    # Send email for a charge by ID
    # @param id [Integer, String] charge ID
    # @return [Charge]
    def send_email(id)
      find(id).send_email
    end

    # Get PIX for a charge by ID
    # @param id [Integer, String] charge ID
    # @return [ConexaObject]
    def pix(id)
      find(id).pix
    end
  end
end

#charge_idInteger (readonly)

Returns Charge ID (also accessible as #id).

Returns:

  • (Integer)

    Charge ID (also accessible as #id)



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/conexa/resources/charge.rb', line 29

class Charge < Model
  primary_key_attribute :charge_id

  # The values `status` can take on a charge, per the collection's field table
  # for `GET /charge/:id`.
  #
  # **`excluded` is here but not in {FILTERABLE_STATUSES}.** The two lists are
  # not the same thing: a charge can hold a status you cannot query by. This
  # constant shipped with nine values in 0.2.1 because it was built from the
  # filter's rejection message rather than from the field table.
  STATUSES = %w[unpaid paid negotiated generatedByNegotiation cancelled
                denied thirdPartyCompany protested juridical excluded].freeze

  # What `GET /charges?status=` accepts. The API names them in the 400 it
  # returns for an unrecognised value, so this list is the API's own:
  #
  #   status=zzz -> 400 "Status is not on the list (unpaid, negotiated,
  #                 generatedByNegotiation, cancelled, paid, denied,
  #                 thirdPartyCompany, protested, juridical)"
  #
  # `pending` and `overdue` are in neither list, which is why the predicates
  # built on them never matched.
  FILTERABLE_STATUSES = (STATUSES - %w[excluded]).freeze

  # @return [Boolean]
  def paid?
    status == 'paid'
  end

  # Is this charge still open?
  # @return [Boolean]
  def unpaid?
    status == 'unpaid'
  end

  # @return [Boolean]
  def cancelled?
    status == 'cancelled'
  end

  # @deprecated The API has no `pending` status; the open state is `unpaid`.
  #   This alias only exists so callers written against the old, never-matching
  #   predicate keep working while they migrate.
  # @return [Boolean]
  def pending?
    self.class.deprecate(:pending?,
                         "`Charge#pending?` foi renomeado para `unpaid?` em conexa 0.2.1 — " \
                         "a API v2 não tem status `pending`, o estado em aberto chama-se " \
                         "`unpaid`. O alias será removido em 0.3.0.")
    unpaid?
  end

  # @deprecated The API has no `overdue` status. An overdue charge is `unpaid`
  #   with a `due_date` in the past; compare the date yourself.
  # @return [Boolean] always false
  def overdue?
    self.class.deprecate(:overdue?,
                         "`Charge#overdue?` sempre devolveu false — a API v2 não tem status " \
                         "`overdue`. Use `unpaid?` e compare `due_date`. O método será " \
                         "removido em 0.3.0.")
    false
  end

  # Settle (pay) this charge
  #
  # Moves money and, on a configured tenant, issues an NF-e. Not safe to retry
  # blindly: a second attempt on a settled charge answers 422 CHARGE_11.
  #
  # The API answers 204 with an empty body on success.
  #
  # @param params [Hash] settlement details
  # @option params [String] :settlement_date required, yyyy-MM-dd
  # @option params [Hash] :receiving_method required, {id:, installments_quantity:}
  # @option params [Integer] :account_id required
  # @option params [Float] :paid_amount defaults to the charge amount, without interest
  # @option params [Boolean] :send_email defaults to false
  # @return [self]
  def settle(params = {})
    Conexa::Request.patch(self.class.show_url("settle", primary_key), params: params).call(class_name)
    self
  end

  # Get PIX QR Code for this charge
  # @return [ConexaObject] PIX data including qr_code and qr_code_base64
  def pix
    Conexa::Request.get(self.class.show_url("pix", primary_key)).call("pix")
  end

  # Cancel this charge
  # @return [self]
  def cancel
    Conexa::Request.post(self.class.show_url("cancel", primary_key)).call(class_name)
    self
  end

  # Send charge notification by email
  # @return [self]
  def send_email
    Conexa::Request.post(self.class.show_url("sendEmail", primary_key)).call(class_name)
    self
  end

  class << self
    # Settle a charge by ID
    # @param id [Integer, String] charge ID
    # @param params [Hash] optional payment details
    # @return [Charge]
    def settle(id, params = {})
      find(id).settle(params)
    end

    # Cancel a charge by ID
    # @param id [Integer, String] charge ID
    # @return [Charge]
    def cancel(id)
      find(id).cancel
    end

    # Send email for a charge by ID
    # @param id [Integer, String] charge ID
    # @return [Charge]
    def send_email(id)
      find(id).send_email
    end

    # Get PIX for a charge by ID
    # @param id [Integer, String] charge ID
    # @return [ConexaObject]
    def pix(id)
      find(id).pix
    end
  end
end

#customer_idInteger (readonly)

Returns Customer ID.

Returns:

  • (Integer)

    Customer ID



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/conexa/resources/charge.rb', line 29

class Charge < Model
  primary_key_attribute :charge_id

  # The values `status` can take on a charge, per the collection's field table
  # for `GET /charge/:id`.
  #
  # **`excluded` is here but not in {FILTERABLE_STATUSES}.** The two lists are
  # not the same thing: a charge can hold a status you cannot query by. This
  # constant shipped with nine values in 0.2.1 because it was built from the
  # filter's rejection message rather than from the field table.
  STATUSES = %w[unpaid paid negotiated generatedByNegotiation cancelled
                denied thirdPartyCompany protested juridical excluded].freeze

  # What `GET /charges?status=` accepts. The API names them in the 400 it
  # returns for an unrecognised value, so this list is the API's own:
  #
  #   status=zzz -> 400 "Status is not on the list (unpaid, negotiated,
  #                 generatedByNegotiation, cancelled, paid, denied,
  #                 thirdPartyCompany, protested, juridical)"
  #
  # `pending` and `overdue` are in neither list, which is why the predicates
  # built on them never matched.
  FILTERABLE_STATUSES = (STATUSES - %w[excluded]).freeze

  # @return [Boolean]
  def paid?
    status == 'paid'
  end

  # Is this charge still open?
  # @return [Boolean]
  def unpaid?
    status == 'unpaid'
  end

  # @return [Boolean]
  def cancelled?
    status == 'cancelled'
  end

  # @deprecated The API has no `pending` status; the open state is `unpaid`.
  #   This alias only exists so callers written against the old, never-matching
  #   predicate keep working while they migrate.
  # @return [Boolean]
  def pending?
    self.class.deprecate(:pending?,
                         "`Charge#pending?` foi renomeado para `unpaid?` em conexa 0.2.1 — " \
                         "a API v2 não tem status `pending`, o estado em aberto chama-se " \
                         "`unpaid`. O alias será removido em 0.3.0.")
    unpaid?
  end

  # @deprecated The API has no `overdue` status. An overdue charge is `unpaid`
  #   with a `due_date` in the past; compare the date yourself.
  # @return [Boolean] always false
  def overdue?
    self.class.deprecate(:overdue?,
                         "`Charge#overdue?` sempre devolveu false — a API v2 não tem status " \
                         "`overdue`. Use `unpaid?` e compare `due_date`. O método será " \
                         "removido em 0.3.0.")
    false
  end

  # Settle (pay) this charge
  #
  # Moves money and, on a configured tenant, issues an NF-e. Not safe to retry
  # blindly: a second attempt on a settled charge answers 422 CHARGE_11.
  #
  # The API answers 204 with an empty body on success.
  #
  # @param params [Hash] settlement details
  # @option params [String] :settlement_date required, yyyy-MM-dd
  # @option params [Hash] :receiving_method required, {id:, installments_quantity:}
  # @option params [Integer] :account_id required
  # @option params [Float] :paid_amount defaults to the charge amount, without interest
  # @option params [Boolean] :send_email defaults to false
  # @return [self]
  def settle(params = {})
    Conexa::Request.patch(self.class.show_url("settle", primary_key), params: params).call(class_name)
    self
  end

  # Get PIX QR Code for this charge
  # @return [ConexaObject] PIX data including qr_code and qr_code_base64
  def pix
    Conexa::Request.get(self.class.show_url("pix", primary_key)).call("pix")
  end

  # Cancel this charge
  # @return [self]
  def cancel
    Conexa::Request.post(self.class.show_url("cancel", primary_key)).call(class_name)
    self
  end

  # Send charge notification by email
  # @return [self]
  def send_email
    Conexa::Request.post(self.class.show_url("sendEmail", primary_key)).call(class_name)
    self
  end

  class << self
    # Settle a charge by ID
    # @param id [Integer, String] charge ID
    # @param params [Hash] optional payment details
    # @return [Charge]
    def settle(id, params = {})
      find(id).settle(params)
    end

    # Cancel a charge by ID
    # @param id [Integer, String] charge ID
    # @return [Charge]
    def cancel(id)
      find(id).cancel
    end

    # Send email for a charge by ID
    # @param id [Integer, String] charge ID
    # @return [Charge]
    def send_email(id)
      find(id).send_email
    end

    # Get PIX for a charge by ID
    # @param id [Integer, String] charge ID
    # @return [ConexaObject]
    def pix(id)
      find(id).pix
    end
  end
end

#due_dateString (readonly)

Returns Due date.

Returns:

  • (String)

    Due date



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/conexa/resources/charge.rb', line 29

class Charge < Model
  primary_key_attribute :charge_id

  # The values `status` can take on a charge, per the collection's field table
  # for `GET /charge/:id`.
  #
  # **`excluded` is here but not in {FILTERABLE_STATUSES}.** The two lists are
  # not the same thing: a charge can hold a status you cannot query by. This
  # constant shipped with nine values in 0.2.1 because it was built from the
  # filter's rejection message rather than from the field table.
  STATUSES = %w[unpaid paid negotiated generatedByNegotiation cancelled
                denied thirdPartyCompany protested juridical excluded].freeze

  # What `GET /charges?status=` accepts. The API names them in the 400 it
  # returns for an unrecognised value, so this list is the API's own:
  #
  #   status=zzz -> 400 "Status is not on the list (unpaid, negotiated,
  #                 generatedByNegotiation, cancelled, paid, denied,
  #                 thirdPartyCompany, protested, juridical)"
  #
  # `pending` and `overdue` are in neither list, which is why the predicates
  # built on them never matched.
  FILTERABLE_STATUSES = (STATUSES - %w[excluded]).freeze

  # @return [Boolean]
  def paid?
    status == 'paid'
  end

  # Is this charge still open?
  # @return [Boolean]
  def unpaid?
    status == 'unpaid'
  end

  # @return [Boolean]
  def cancelled?
    status == 'cancelled'
  end

  # @deprecated The API has no `pending` status; the open state is `unpaid`.
  #   This alias only exists so callers written against the old, never-matching
  #   predicate keep working while they migrate.
  # @return [Boolean]
  def pending?
    self.class.deprecate(:pending?,
                         "`Charge#pending?` foi renomeado para `unpaid?` em conexa 0.2.1 — " \
                         "a API v2 não tem status `pending`, o estado em aberto chama-se " \
                         "`unpaid`. O alias será removido em 0.3.0.")
    unpaid?
  end

  # @deprecated The API has no `overdue` status. An overdue charge is `unpaid`
  #   with a `due_date` in the past; compare the date yourself.
  # @return [Boolean] always false
  def overdue?
    self.class.deprecate(:overdue?,
                         "`Charge#overdue?` sempre devolveu false — a API v2 não tem status " \
                         "`overdue`. Use `unpaid?` e compare `due_date`. O método será " \
                         "removido em 0.3.0.")
    false
  end

  # Settle (pay) this charge
  #
  # Moves money and, on a configured tenant, issues an NF-e. Not safe to retry
  # blindly: a second attempt on a settled charge answers 422 CHARGE_11.
  #
  # The API answers 204 with an empty body on success.
  #
  # @param params [Hash] settlement details
  # @option params [String] :settlement_date required, yyyy-MM-dd
  # @option params [Hash] :receiving_method required, {id:, installments_quantity:}
  # @option params [Integer] :account_id required
  # @option params [Float] :paid_amount defaults to the charge amount, without interest
  # @option params [Boolean] :send_email defaults to false
  # @return [self]
  def settle(params = {})
    Conexa::Request.patch(self.class.show_url("settle", primary_key), params: params).call(class_name)
    self
  end

  # Get PIX QR Code for this charge
  # @return [ConexaObject] PIX data including qr_code and qr_code_base64
  def pix
    Conexa::Request.get(self.class.show_url("pix", primary_key)).call("pix")
  end

  # Cancel this charge
  # @return [self]
  def cancel
    Conexa::Request.post(self.class.show_url("cancel", primary_key)).call(class_name)
    self
  end

  # Send charge notification by email
  # @return [self]
  def send_email
    Conexa::Request.post(self.class.show_url("sendEmail", primary_key)).call(class_name)
    self
  end

  class << self
    # Settle a charge by ID
    # @param id [Integer, String] charge ID
    # @param params [Hash] optional payment details
    # @return [Charge]
    def settle(id, params = {})
      find(id).settle(params)
    end

    # Cancel a charge by ID
    # @param id [Integer, String] charge ID
    # @return [Charge]
    def cancel(id)
      find(id).cancel
    end

    # Send email for a charge by ID
    # @param id [Integer, String] charge ID
    # @return [Charge]
    def send_email(id)
      find(id).send_email
    end

    # Get PIX for a charge by ID
    # @param id [Integer, String] charge ID
    # @return [ConexaObject]
    def pix(id)
      find(id).pix
    end
  end
end

Returns Payment date.

Returns:

  • (String, nil)

    Payment date



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/conexa/resources/charge.rb', line 29

class Charge < Model
  primary_key_attribute :charge_id

  # The values `status` can take on a charge, per the collection's field table
  # for `GET /charge/:id`.
  #
  # **`excluded` is here but not in {FILTERABLE_STATUSES}.** The two lists are
  # not the same thing: a charge can hold a status you cannot query by. This
  # constant shipped with nine values in 0.2.1 because it was built from the
  # filter's rejection message rather than from the field table.
  STATUSES = %w[unpaid paid negotiated generatedByNegotiation cancelled
                denied thirdPartyCompany protested juridical excluded].freeze

  # What `GET /charges?status=` accepts. The API names them in the 400 it
  # returns for an unrecognised value, so this list is the API's own:
  #
  #   status=zzz -> 400 "Status is not on the list (unpaid, negotiated,
  #                 generatedByNegotiation, cancelled, paid, denied,
  #                 thirdPartyCompany, protested, juridical)"
  #
  # `pending` and `overdue` are in neither list, which is why the predicates
  # built on them never matched.
  FILTERABLE_STATUSES = (STATUSES - %w[excluded]).freeze

  # @return [Boolean]
  def paid?
    status == 'paid'
  end

  # Is this charge still open?
  # @return [Boolean]
  def unpaid?
    status == 'unpaid'
  end

  # @return [Boolean]
  def cancelled?
    status == 'cancelled'
  end

  # @deprecated The API has no `pending` status; the open state is `unpaid`.
  #   This alias only exists so callers written against the old, never-matching
  #   predicate keep working while they migrate.
  # @return [Boolean]
  def pending?
    self.class.deprecate(:pending?,
                         "`Charge#pending?` foi renomeado para `unpaid?` em conexa 0.2.1 — " \
                         "a API v2 não tem status `pending`, o estado em aberto chama-se " \
                         "`unpaid`. O alias será removido em 0.3.0.")
    unpaid?
  end

  # @deprecated The API has no `overdue` status. An overdue charge is `unpaid`
  #   with a `due_date` in the past; compare the date yourself.
  # @return [Boolean] always false
  def overdue?
    self.class.deprecate(:overdue?,
                         "`Charge#overdue?` sempre devolveu false — a API v2 não tem status " \
                         "`overdue`. Use `unpaid?` e compare `due_date`. O método será " \
                         "removido em 0.3.0.")
    false
  end

  # Settle (pay) this charge
  #
  # Moves money and, on a configured tenant, issues an NF-e. Not safe to retry
  # blindly: a second attempt on a settled charge answers 422 CHARGE_11.
  #
  # The API answers 204 with an empty body on success.
  #
  # @param params [Hash] settlement details
  # @option params [String] :settlement_date required, yyyy-MM-dd
  # @option params [Hash] :receiving_method required, {id:, installments_quantity:}
  # @option params [Integer] :account_id required
  # @option params [Float] :paid_amount defaults to the charge amount, without interest
  # @option params [Boolean] :send_email defaults to false
  # @return [self]
  def settle(params = {})
    Conexa::Request.patch(self.class.show_url("settle", primary_key), params: params).call(class_name)
    self
  end

  # Get PIX QR Code for this charge
  # @return [ConexaObject] PIX data including qr_code and qr_code_base64
  def pix
    Conexa::Request.get(self.class.show_url("pix", primary_key)).call("pix")
  end

  # Cancel this charge
  # @return [self]
  def cancel
    Conexa::Request.post(self.class.show_url("cancel", primary_key)).call(class_name)
    self
  end

  # Send charge notification by email
  # @return [self]
  def send_email
    Conexa::Request.post(self.class.show_url("sendEmail", primary_key)).call(class_name)
    self
  end

  class << self
    # Settle a charge by ID
    # @param id [Integer, String] charge ID
    # @param params [Hash] optional payment details
    # @return [Charge]
    def settle(id, params = {})
      find(id).settle(params)
    end

    # Cancel a charge by ID
    # @param id [Integer, String] charge ID
    # @return [Charge]
    def cancel(id)
      find(id).cancel
    end

    # Send email for a charge by ID
    # @param id [Integer, String] charge ID
    # @return [Charge]
    def send_email(id)
      find(id).send_email
    end

    # Get PIX for a charge by ID
    # @param id [Integer, String] charge ID
    # @return [ConexaObject]
    def pix(id)
      find(id).pix
    end
  end
end

#statusString (readonly)

Returns Status: pending, paid, overdue, cancelled.

Returns:

  • (String)

    Status: pending, paid, overdue, cancelled



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/conexa/resources/charge.rb', line 29

class Charge < Model
  primary_key_attribute :charge_id

  # The values `status` can take on a charge, per the collection's field table
  # for `GET /charge/:id`.
  #
  # **`excluded` is here but not in {FILTERABLE_STATUSES}.** The two lists are
  # not the same thing: a charge can hold a status you cannot query by. This
  # constant shipped with nine values in 0.2.1 because it was built from the
  # filter's rejection message rather than from the field table.
  STATUSES = %w[unpaid paid negotiated generatedByNegotiation cancelled
                denied thirdPartyCompany protested juridical excluded].freeze

  # What `GET /charges?status=` accepts. The API names them in the 400 it
  # returns for an unrecognised value, so this list is the API's own:
  #
  #   status=zzz -> 400 "Status is not on the list (unpaid, negotiated,
  #                 generatedByNegotiation, cancelled, paid, denied,
  #                 thirdPartyCompany, protested, juridical)"
  #
  # `pending` and `overdue` are in neither list, which is why the predicates
  # built on them never matched.
  FILTERABLE_STATUSES = (STATUSES - %w[excluded]).freeze

  # @return [Boolean]
  def paid?
    status == 'paid'
  end

  # Is this charge still open?
  # @return [Boolean]
  def unpaid?
    status == 'unpaid'
  end

  # @return [Boolean]
  def cancelled?
    status == 'cancelled'
  end

  # @deprecated The API has no `pending` status; the open state is `unpaid`.
  #   This alias only exists so callers written against the old, never-matching
  #   predicate keep working while they migrate.
  # @return [Boolean]
  def pending?
    self.class.deprecate(:pending?,
                         "`Charge#pending?` foi renomeado para `unpaid?` em conexa 0.2.1 — " \
                         "a API v2 não tem status `pending`, o estado em aberto chama-se " \
                         "`unpaid`. O alias será removido em 0.3.0.")
    unpaid?
  end

  # @deprecated The API has no `overdue` status. An overdue charge is `unpaid`
  #   with a `due_date` in the past; compare the date yourself.
  # @return [Boolean] always false
  def overdue?
    self.class.deprecate(:overdue?,
                         "`Charge#overdue?` sempre devolveu false — a API v2 não tem status " \
                         "`overdue`. Use `unpaid?` e compare `due_date`. O método será " \
                         "removido em 0.3.0.")
    false
  end

  # Settle (pay) this charge
  #
  # Moves money and, on a configured tenant, issues an NF-e. Not safe to retry
  # blindly: a second attempt on a settled charge answers 422 CHARGE_11.
  #
  # The API answers 204 with an empty body on success.
  #
  # @param params [Hash] settlement details
  # @option params [String] :settlement_date required, yyyy-MM-dd
  # @option params [Hash] :receiving_method required, {id:, installments_quantity:}
  # @option params [Integer] :account_id required
  # @option params [Float] :paid_amount defaults to the charge amount, without interest
  # @option params [Boolean] :send_email defaults to false
  # @return [self]
  def settle(params = {})
    Conexa::Request.patch(self.class.show_url("settle", primary_key), params: params).call(class_name)
    self
  end

  # Get PIX QR Code for this charge
  # @return [ConexaObject] PIX data including qr_code and qr_code_base64
  def pix
    Conexa::Request.get(self.class.show_url("pix", primary_key)).call("pix")
  end

  # Cancel this charge
  # @return [self]
  def cancel
    Conexa::Request.post(self.class.show_url("cancel", primary_key)).call(class_name)
    self
  end

  # Send charge notification by email
  # @return [self]
  def send_email
    Conexa::Request.post(self.class.show_url("sendEmail", primary_key)).call(class_name)
    self
  end

  class << self
    # Settle a charge by ID
    # @param id [Integer, String] charge ID
    # @param params [Hash] optional payment details
    # @return [Charge]
    def settle(id, params = {})
      find(id).settle(params)
    end

    # Cancel a charge by ID
    # @param id [Integer, String] charge ID
    # @return [Charge]
    def cancel(id)
      find(id).cancel
    end

    # Send email for a charge by ID
    # @param id [Integer, String] charge ID
    # @return [Charge]
    def send_email(id)
      find(id).send_email
    end

    # Get PIX for a charge by ID
    # @param id [Integer, String] charge ID
    # @return [ConexaObject]
    def pix(id)
      find(id).pix
    end
  end
end

Class Method Details

.cancel(id) ⇒ Charge

Cancel a charge by ID

Parameters:

  • id (Integer, String)

    charge ID

Returns:



143
144
145
# File 'lib/conexa/resources/charge.rb', line 143

def cancel(id)
  find(id).cancel
end

.pix(id) ⇒ ConexaObject

Get PIX for a charge by ID

Parameters:

  • id (Integer, String)

    charge ID

Returns:



157
158
159
# File 'lib/conexa/resources/charge.rb', line 157

def pix(id)
  find(id).pix
end

.send_email(id) ⇒ Charge

Send email for a charge by ID

Parameters:

  • id (Integer, String)

    charge ID

Returns:



150
151
152
# File 'lib/conexa/resources/charge.rb', line 150

def send_email(id)
  find(id).send_email
end

.settle(id, params = {}) ⇒ Charge

Settle a charge by ID

Parameters:

  • id (Integer, String)

    charge ID

  • params (Hash) (defaults to: {})

    optional payment details

Returns:



136
137
138
# File 'lib/conexa/resources/charge.rb', line 136

def settle(id, params = {})
  find(id).settle(params)
end

Instance Method Details

#cancelself

Cancel this charge

Returns:

  • (self)


119
120
121
122
# File 'lib/conexa/resources/charge.rb', line 119

def cancel
  Conexa::Request.post(self.class.show_url("cancel", primary_key)).call(class_name)
  self
end

#cancelled?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/conexa/resources/charge.rb', line 65

def cancelled?
  status == 'cancelled'
end

#overdue?Boolean

Deprecated.

The API has no overdue status. An overdue charge is unpaid with a due_date in the past; compare the date yourself.

Returns always false.

Returns:

  • (Boolean)

    always false



84
85
86
87
88
89
90
# File 'lib/conexa/resources/charge.rb', line 84

def overdue?
  self.class.deprecate(:overdue?,
                       "`Charge#overdue?` sempre devolveu false — a API v2 não tem status " \
                       "`overdue`. Use `unpaid?` e compare `due_date`. O método será " \
                       "removido em 0.3.0.")
  false
end

#paid?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/conexa/resources/charge.rb', line 54

def paid?
  status == 'paid'
end

#pending?Boolean

Deprecated.

The API has no pending status; the open state is unpaid. This alias only exists so callers written against the old, never-matching predicate keep working while they migrate.

Returns:

  • (Boolean)


73
74
75
76
77
78
79
# File 'lib/conexa/resources/charge.rb', line 73

def pending?
  self.class.deprecate(:pending?,
                       "`Charge#pending?` foi renomeado para `unpaid?` em conexa 0.2.1 — " \
                       "a API v2 não tem status `pending`, o estado em aberto chama-se " \
                       "`unpaid`. O alias será removido em 0.3.0.")
  unpaid?
end

#pixConexaObject

Get PIX QR Code for this charge

Returns:

  • (ConexaObject)

    PIX data including qr_code and qr_code_base64



113
114
115
# File 'lib/conexa/resources/charge.rb', line 113

def pix
  Conexa::Request.get(self.class.show_url("pix", primary_key)).call("pix")
end

#send_emailself

Send charge notification by email

Returns:

  • (self)


126
127
128
129
# File 'lib/conexa/resources/charge.rb', line 126

def send_email
  Conexa::Request.post(self.class.show_url("sendEmail", primary_key)).call(class_name)
  self
end

#settle(params = {}) ⇒ self

Settle (pay) this charge

Moves money and, on a configured tenant, issues an NF-e. Not safe to retry blindly: a second attempt on a settled charge answers 422 CHARGE_11.

The API answers 204 with an empty body on success.

Parameters:

  • params (Hash) (defaults to: {})

    settlement details

Options Hash (params):

  • :settlement_date (String)

    required, yyyy-MM-dd

  • :receiving_method (Hash)

    required, installments_quantity:

  • :account_id (Integer)

    required

  • :paid_amount (Float)

    defaults to the charge amount, without interest

  • :send_email (Boolean)

    defaults to false

Returns:

  • (self)


106
107
108
109
# File 'lib/conexa/resources/charge.rb', line 106

def settle(params = {})
  Conexa::Request.patch(self.class.show_url("settle", primary_key), params: params).call(class_name)
  self
end

#unpaid?Boolean

Is this charge still open?

Returns:

  • (Boolean)


60
61
62
# File 'lib/conexa/resources/charge.rb', line 60

def unpaid?
  status == 'unpaid'
end