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 collapse
- STATUSES =
The values
statuscan take on a charge, per the collection's field table forGET /charge/:id.excludedis 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)"pendingandoverdueare 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
-
#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.
- #cancelled? ⇒ Boolean
-
#overdue? ⇒ Boolean
deprecated
Deprecated.
The API has no
overduestatus. An overdue charge isunpaidwith adue_datein the past; compare the date yourself. - #paid? ⇒ Boolean
-
#pending? ⇒ Boolean
deprecated
Deprecated.
The API has no
pendingstatus; the open state isunpaid. This alias only exists so callers written against the old, never-matching predicate keep working while they migrate. -
#pix ⇒ ConexaObject
Get PIX QR Code for this charge.
-
#send_email ⇒ self
Send charge notification by email.
-
#settle(params = {}) ⇒ self
Settle (pay) this charge.
-
#unpaid? ⇒ Boolean
Is this charge still open?.
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
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 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_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 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_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 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_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 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 |
#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 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 |
#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 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
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
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
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
136 137 138 |
# File 'lib/conexa/resources/charge.rb', line 136 def settle(id, params = {}) find(id).settle(params) end |
Instance Method Details
#cancel ⇒ self
Cancel this charge
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
65 66 67 |
# File 'lib/conexa/resources/charge.rb', line 65 def cancelled? status == 'cancelled' end |
#overdue? ⇒ Boolean
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.
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
54 55 56 |
# File 'lib/conexa/resources/charge.rb', line 54 def paid? status == 'paid' end |
#pending? ⇒ Boolean
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.
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 |
#pix ⇒ ConexaObject
Get PIX QR Code for this charge
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_email ⇒ self
Send charge notification by email
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.
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?
60 61 62 |
# File 'lib/conexa/resources/charge.rb', line 60 def unpaid? status == 'unpaid' end |