stripe_invoice 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df644f3ed96fa4252f80eed1698a5d5281cc484a
4
- data.tar.gz: 90a0dd31292726cd2c018fcd893f8a418fd0af17
3
+ metadata.gz: d6c62d186f30b26ee3f6f9c5e0741a8f5e855924
4
+ data.tar.gz: cc3d701733f07968d2fdf9ba1d9af4eb7c5f953a
5
5
  SHA512:
6
- metadata.gz: 75e3bc64405cf840b164b385a4cad26ebd2164c7120d42e65862960a4af6d00d302b97103c64e846802d24db17437f80e12013c0453f857ba939b995d69d04cf
7
- data.tar.gz: cde4bd6bf66f8490b7f9048e1e124524de4f2f729a4191548c0f3e0eaf059902ac54c56c6f169a293cc9d766c7ebd5c34ea03f031330dd19ffe01e966036c9d7
6
+ metadata.gz: 2f43f460652eef6aa0204be986a70a2239384f3557c6d7c3ede0a05ae38ca5b65dcb04d3787366dfca6adb50bca27681b28ef2553ac328d22df8e6f13f763a77
7
+ data.tar.gz: 0914d73f343604a061f854d02d394f1fcb4bd40ec8a42abb77143d1c5abb27d55b53ecd56b1ef7414182ae167c8dabbf84496434bf1b9b31315f9d77e7e8d45e
@@ -28,7 +28,7 @@ module StripeInvoice
28
28
  country: country,
29
29
  tax_number: charge.tax_number,
30
30
  billing_address: charge.billing_address,
31
- bt: Stripe::BalanceTransaction.retrieve(charge.indifferent_json[:balance_transaction]),
31
+ bt: charge.balance_transaction_object,
32
32
  owner: owner,
33
33
  }
34
34
  puts "[#{self.class.name}##{__method__.to_s}] aggregating data #{charge.stripe_id}"
@@ -82,11 +82,13 @@ module StripeInvoice
82
82
  result = []
83
83
  charges.each_key do |key|
84
84
  next if key.blank?
85
-
85
+
86
86
  result << {
87
- amount: charges[key].sum{|char| char[:charge].total_less_refunds},
88
- currency: charges[key].first[:charge].currency,
89
- tax_number: key
87
+ amount: (charges[key].sum {|charge| charge[:charge].balance_transaction_total_less_refunds}),
88
+ currency: charges[key].first[:bt][:currency],
89
+ tax_number: key,
90
+ country: (charges[key].first[:charge].owner.country ? charges[key].first[:charge].owner.country :
91
+ "CC: #{charges[key].first[:charge].source_country}")
90
92
  }
91
93
  end
92
94
 
@@ -41,10 +41,46 @@ module StripeInvoice
41
41
  refunds.inject(0){ |total,refund| total + refund[:amount]}
42
42
  end
43
43
 
44
+ def total_refund_transaction
45
+ refunds.inject(0) do |total, refund|
46
+ bt = Stripe::BalanceTransaction.retrieve(refund[:balance_transaction])
47
+ total + bt[:amount]
48
+ end
49
+ end
50
+
44
51
  def total_less_refunds
45
52
  total - total_refund
46
53
  end
47
54
 
55
+ def balance_transaction_object
56
+ @btobj ||= Stripe::BalanceTransaction.retrieve balance_transaction_sid
57
+ end
58
+
59
+ def balance_transaction_sid
60
+ self.indifferent_json[:balance_transaction]
61
+ end
62
+
63
+ def balance_transaction_currency
64
+ self.balance_transaction_object[:currency]
65
+ end
66
+
67
+ def balance_transaction_total_less_refunds
68
+ result = (balance_transaction_object[:amount] - self.total_refund_transaction)
69
+ puts "[#{self.class.name}##{__method__.to_s}] result for #{id}-#{tax_number}: #{result}"
70
+
71
+ result
72
+ end
73
+
74
+ # the country the source is registered in
75
+ def source_country
76
+ # source can only be accessed via Customer
77
+ cus = Stripe::Customer.retrieve self.indifferent_json[:customer]
78
+ # TODO this is wrong, because there might be multiple sources and I
79
+ # just randomly select the first one - also some source types might NOT even
80
+ # have a country information
81
+ cus.sources.data[0].country
82
+ end
83
+
48
84
  # builds the invoice from the stripe CHARGE object
49
85
  # OR updates the existing invoice if an invoice for that id exists
50
86
  def self.create_from_stripe(stripe_charge)
@@ -29,7 +29,7 @@ prawn_document(:page_layout => :portrait) do |pdf|
29
29
  pdf.start_new_page
30
30
  pdf.font_size(17.5) { pdf.text "Volume per tax ID", :style => :bold }
31
31
  volume_per_tax_number.each do |vptn_hash|
32
- pdf.text "#{vptn_hash[:tax_number]}: #{format_stripe_currency(vptn_hash,:amount)}"
32
+ pdf.text "#{vptn_hash[:tax_number]}(#{vptn_hash[:country]}): #{format_stripe_currency(vptn_hash,:amount)}"
33
33
  end
34
34
 
35
35
  pdf.start_new_page
@@ -1,3 +1,3 @@
1
1
  module StripeInvoice
2
- VERSION = "1.3.2"
2
+ VERSION = "1.3.3"
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.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Engelhardt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-08 00:00:00.000000000 Z
11
+ date: 2016-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails