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 +4 -4
- data/lib/compensated/stripe/event_parser.rb +60 -0
- data/lib/compensated/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd372eb0e25b2a4556c00570678711625b4bc2c0fbc03a39895eecf41773dded
|
4
|
+
data.tar.gz: c284ee4d7dabd693c24f4249dfa8c377541e8f96eee6d4177bd12e7f8da776af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
data/lib/compensated/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2020-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|