class Stripe2QB::Converters::TransferToDeposit
Attributes
charge_to_sales_receipts[R]
deposit[R]
refund_to_refund_receipts[R]
transfer[R]
Public Class Methods
new(transfer, configuration)
click to toggle source
Calls superclass method
Stripe2QB::Converters::Base::new
# File lib/stripe2qb/converters/transfer_to_deposit.rb, line 9 def initialize(transfer, configuration) super(configuration) @transfer = transfer charges = stripe_api.get_transfer_charges(transfer.id) @charge_to_sales_receipts = charges.map {|charge| ChargeToSalesReceipt.new(charge, configuration) } refunds = stripe_api.get_transfer_refunds(transfer.id) @refund_to_refund_receipts = refunds.map {|refund| RefundToRefundReceipt.new(refund, configuration) } @deposit = build_empty_deposit end
Public Instance Methods
create!()
click to toggle source
# File lib/stripe2qb/converters/transfer_to_deposit.rb, line 37 def create! raise "Deposit for #{transfer.id} already exists: #{find.id}" if exists? create_dependencies! build_deposit_line_items quickbooks_api.deposit_service.create(deposit) end
create_dependencies!()
click to toggle source
# File lib/stripe2qb/converters/transfer_to_deposit.rb, line 45 def create_dependencies! charge_to_sales_receipts.each do |charge_to_sales_receipt| charge_to_sales_receipt.find_or_create end refund_to_refund_receipts.each do |refund_to_refund_receipt| refund_to_refund_receipt.find_or_create end end
delete!()
click to toggle source
# File lib/stripe2qb/converters/transfer_to_deposit.rb, line 55 def delete! return false unless exists? result = quickbooks_api.deposit_service.delete(find) @found = nil delete_dependencies! result end
delete_dependencies!()
click to toggle source
# File lib/stripe2qb/converters/transfer_to_deposit.rb, line 66 def delete_dependencies! charge_to_sales_receipts.each do |charge_to_sales_receipt| charge_to_sales_receipt.delete! if charge_to_sales_receipt.exists? end refund_to_refund_receipts.each do |refund_to_refund_receipt| refund_to_refund_receipt.delete! if refund_to_refund_receipt.exists? end end
find()
click to toggle source
# File lib/stripe2qb/converters/transfer_to_deposit.rb, line 23 def find return @found if @found # Quickbooks doesn't have an external ID on Deposits, so we have to # search for a match on private_note... # first narrow down results by txn_date deposits = quickbooks_api.deposit_service.find_by(:txn_date, format_date(transfer.created)) deposits.each do |deposit| return @found = deposit if deposit.private_note =~ /#{transfer.id}/ end nil end
Private Instance Methods
build_deposit_line_item_for_fee_refunds()
click to toggle source
# File lib/stripe2qb/converters/transfer_to_deposit.rb, line 139 def build_deposit_line_item_for_fee_refunds line_item = Quickbooks::Model::DepositLineItem.new fee_refunds = refund_to_refund_receipts.inject(0) {|sum, refund_to_refund_receipt| sum += refund_to_refund_receipt.refund.fee } line_item.amount = format_amount(-1 * fee_refunds) # convert to positive number for Deposit line_item.description = "Stripe Fee Refunds for #{transfer.id}" set_deposit_line_detail_for_fees(line_item) line_item end
build_deposit_line_item_for_fees()
click to toggle source
# File lib/stripe2qb/converters/transfer_to_deposit.rb, line 129 def build_deposit_line_item_for_fees line_item = Quickbooks::Model::DepositLineItem.new fees = charge_to_sales_receipts.inject(0) {|sum, charge_to_sales_receipts| sum += charge_to_sales_receipts.charge.fee } line_item.amount = format_amount(-1 * fees) # convert to negative number for Deposit line_item.description = "Stripe Fees for #{transfer.id}" set_deposit_line_detail_for_fees(line_item) line_item end
build_deposit_line_item_for_refund_receipt(refund_receipt)
click to toggle source
# File lib/stripe2qb/converters/transfer_to_deposit.rb, line 115 def build_deposit_line_item_for_refund_receipt(refund_receipt) line_item = Quickbooks::Model::DepositLineItem.new line_item.amount = -1 * refund_receipt.total # convert to negative number for Deposit line_item.description = "Deposit for RefundReceipt #{refund_receipt.id}" linked_txn = Quickbooks::Model::LinkedTransaction.new linked_txn.txn_id = refund_receipt.id linked_txn.txn_type = 'RefundReceipt' linked_txn.txn_line_id = 0 line_item.linked_transactions = [ linked_txn ] line_item end
build_deposit_line_item_for_sales_receipt(sales_receipt)
click to toggle source
# File lib/stripe2qb/converters/transfer_to_deposit.rb, line 101 def build_deposit_line_item_for_sales_receipt(sales_receipt) line_item = Quickbooks::Model::DepositLineItem.new line_item.amount = sales_receipt.total line_item.description = "Deposit for SalesReceipt #{sales_receipt.id}" linked_txn = Quickbooks::Model::LinkedTransaction.new linked_txn.txn_id = sales_receipt.id linked_txn.txn_type = 'SalesReceipt' linked_txn.txn_line_id = 0 line_item.linked_transactions = [ linked_txn ] line_item end
build_deposit_line_items()
click to toggle source
# File lib/stripe2qb/converters/transfer_to_deposit.rb, line 88 def build_deposit_line_items charge_to_sales_receipts.each do |charge_to_sales_receipt| deposit.line_items << build_deposit_line_item_for_sales_receipt(charge_to_sales_receipt.find) end refund_to_refund_receipts.each do |refund_to_refund_receipt| deposit.line_items << build_deposit_line_item_for_refund_receipt(refund_to_refund_receipt.find) end deposit.line_items << build_deposit_line_item_for_fees deposit.line_items << build_deposit_line_item_for_fee_refunds end
build_empty_deposit()
click to toggle source
# File lib/stripe2qb/converters/transfer_to_deposit.rb, line 78 def build_empty_deposit deposit = Quickbooks::Model::Deposit.new deposit.deposit_to_account_id = quickbooks_api.deposit_account.id deposit.txn_date = format_date(transfer.created) deposit.private_note = "Imported by Stripe2QB: #{transfer.id}" deposit.auto_doc_number! deposit end
set_deposit_line_detail_for_fees(line_item)
click to toggle source
# File lib/stripe2qb/converters/transfer_to_deposit.rb, line 149 def set_deposit_line_detail_for_fees(line_item) line_item.deposit_line_detail! do |detail| detail.entity = Quickbooks::Model::BaseReference.new(quickbooks_api.deposit_fees_vendor.id, type: 'Vendor') detail.account_id = quickbooks_api.deposit_fees_account.id end end