Class: SuperGood::SolidusTaxjar::TransactionIdGenerator
- Inherits:
-
Object
- Object
- SuperGood::SolidusTaxjar::TransactionIdGenerator
- 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
-
.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.
-
.refund_transaction_id(transaction_id) ⇒ String
Generates a ‘transaction_id` for a refund transaction based on the ID of the transaction we’re refunding.
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.
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.
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 |