Class: AvataxClient::Request::Transaction

Inherits:
Base
  • Object
show all
Defined in:
lib/avatax_client/request/transaction.rb

Overview

Handles requests to Avatax api dealing with Transactions.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AvataxClient::ReverseCoercion

included, #to_body

Class Method Details

.adjust!(adjustment_reason:, adjustment_description: "", transaction:) ⇒ AvataxClient::Response, AvataxClient::Errors

Parameters:

Returns:



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_reasonsOpenStruct

Reasons to make an adjustment to a Avatax Transaction. rubocop:disable Metrics/MethodLength

Returns:

  • (OpenStruct)


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.

Parameters:

  • company_code (String)

    unique code identifying the company

  • transaction_code (String)

    unique code identifying the transaction

Returns:



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

See Also:

  • AvataxClient::Request::Transaction.{{.adjust!}


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

See Also:

  • AvataxClient::Request::Transaction.{{.commit!}


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

See Also:

  • AvataxClient::Request::Transaction.{{.create!}


131
132
133
# File 'lib/avatax_client/request/transaction.rb', line 131

def create!
  self.class.create!(transaction: self)
end