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
User-defined cart ID for the order.
Array of CartItem
s.
User-defined customer ID for the Transaction
.
The Address
of which the shipment arrives.
The order ID for authorized
, captured
, and authorized_with_captured
methods.
The Address
of which the shipment originates.
Public Class Methods
Create a new transaction.
Parameters¶ ↑
- params
-
Transaction
params.
TaxCloud::Record::new
# File lib/tax_cloud/transaction.rb, line 24 def initialize(params = {}) params = { cart_items: [] }.merge(params) super params end
Public Instance Methods
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.
# File lib/tax_cloud/transaction.rb, line 66 def captured(options = {}) options = { date_captured: Date.today }.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 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 31 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
Marks any included cart items as returned.
Options¶ ↑
- returned_date
-
The date the return occured. Default is today.
# File lib/tax_cloud/transaction.rb, line 102 def returned(options = {}) options = { returned_date: Date.today }.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
# File lib/tax_cloud/transaction.rb, line 116 def xml_date(val) val.respond_to?(:strftime) ? val.strftime('%Y-%m-%d') : val end