Class: AvataxClient::Request::Transaction
- Defined in:
- lib/avatax_client/request/transaction.rb
Overview
Handles requests to Avatax api dealing with Transactions.
Class Method Summary collapse
- .adjust!(adjustment_reason:, adjustment_description: "", transaction:) ⇒ AvataxClient::Response, AvataxClient::Errors
-
.adjustment_reasons ⇒ OpenStruct
Reasons to make an adjustment to a Avatax Transaction.
-
.commit!(company_code:, transaction_code:) ⇒ AvataxClient::Response, AvataxClient::Errors
Changes an uncommitted transaction into a committed transaction.
- .create!(transaction:) ⇒ AvataxClient::Response, AvataxClient::Errors
Instance Method Summary collapse
- #adjust!(adjustment_description: "", adjustment_reason:) ⇒ Object
- #commit! ⇒ Object
- #create! ⇒ Object
Methods included from AvataxClient::ReverseCoercion
Class Method Details
.adjust!(adjustment_reason:, adjustment_description: "", transaction:) ⇒ AvataxClient::Response, AvataxClient::Errors
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/avatax_client/request/transaction.rb', line 41 def adjust!(adjustment_reason:, adjustment_description: "", transaction:) body_params = { adjustmentReason: adjustment_reason, adjustmentDescription: adjustment_description, newTransaction: transaction.to_body } body = JSON.generate(body_params.delete_if { |_key, value| value.blank? }) path = "companies/#{transaction.company_code}/transactions/#{transaction.code}/adjust" res = Typhoeus.post(url(path), body: body, headers: headers, userpwd: credentials) handle_response(response: res) end |
.adjustment_reasons ⇒ OpenStruct
Reasons to make an adjustment to a Avatax Transaction. rubocop:disable Metrics/MethodLength
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/avatax_client/request/transaction.rb', line 21 def adjustment_reasons OpenStruct.new( bad_debt: "BadDebt", exempt_cert: "ExemptCertApplied", not_adjusted: "NotAdjusted", offline: "Offline", other: "Other", price_adjusted: "PriceAdjusted", product_exchanged: "ProductExchanged", product_returned: "ProductReturned", reconciled: "ReconciledWithGeneralLedger", sourcing_issue: "SourcingIssue" ) end |
.commit!(company_code:, transaction_code:) ⇒ AvataxClient::Response, AvataxClient::Errors
Changes an uncommitted transaction into a committed transaction.
68 69 70 71 72 73 |
# File 'lib/avatax_client/request/transaction.rb', line 68 def commit!(company_code:, transaction_code:) path = "companies/#{company_code}/transactions/#{transaction_code}/commit" body = JSON.generate(commit: true) res = Typhoeus.post(url(path), body: body, headers: headers, userpwd: credentials) handle_response(response: res) end |
.create!(transaction:) ⇒ AvataxClient::Response, AvataxClient::Errors
56 57 58 59 60 61 62 |
# File 'lib/avatax_client/request/transaction.rb', line 56 def create!(transaction:) path = "transactions/create" hash = transaction.to_body body = JSON.generate(hash) res = Typhoeus.post(url(path), body: body, headers: headers, userpwd: credentials) handle_response(response: res) end |
Instance Method Details
#adjust!(adjustment_description: "", adjustment_reason:) ⇒ Object
125 126 127 128 |
# File 'lib/avatax_client/request/transaction.rb', line 125 def adjust!(adjustment_description: "", adjustment_reason:) self.class.adjust!(adjustment_description: adjustment_description, adjustment_reason: adjustment_reason, transaction: self) end |
#commit! ⇒ Object
136 137 138 |
# File 'lib/avatax_client/request/transaction.rb', line 136 def commit! self.class.commit!(company_code: company_code, transaction_code: code) end |
#create! ⇒ Object
131 132 133 |
# File 'lib/avatax_client/request/transaction.rb', line 131 def create! self.class.create!(transaction: self) end |