class TaxCloud::Transaction

Lookup tax rate, authorize, and capture the information to be logged into TaxCloud.

Note: The Transaction must not change between the lookup and authorization method calls.

Attributes

cart_id[RW]

User-defined cart ID for the order.

cart_items[RW]

Array of CartItems.

customer_id[RW]

User-defined customer ID for the Transaction.

destination[RW]

The Address of which the shipment arrives.

order_id[RW]

The order ID for authorized, captured, and authorized_with_captured methods.

origin[RW]

The Address of which the shipment originates.

Public Class Methods

new(params = {}) click to toggle source

Create a new transaction.

Parameters

params

Transaction params.

Calls superclass method TaxCloud::Record::new
# File lib/tax_cloud/transaction.rb, line 22
def initialize(params = {})
  params = { cart_items: [] }.merge(params)
  super params
end

Public Instance Methods

authorized(options = {}) click to toggle source

Once a purchase has been made and payment has been authorized, this method must be called. A matching Lookup call must have been made before this is called.

Options

date_authorized
  • The date the transaction was authorized. Default is today respecting timezone.

# File lib/tax_cloud/transaction.rb, line 46
def authorized(options = {})
  options = { date_authorized: Date.current }.merge(options)

  request_params = {
    'customerID' => customer_id,
    'cartID' => cart_id,
    'orderID' => order_id,
    'dateAuthorized' => xml_date(options[:date_authorized])
  }

  response = TaxCloud.client.request :authorized, request_params
  TaxCloud::Responses::Authorized.parse response
end
authorized_with_capture(options = {}) click to toggle source

Combines the authorized and captured methods into a single call

Options

date_authorized

The date the transaction was authorized. Default is today respecting timezone.

date_captured
  • The date the transaction was captured. Default is today respecting timezone.

# File lib/tax_cloud/transaction.rb, line 82
def authorized_with_capture(options = {})
  options = { date_authorized: Date.current, date_captured: Date.current }.merge(options)
  request_params = {
    'customerID' => customer_id,
    'cartID' => cart_id,
    'orderID' => order_id,
    'dateAuthorized' => xml_date(options[:date_authorized]),
    'dateCaptured' => xml_date(options[:date_captured])
  }

  response = TaxCloud.client.request :authorized_with_capture, request_params
  TaxCloud::Responses::AuthorizedWithCapture.parse response
end
captured(options = {}) click to toggle source

Complete the transaction. The order_id passed into captured must match the order_id that was passed into authorized.

Options

date_captured

The time the transaction was captured. Default is today respecting timezone.

# File lib/tax_cloud/transaction.rb, line 64
def captured(options = {})
  options = { date_captured: Date.current }.merge(options)
  request_params = {
    'customerID' => customer_id,
    'cartID' => cart_id,
    'orderID' => order_id,
    'dateCaptured' => xml_date(options[:date_captured])
  }

  response = TaxCloud.client.request :captured, request_params
  TaxCloud::Responses::Captured.parse response
end
lookup() click to toggle source

Lookup the tax rate for the transaction. The returned information is based on the originating address, destination address, and cart items.

# File lib/tax_cloud/transaction.rb, line 29
def lookup
  request_params = {
    'customerID' => customer_id,
    'cartID' => cart_id,
    'cartItems' => { 'CartItem' => cart_items.map(&:to_hash) },
    'origin' => origin.to_hash,
    'destination' => destination.to_hash
  }

  response = TaxCloud.client.request :lookup, request_params
  TaxCloud::Responses::Lookup.parse response
end
returned(options = {}) click to toggle source

Marks any included cart items as returned.

Options

returned_date

The date the return occured. Default is today respecting timezone.

# File lib/tax_cloud/transaction.rb, line 100
def returned(options = {})
  options = { returned_date: Date.current }.merge(options)
  request_params = {
    'orderID' => order_id,
    'cartItems' => { 'CartItem' => cart_items.map(&:to_hash) },
    'returnedDate' => xml_date(options[:returned_date])
  }

  response = TaxCloud.client.request :returned, request_params
  TaxCloud::Responses::Returned.parse response
end

Private Instance Methods

xml_date(val) click to toggle source
# File lib/tax_cloud/transaction.rb, line 114
def xml_date(val)
  val.respond_to?(:strftime) ? val.strftime('%Y-%m-%d') : val
end