compensated 0.1.0.pre12 → 0.1.0.pre13
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 +49 -12
- data/lib/compensated/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ffaeea7f175182813c34e67a329003fd5d59830fad22ba2fdee2a0431e8d471
|
4
|
+
data.tar.gz: 8afb60789b60155b3b905e92235f861583fdda79507d3d2e2c1c61c4e10fa71b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee192c911a7d01c525f99ff4bb5dd9b894de9346fead72f0bdb7699dceec262ab24cd78625063de80321310bab284785a995379d6a70959603be23a36a0af7d9
|
7
|
+
data.tar.gz: df66cefcd2e238b646bf68f1814dc9519ddea22e9a5c0d8f50822112f640fd9bde12303ef47d308cacbd0e135c3aab9870c4435e7e20b16f3960038cde57e0e7
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require "compensated/event_parser"
|
2
2
|
module Compensated
|
3
3
|
module Stripe
|
4
|
-
SUPPORTED_EVENTS = %w[charge.succeeded invoice.payment_succeeded invoice.payment_failed
|
4
|
+
SUPPORTED_EVENTS = %w[charge.succeeded invoice.payment_succeeded invoice.payment_failed
|
5
|
+
customer.subscription.updated customer.subscription.deleted]
|
5
6
|
class EventParser < Compensated::EventParser
|
6
7
|
def parses?(request)
|
7
8
|
return false if request.nil? || request.empty?
|
@@ -45,13 +46,16 @@ module Compensated
|
|
45
46
|
end
|
46
47
|
|
47
48
|
private def products(data)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
key = (invoice?(data) ? :lines : :items)
|
50
|
+
return [] unless data[:data][:object][key]
|
51
|
+
items = data[:data][:object][key][:data]
|
52
|
+
|
53
|
+
items.map do |line|
|
54
|
+
value = product(line, data)
|
55
|
+
next if value.nil? || value.empty?
|
56
|
+
value
|
54
57
|
end
|
58
|
+
|
55
59
|
end
|
56
60
|
|
57
61
|
private def product(line, data)
|
@@ -61,14 +65,43 @@ module Compensated
|
|
61
65
|
purchased: purchased(data),
|
62
66
|
description: line[:description],
|
63
67
|
quantity: line[:quantity],
|
64
|
-
|
65
|
-
|
68
|
+
# TODO: Deprecate `expiration` as it now lives on subscription!
|
69
|
+
# BUT people are using `expiration` so let's figure out
|
70
|
+
# a way to safely remove it.
|
71
|
+
expiration: period_end(line, data),
|
72
|
+
subscription: subscription(line, data),
|
66
73
|
plan: plan(line)
|
67
74
|
}.compact
|
68
75
|
end
|
69
76
|
|
70
|
-
private def
|
71
|
-
|
77
|
+
private def period_start(line, data)
|
78
|
+
return nil unless line[:period] || data[:data][:object][:current_period_start]
|
79
|
+
timestamp = line[:period] ? line[:period][:start] : data[:data][:object][:current_period_start]
|
80
|
+
Time.at(timestamp)
|
81
|
+
end
|
82
|
+
private def period_end(line, data)
|
83
|
+
return nil unless line[:period] || data[:data][:object][:current_period_end]
|
84
|
+
timestamp = line[:period] ? line[:period][:end] : data[:data][:object][:current_period_end]
|
85
|
+
Time.at(timestamp)
|
86
|
+
end
|
87
|
+
|
88
|
+
private def subscription(line, data)
|
89
|
+
{
|
90
|
+
id: line[:subscription],
|
91
|
+
period: {
|
92
|
+
start: period_start(line, data),
|
93
|
+
end: period_end(line, data),
|
94
|
+
}.compact,
|
95
|
+
status: subscription_status(data)
|
96
|
+
}.compact
|
97
|
+
end
|
98
|
+
|
99
|
+
private def subscription_status(data)
|
100
|
+
return :ended unless data[:data][:object][:ended_at].nil?
|
101
|
+
return :canceled unless data[:data][:object][:canceled_at].nil?
|
102
|
+
return :active if data[:data][:object][:status] == "paid"
|
103
|
+
|
104
|
+
data[:data][:object][:status].to_sym
|
72
105
|
end
|
73
106
|
|
74
107
|
private def plan(line)
|
@@ -90,7 +123,11 @@ module Compensated
|
|
90
123
|
end
|
91
124
|
|
92
125
|
private def purchased(data)
|
93
|
-
string = data[:data][:object][:
|
126
|
+
string = if data[:data][:object][:created]
|
127
|
+
data[:data][:object][:created]
|
128
|
+
else
|
129
|
+
data[:data][:object][:status_transitions][0][:paid_at]
|
130
|
+
end
|
94
131
|
return nil if string.nil?
|
95
132
|
Time.at(string)
|
96
133
|
end
|
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.pre13
|
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-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,8 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: 1.3.1
|
117
117
|
requirements: []
|
118
|
-
|
119
|
-
rubygems_version: 2.7.6.2
|
118
|
+
rubygems_version: 3.0.3
|
120
119
|
signing_key:
|
121
120
|
specification_version: 4
|
122
121
|
summary: Provide value (In Ruby!). Get paid.
|