Class: SuperGood::SolidusTaxjar::TransactionIdGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/super_good/solidus_taxjar/transaction_id_generator.rb

Overview

Responsible for generating ‘transaction_id` references for transactions we create on TaxJar for Solidus orders. This class handles creating associated ID’s for transactions which need to be cancelled and recreated when the order is updated in Solidus after it has been sent to the TaxJar reporting API.

Class Method Summary collapse

Class Method Details

.next_transaction_id(order:, current_transaction_id: nil) ⇒ String

Generates the next sequential ‘transaction_id` given an order and optionally the current transaction ID on TaxJar. This handles the case where a transaction already has been created on TaxJar and later needs to be cancelled and we need to create an updated transaction with an associated identifier.

Parameters:

  • order (Spree::Order)

    the order for which we want to generate a transaction ID.

  • current_transaction_id (String) (defaults to: nil)

    the current transaction ID for the order if it exists on TaxJar.

Returns:

  • (String)

    the next sequential ‘transaction_id`



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/super_good/solidus_taxjar/transaction_id_generator.rb', line 21

def next_transaction_id(order:, current_transaction_id: nil)
  if current_transaction_id.nil?
    "#{order.number}"
  elsif order.number == current_transaction_id
    "#{current_transaction_id}-1"
  else
    parts = current_transaction_id.rpartition("-")
    parts.last.next!
    parts.join
  end
end

.refund_transaction_id(transaction_id) ⇒ String

Generates a ‘transaction_id` for a refund transaction based on the ID of the transaction we’re refunding.

Parameters:

  • transaction_id (String)

    the ID of the transaction we are refunding.

Returns:

  • (String)

    the expected refund transaction ID.



39
40
41
# File 'lib/super_good/solidus_taxjar/transaction_id_generator.rb', line 39

def refund_transaction_id(transaction_id)
  "#{transaction_id}-REFUND"
end