stripe_invoice 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da990157c574276a7b2227200aa58429d99612b4
4
- data.tar.gz: 337dc79ce73255c73ebdcb6bf09616bf5843be70
3
+ metadata.gz: eaffd686fa6c9c5dd2cb4e11cde6b468a55b4e88
4
+ data.tar.gz: ecc0615876caf9309adcf1f886313201795c3f0a
5
5
  SHA512:
6
- metadata.gz: 86cffdeb3f473395a9c0a36c338a62d672970304dfcc8b948f81704976252d770e89405f75df308ddaffe11929872d85ef72f23d6f38b335423eb099c88aa5d4
7
- data.tar.gz: 27bca204901a23d12251aa5337da4496618ff118d7ebf7ea642c214ca86599e1c1160fa9446f336bc8baae64acc0ad14b061c9033bf640bdf81dcab5f54941b6
6
+ metadata.gz: 8d5495ebba9a0baba0193803890623ff0889bfabfb6bc88255df318d62e1975eef20acff5eb2352b46739096e2c0758e39f812e6c4a3fe629f880b125434d4e3
7
+ data.tar.gz: f06c4a011698ca01c8d3aba3cebe0032359399e6d61966089ca5681612613ee8d3ee18d469bc547b7e33eea64ee753881c1558b16d049dc775675d46b5ef302a
@@ -16,14 +16,17 @@ module StripeInvoice
16
16
  puts "[DJTaxReport] number of charges in year: #{sicharges.size}"
17
17
  arr_data = []
18
18
  sicharges.each do |charge|
19
- owner = Koudoku.owner_class.find(charge.owner_id)
19
+ owner = charge.owner
20
20
 
21
21
  next unless owner # skip if we don't have an owner
22
22
 
23
23
  data = {
24
24
  charge: charge,
25
+ country: charge.country,
26
+ tax_number: charge.tax_number,
27
+ billing_address: charge.billing_address,
25
28
  bt: Stripe::BalanceTransaction.retrieve(charge.indifferent_json[:balance_transaction]),
26
- owner: owner
29
+ owner: owner,
27
30
  }
28
31
  puts "[DJTaxReport] aggregating data #{charge.stripe_id}"
29
32
  if charge.indifferent_json[:refunds].count > 0
@@ -76,14 +79,14 @@ module StripeInvoice
76
79
 
77
80
  sicharges.each do |hash_ch|
78
81
  # get value or 0 if not present
79
- value = result.fetch(hash_ch[:owner].country) { 0 }
82
+ value = result.fetch(hash_ch[:country]) { 0 }
80
83
 
81
84
  if hash_ch[:refunds]
82
85
  hash_ch[:refunds].each do |refund|
83
86
  value -= refund[:bt][:amount]
84
87
  end
85
88
  end # deduct refunds
86
- result[hash_ch[:owner].country] = value + hash_ch[:bt][:amount]
89
+ result[hash_ch[:country]] = value + hash_ch[:bt][:amount]
87
90
  end
88
91
 
89
92
  result.each do |key, value|
@@ -7,10 +7,5 @@ module StripeInvoice
7
7
  number_to_currency(obj[attr_sym].to_f / 100, unit: "#{obj[:currency].upcase} ")
8
8
  end
9
9
 
10
-
11
- def format_billing_address(owner)
12
- raise "You need to implement #billing_address on your subscription owner class" unless owner.respond_to? :billing_address
13
- owner.billing_address
14
- end
15
10
  end
16
11
  end
@@ -20,6 +20,19 @@ module StripeInvoice
20
20
  @owner ||= Koudoku.owner_class.find(owner_id)
21
21
  end
22
22
 
23
+ def billing_address
24
+ indifferent_json[:metadata][:billing_address] || owner.try(:billing_address)
25
+ end
26
+
27
+ def tax_number
28
+ indifferent_json[:metadata][:tax_number] || owner.try(:tax_number)
29
+ end
30
+
31
+
32
+ def country
33
+ indifferent_json[:metadata][:country] || owner.try(:country)
34
+ end
35
+
23
36
  def refunds
24
37
  indifferent_json[:refunds]
25
38
  end
@@ -31,12 +44,14 @@ module StripeInvoice
31
44
  # builds the invoice from the stripe CHARGE object
32
45
  # OR updates the existing invoice if an invoice for that id exists
33
46
  def self.create_from_stripe(stripe_charge)
34
- charge = Charge.find_by_stripe_id(stripe_charge[:id])
35
47
 
36
48
  unless stripe_charge.paid
37
49
  puts "ignoring unpaid charges"
38
50
  return
39
- end
51
+ end
52
+
53
+ charge = Charge.find_by_stripe_id(stripe_charge[:id])
54
+
40
55
  # for existing invoices just update and be done
41
56
  if charge.present?
42
57
  charge.update_attribute(:json, stripe_charge)
@@ -75,8 +90,21 @@ module StripeInvoice
75
90
  def self.get_subscription_owner(stripe_charge)
76
91
  # ::Subscription is generated by Koudoku, but lives in main_app
77
92
  subscription = ::Subscription.find_by_stripe_id(stripe_charge.customer)
78
- return nil if subscription.nil?
79
- owner = subscription.subscription_owner
93
+
94
+ # we found them directly, go for it.
95
+ unless subscription.nil?
96
+ return subscription.subscription_owner
97
+ end
98
+
99
+ # koudoku does have a nasty feature/bug in that it deletes the subscription
100
+ # from the database when it is cancelled. This makes it impossible to
101
+ # match past charges to customers based solely on the subscription's stripe_id
102
+ # instead we also try to match the email address/owner_id that was send to stripe
103
+ # when the account was created
104
+ stripe_customer = Stripe::Customer.retrieve stripe_charge.customer
105
+ owner_id = stripe_customer.description.to_i
106
+ Koudoku.owner_class.find(owner_id)
107
+
80
108
  end
81
109
  end
82
110
  end
@@ -33,8 +33,8 @@ prawn_document(:page_layout => :portrait) do |pdf|
33
33
 
34
34
  pdf.text "Charged: #{format_stripe_currency(hash_ch[:charge], :total)}"
35
35
  pdf.text "Transaction: #{format_stripe_currency(hash_ch[:bt])} (Fee: #{format_stripe_currency(hash_ch[:bt],:fee)})"
36
- pdf.text "Billed to: #{format_billing_address hash_ch[:owner]}"
37
- pdf.text "Customer tax number: #{hash_ch[:owner].tax_number}" unless hash_ch[:owner].tax_number.blank?
36
+ pdf.text "Billed to: #{hash_ch[:billing_address]}"
37
+ pdf.text "Customer tax number: #{hash_ch[:tax_number]}" unless hash_ch[:tax_number].blank?
38
38
  if hash_ch[:refunds]
39
39
  ref_text = "<b>Refunds:</b>\n"
40
40
  hash_ch[:refunds].each do |hash_refund|
@@ -1,3 +1,3 @@
1
1
  module StripeInvoice
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe_invoice
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Engelhardt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-09 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails