Class: Stripe2QB::Converters::RefundToRefundReceipt

Inherits:
Base
  • Object
show all
Defined in:
lib/stripe2qb/converters/refund_to_refund_receipt.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#quickbooks_api, #stripe_api

Instance Method Summary collapse

Methods inherited from Base

#exists?, #find_or_create

Constructor Details

#initialize(refund, configuration) ⇒ RefundToRefundReceipt

Returns a new instance of RefundToRefundReceipt.



7
8
9
10
11
12
# File 'lib/stripe2qb/converters/refund_to_refund_receipt.rb', line 7

def initialize(refund, configuration)
  super(configuration)

  @refund = refund
  @refund_receipt = build_refund_receipt
end

Instance Attribute Details

#refundObject (readonly)

Returns the value of attribute refund.



4
5
6
# File 'lib/stripe2qb/converters/refund_to_refund_receipt.rb', line 4

def refund
  @refund
end

#refund_receiptObject (readonly)

Returns the value of attribute refund_receipt.



5
6
7
# File 'lib/stripe2qb/converters/refund_to_refund_receipt.rb', line 5

def refund_receipt
  @refund_receipt
end

Instance Method Details

#create!Object



28
29
30
31
32
# File 'lib/stripe2qb/converters/refund_to_refund_receipt.rb', line 28

def create!
  raise "RefundReceipt for #{refund.id} already exists: #{find.id}" if exists?

  quickbooks_api.refund_receipt_service.create(refund_receipt)
end

#delete!Object



34
35
36
37
38
39
40
41
# File 'lib/stripe2qb/converters/refund_to_refund_receipt.rb', line 34

def delete!
  return false unless exists?

  result = quickbooks_api.refund_receipt_service.delete(find)
  @found = nil

  result
end

#findObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/stripe2qb/converters/refund_to_refund_receipt.rb', line 14

def find
  return @found if @found

  # Quickbooks doesn't have payment_ref_number on RefundReceipts, so we
  # have to search for a match on private_note...
  # first narrow down results by txn_date
  refund_receipts = quickbooks_api.refund_receipt_service.find_by(:txn_date, format_date(refund.created))
  refund_receipts.each do |refund_receipt|
    return @found = refund_receipt if refund_receipt.private_note =~ /#{refund.id}/
  end

  nil
end