Class: Conexa::Charge
- Inherits:
-
Model
- Object
- ConexaObject
- Model
- Conexa::Charge
- Defined in:
- lib/conexa/resources/charge.rb
Overview
Charge resource for billing/invoices
Constant Summary
Constants inherited from ConexaObject
Conexa::ConexaObject::RESOURCES
Instance Attribute Summary collapse
-
#amount ⇒ Float
readonly
Charge amount.
-
#charge_id ⇒ Integer
readonly
Charge ID (also accessible as #id).
-
#customer_id ⇒ Integer
readonly
Customer ID.
-
#due_date ⇒ String
readonly
Due date.
-
#paid_at ⇒ String?
readonly
Payment date.
-
#status ⇒ String
readonly
Status: pending, paid, overdue, cancelled.
Attributes inherited from ConexaObject
Class Method Summary collapse
-
.cancel(id) ⇒ Charge
Cancel a charge by ID.
-
.pix(id) ⇒ ConexaObject
Get PIX for a charge by ID.
-
.send_email(id) ⇒ Charge
Send email for a charge by ID.
-
.settle(id, params = {}) ⇒ Charge
Settle a charge by ID.
Instance Method Summary collapse
-
#cancel ⇒ self
Cancel this charge.
-
#overdue? ⇒ Boolean
Check if charge is overdue.
-
#paid? ⇒ Boolean
Check if charge is paid.
-
#pending? ⇒ Boolean
Check if charge is pending.
-
#pix ⇒ ConexaObject
Get PIX QR Code for this charge.
-
#send_email ⇒ self
Send charge notification by email.
-
#settle(params = {}) ⇒ self
Settle (pay) this charge.
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
#amount ⇒ Float (readonly)
Returns 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_id ⇒ Integer (readonly)
Returns 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_id ⇒ Integer (readonly)
Returns 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_date ⇒ String (readonly)
Returns 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 |
#paid_at ⇒ String? (readonly)
Returns 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 |
#status ⇒ String (readonly)
Returns 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
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
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
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
94 95 96 |
# File 'lib/conexa/resources/charge.rb', line 94 def settle(id, params = {}) find(id).settle(params) end |
Instance Method Details
#cancel ⇒ self
Cancel this charge
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
46 47 48 |
# File 'lib/conexa/resources/charge.rb', line 46 def overdue? status == 'overdue' end |
#paid? ⇒ Boolean
Check if charge is paid
34 35 36 |
# File 'lib/conexa/resources/charge.rb', line 34 def paid? status == 'paid' end |
#pending? ⇒ Boolean
Check if charge is pending
40 41 42 |
# File 'lib/conexa/resources/charge.rb', line 40 def pending? status == 'pending' end |
#pix ⇒ ConexaObject
Get PIX QR Code for this charge
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_email ⇒ self
Send charge notification by email
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.
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 |