Class: SpreeAvataxOfficial::GetTaxService

Inherits:
Base
  • Object
show all
Defined in:
app/services/spree_avatax_official/get_tax_service.rb

Constant Summary

Constants inherited from Base

Base::APP_NAME, Base::APP_VERSION, Base::CONNECTION_OPTIONS, Base::SUCCESS_STATUSES

Instance Method Summary collapse

Instance Method Details

#call(order:, options: {}) ⇒ Object



3
4
5
6
7
8
9
# File 'app/services/spree_avatax_official/get_tax_service.rb', line 3

def call(order:, options: {})
  response = send_request(order, options)

  return failure(response) if response.body['error'].present?

  success(taxCalculated: response.body['totalTaxCalculated'])
end

#send_request(order, options) ⇒ Object



11
12
13
14
15
16
17
18
# File 'app/services/spree_avatax_official/get_tax_service.rb', line 11

def send_request(order, options)
  create_transaction_model = SpreeAvataxOfficial::Transactions::CreatePresenter.new(
    order:            order,
    transaction_type: SpreeAvataxOfficial::Transaction::SALES_ORDER
  ).to_json

  client(order: order).create_transaction(create_transaction_model, options)
end