compensated 0.1.0.pre11 → 0.1.0.pre12

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
  SHA256:
3
- metadata.gz: 1454c1dc1fb00eb18f19f349434b8a66ac06d785f48addf22d3e2e301c0902b4
4
- data.tar.gz: dea5812f96e6dfcba08ae5bf50eb38e85e8cce9c6e858133294c2ac6b9280a11
3
+ metadata.gz: bd372eb0e25b2a4556c00570678711625b4bc2c0fbc03a39895eecf41773dded
4
+ data.tar.gz: c284ee4d7dabd693c24f4249dfa8c377541e8f96eee6d4177bd12e7f8da776af
5
5
  SHA512:
6
- metadata.gz: b364b04efd1219362586d73b30f86dbd067e9ec323ddc027d55248c8781a452e4edadd5279f9f1e1e6dbc018481927521ab9ebc0c7d44229896530829aeb6929
7
- data.tar.gz: 26d5b42bdd9aa6aee198e4b38300604e261a7c7ec519154025e626ca5a6dacdd356f7e771b42a9ac93c0d3103fb6eac5d90a96d4f386310f89afa9c77c786b6e
6
+ metadata.gz: 932ec9c9431d968d7c27ec007abad733e6993d5028f08740cb4d785d5811d8ee0db2a831f79a89b10bce8b3708cefb10f73cf86c8b22fdabe2b270f648da7531
7
+ data.tar.gz: bbb5ac4795f1fdfee765a9d1417e3af6c5236b15bc51a5cc9b9fb24dd9a87be85c1085ffa55413bf396f9d639d516a74663a3b570e3c21ed54dda7bd45e1f9c5
@@ -17,10 +17,19 @@ module Compensated
17
17
  payment_processor: :stripe,
18
18
  amount: amount(data),
19
19
  customer: customer(data),
20
+ invoice: invoice(data),
21
+ products: products(data),
20
22
  timestamp: Time.at(data[:created]),
21
23
  }
22
24
  end
23
25
 
26
+ private def invoice(data)
27
+ return nil unless invoice?(data)
28
+ {
29
+ id: data[:data][:object][:id],
30
+ created: Time.at(data[:data][:object][:created])
31
+ }
32
+ end
24
33
  private def customer(data)
25
34
  if invoice?(data)
26
35
  {
@@ -35,6 +44,57 @@ module Compensated
35
44
  end
36
45
  end
37
46
 
47
+ private def products(data)
48
+ if invoice?(data)
49
+ data[:data][:object][:lines][:data].map do |line|
50
+ value = product(line, data)
51
+ next if value.nil? || value.empty?
52
+ value
53
+ end
54
+ end
55
+ end
56
+
57
+ private def product(line, data)
58
+ return nil if line.nil? || line.empty?
59
+ {
60
+ sku: sku(line),
61
+ purchased: purchased(data),
62
+ description: line[:description],
63
+ quantity: line[:quantity],
64
+ expiration: Time.at(line[:period][:end]),
65
+ subscription: subscription(line),
66
+ plan: plan(line)
67
+ }.compact
68
+ end
69
+
70
+ private def subscription(line)
71
+ { id: line[:subscription] }.compact
72
+ end
73
+
74
+ private def plan(line)
75
+ return nil unless line[:plan] && line[:plan].respond_to?(:[])
76
+ {
77
+ sku: line[:plan][:id],
78
+ name: line[:plan][:nickname],
79
+ interval: {
80
+ period: line[:plan][:interval],
81
+ count: line[:plan][:interval_count]
82
+ }.compact
83
+ }.compact
84
+ end
85
+
86
+ private def sku(line)
87
+ plan = line.fetch(:plan, {})
88
+ return nil if plan.nil?
89
+ plan.fetch(:product, nil)
90
+ end
91
+
92
+ private def purchased(data)
93
+ string = data[:data][:object][:status_transitions][:paid_at]
94
+ return nil if string.nil?
95
+ Time.at(string)
96
+ end
97
+
38
98
  private def amount(data)
39
99
  {
40
100
  currency: data[:data][:object][:currency]&.upcase,
@@ -1,3 +1,3 @@
1
1
  module Compensated
2
- VERSION = "0.1.0.pre11"
2
+ VERSION = "0.1.0.pre12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compensated
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre11
4
+ version: 0.1.0.pre12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-03 00:00:00.000000000 Z
11
+ date: 2020-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler