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

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 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
# File 'lib/conexa/resources/charge.rb', line 29

class Charge < Model
  primary_key_attribute :charge_id

  # Check if charge is paid
  # @return [Boolean]
  def paid?
    status == 'paid'
  end

  # Check if charge is pending
  # @return [Boolean]
  def pending?
    status == 'pending'
  end

  # Check if charge is overdue
  # @return [Boolean]
  def overdue?
    status == 'overdue'
  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
# File 'lib/conexa/resources/charge.rb', line 29

class Charge < Model
  primary_key_attribute :charge_id

  # Check if charge is paid
  # @return [Boolean]
  def paid?
    status == 'paid'
  end

  # Check if charge is pending
  # @return [Boolean]
  def pending?
    status == 'pending'
  end

  # Check if charge is overdue
  # @return [Boolean]
  def overdue?
    status == 'overdue'
  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
# File 'lib/conexa/resources/charge.rb', line 29

class Charge < Model
  primary_key_attribute :charge_id

  # Check if charge is paid
  # @return [Boolean]
  def paid?
    status == 'paid'
  end

  # Check if charge is pending
  # @return [Boolean]
  def pending?
    status == 'pending'
  end

  # Check if charge is overdue
  # @return [Boolean]
  def overdue?
    status == 'overdue'
  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
# File 'lib/conexa/resources/charge.rb', line 29

class Charge < Model
  primary_key_attribute :charge_id

  # Check if charge is paid
  # @return [Boolean]
  def paid?
    status == 'paid'
  end

  # Check if charge is pending
  # @return [Boolean]
  def pending?
    status == 'pending'
  end

  # Check if charge is overdue
  # @return [Boolean]
  def overdue?
    status == 'overdue'
  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
# File 'lib/conexa/resources/charge.rb', line 29

class Charge < Model
  primary_key_attribute :charge_id

  # Check if charge is paid
  # @return [Boolean]
  def paid?
    status == 'paid'
  end

  # Check if charge is pending
  # @return [Boolean]
  def pending?
    status == 'pending'
  end

  # Check if charge is overdue
  # @return [Boolean]
  def overdue?
    status == 'overdue'
  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
# File 'lib/conexa/resources/charge.rb', line 29

class Charge < Model
  primary_key_attribute :charge_id

  # Check if charge is paid
  # @return [Boolean]
  def paid?
    status == 'paid'
  end

  # Check if charge is pending
  # @return [Boolean]
  def pending?
    status == 'pending'
  end

  # Check if charge is overdue
  # @return [Boolean]
  def overdue?
    status == 'overdue'
  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:



101
102
103
# File 'lib/conexa/resources/charge.rb', line 101

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

.pix(id) ⇒ ConexaObject

Get PIX for a charge by ID

Parameters:

  • id (Integer, String)

    charge ID

Returns:



115
116
117
# File 'lib/conexa/resources/charge.rb', line 115

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:



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

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:



94
95
96
# File 'lib/conexa/resources/charge.rb', line 94

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

Instance Method Details

#cancelself

Cancel this charge

Returns:

  • (self)


77
78
79
80
# File 'lib/conexa/resources/charge.rb', line 77

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

#overdue?Boolean

Check if charge is overdue

Returns:

  • (Boolean)


46
47
48
# File 'lib/conexa/resources/charge.rb', line 46

def overdue?
  status == 'overdue'
end

#paid?Boolean

Check if charge is paid

Returns:

  • (Boolean)


34
35
36
# File 'lib/conexa/resources/charge.rb', line 34

def paid?
  status == 'paid'
end

#pending?Boolean

Check if charge is pending

Returns:

  • (Boolean)


40
41
42
# File 'lib/conexa/resources/charge.rb', line 40

def pending?
  status == 'pending'
end

#pixConexaObject

Get PIX QR Code for this charge

Returns:

  • (ConexaObject)

    PIX data including qr_code and qr_code_base64



71
72
73
# File 'lib/conexa/resources/charge.rb', line 71

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

#send_emailself

Send charge notification by email

Returns:

  • (self)


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

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)


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

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