reji 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +14 -0
- data/.gitattributes +4 -0
- data/.gitignore +15 -0
- data/.travis.yml +28 -0
- data/Appraisals +17 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +133 -0
- data/LICENSE +20 -0
- data/README.md +1285 -0
- data/Rakefile +21 -0
- data/app/controllers/reji/payment_controller.rb +31 -0
- data/app/controllers/reji/webhook_controller.rb +170 -0
- data/app/views/payment.html.erb +228 -0
- data/app/views/receipt.html.erb +250 -0
- data/bin/setup +12 -0
- data/config/routes.rb +6 -0
- data/gemfiles/rails_5.0.gemfile +13 -0
- data/gemfiles/rails_5.1.gemfile +13 -0
- data/gemfiles/rails_5.2.gemfile +13 -0
- data/gemfiles/rails_6.0.gemfile +13 -0
- data/lib/generators/reji/install/install_generator.rb +69 -0
- data/lib/generators/reji/install/templates/db/migrate/add_reji_to_users.rb.erb +16 -0
- data/lib/generators/reji/install/templates/db/migrate/create_subscription_items.rb.erb +19 -0
- data/lib/generators/reji/install/templates/db/migrate/create_subscriptions.rb.erb +22 -0
- data/lib/generators/reji/install/templates/reji.rb +36 -0
- data/lib/reji.rb +75 -0
- data/lib/reji/billable.rb +13 -0
- data/lib/reji/concerns/interacts_with_payment_behavior.rb +33 -0
- data/lib/reji/concerns/manages_customer.rb +113 -0
- data/lib/reji/concerns/manages_invoices.rb +136 -0
- data/lib/reji/concerns/manages_payment_methods.rb +202 -0
- data/lib/reji/concerns/manages_subscriptions.rb +91 -0
- data/lib/reji/concerns/performs_charges.rb +36 -0
- data/lib/reji/concerns/prorates.rb +38 -0
- data/lib/reji/configuration.rb +59 -0
- data/lib/reji/engine.rb +4 -0
- data/lib/reji/errors.rb +66 -0
- data/lib/reji/invoice.rb +243 -0
- data/lib/reji/invoice_line_item.rb +98 -0
- data/lib/reji/payment.rb +61 -0
- data/lib/reji/payment_method.rb +32 -0
- data/lib/reji/subscription.rb +567 -0
- data/lib/reji/subscription_builder.rb +206 -0
- data/lib/reji/subscription_item.rb +97 -0
- data/lib/reji/tax.rb +48 -0
- data/lib/reji/version.rb +5 -0
- data/reji.gemspec +32 -0
- data/spec/dummy/app/models/user.rb +21 -0
- data/spec/dummy/application.rb +53 -0
- data/spec/dummy/config/database.yml +11 -0
- data/spec/dummy/db/schema.rb +40 -0
- data/spec/feature/charges_spec.rb +67 -0
- data/spec/feature/customer_spec.rb +23 -0
- data/spec/feature/invoices_spec.rb +73 -0
- data/spec/feature/multiplan_subscriptions_spec.rb +319 -0
- data/spec/feature/payment_methods_spec.rb +149 -0
- data/spec/feature/pending_updates_spec.rb +77 -0
- data/spec/feature/subscriptions_spec.rb +650 -0
- data/spec/feature/webhooks_spec.rb +162 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/feature_helpers.rb +39 -0
- data/spec/unit/customer_spec.rb +54 -0
- data/spec/unit/invoice_line_item_spec.rb +72 -0
- data/spec/unit/invoice_spec.rb +192 -0
- data/spec/unit/payment_spec.rb +33 -0
- data/spec/unit/subscription_spec.rb +103 -0
- metadata +237 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'payment', type: :unit do
|
6
|
+
it 'can_return_its_requires_payment_method_status' do
|
7
|
+
payment_intent = Stripe::PaymentIntent.new
|
8
|
+
payment_intent.status = 'requires_payment_method'
|
9
|
+
payment = Reji::Payment.new(payment_intent)
|
10
|
+
expect(payment.requires_payment_method).to be true
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can_return_its_requires_action_status' do
|
14
|
+
payment_intent = Stripe::PaymentIntent.new
|
15
|
+
payment_intent.status = 'requires_action'
|
16
|
+
payment = Reji::Payment.new(payment_intent)
|
17
|
+
expect(payment.requires_action).to be true
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'can_return_its_cancelled_status' do
|
21
|
+
payment_intent = Stripe::PaymentIntent.new
|
22
|
+
payment_intent.status = 'canceled'
|
23
|
+
payment = Reji::Payment.new(payment_intent)
|
24
|
+
expect(payment.is_cancelled).to be true
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'can_return_its_succeeded_status' do
|
28
|
+
payment_intent = Stripe::PaymentIntent.new
|
29
|
+
payment_intent.status = 'succeeded'
|
30
|
+
payment = Reji::Payment.new(payment_intent)
|
31
|
+
expect(payment.is_succeeded).to be true
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'subscription', type: :unit do
|
6
|
+
it 'can_check_if_a_subscription_is_incomplete' do
|
7
|
+
subscription = Reji::Subscription.new(stripe_status: 'incomplete')
|
8
|
+
|
9
|
+
expect(subscription.incomplete).to be true
|
10
|
+
expect(subscription.past_due).to be false
|
11
|
+
expect(subscription.active).to be false
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'can_check_if_a_subscription_is_past_due' do
|
15
|
+
subscription = Reji::Subscription.new(stripe_status: 'past_due')
|
16
|
+
|
17
|
+
expect(subscription.incomplete).to be false
|
18
|
+
expect(subscription.past_due).to be true
|
19
|
+
expect(subscription.active).to be false
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'can_check_if_a_subscription_is_active' do
|
23
|
+
subscription = Reji::Subscription.new(stripe_status: 'active')
|
24
|
+
|
25
|
+
expect(subscription.incomplete).to be false
|
26
|
+
expect(subscription.past_due).to be false
|
27
|
+
expect(subscription.active).to be true
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'can_check_if_an_incomplete_subscription_is_not_valid' do
|
31
|
+
subscription = Reji::Subscription.new(stripe_status: 'incomplete')
|
32
|
+
|
33
|
+
expect(subscription.valid).to be false
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'can_check_if_a_past_due_subscription_is_not_valid' do
|
37
|
+
subscription = Reji::Subscription.new(stripe_status: 'past_due')
|
38
|
+
|
39
|
+
expect(subscription.valid).to be false
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'can_check_if_an_active_subscription_is_valid' do
|
43
|
+
subscription = Reji::Subscription.new(stripe_status: 'active')
|
44
|
+
|
45
|
+
expect(subscription.valid).to be true
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'test_payment_is_incomplete_when_status_is_incomplete' do
|
49
|
+
subscription = Reji::Subscription.new(stripe_status: 'incomplete')
|
50
|
+
|
51
|
+
expect(subscription.has_incomplete_payment).to be true
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'test_payment_is_incomplete_when_status_is_past_due' do
|
55
|
+
subscription = Reji::Subscription.new(stripe_status: 'past_due')
|
56
|
+
|
57
|
+
expect(subscription.has_incomplete_payment).to be true
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'test_payment_is_not_incomplete_when_status_is_active' do
|
61
|
+
subscription = Reji::Subscription.new(stripe_status: 'active')
|
62
|
+
|
63
|
+
expect(subscription.has_incomplete_payment).to be false
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'test_incomplete_subscriptions_cannot_be_swapped' do
|
67
|
+
subscription = Reji::Subscription.new(stripe_status: 'incomplete')
|
68
|
+
|
69
|
+
expect {
|
70
|
+
subscription.swap('premium_plan')
|
71
|
+
}.to raise_error(Reji::SubscriptionUpdateFailureError)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'test_incomplete_subscriptions_cannot_update_their_quantity' do
|
75
|
+
subscription = Reji::Subscription.new(stripe_status: 'incomplete')
|
76
|
+
|
77
|
+
expect {
|
78
|
+
subscription.update_quantity(5)
|
79
|
+
}.to raise_error(Reji::SubscriptionUpdateFailureError)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'test_extending_a_trial_requires_a_date_in_the_future' do
|
83
|
+
subscription = Reji::Subscription.new
|
84
|
+
|
85
|
+
expect {
|
86
|
+
subscription.extend_trial(Time.now - 1.day)
|
87
|
+
}.to raise_error(ArgumentError)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'can_check_if_it_has_a_single_plan' do
|
91
|
+
subscription = Reji::Subscription.new(stripe_plan: 'foo')
|
92
|
+
|
93
|
+
expect(subscription.has_single_plan).to be true
|
94
|
+
expect(subscription.has_multiple_plans).to be false
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'can_check_if_it_has_multiple_plans' do
|
98
|
+
subscription = Reji::Subscription.new(stripe_plan: nil)
|
99
|
+
|
100
|
+
expect(subscription.has_single_plan).to be false
|
101
|
+
expect(subscription.has_multiple_plans).to be true
|
102
|
+
end
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,237 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reji
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cuong Giang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: stripe
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: money
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: railties
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: actionmailer
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: wicked_pdf
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: wkhtmltopdf-binary
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec-rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 4.0.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 4.0.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: sqlite3
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.4.2
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.4.2
|
139
|
+
description: Reji provides an expressive, fluent interface to Stripe's subscription
|
140
|
+
billing services.
|
141
|
+
email:
|
142
|
+
- thaicuong.giang@gmail.com
|
143
|
+
executables: []
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- ".editorconfig"
|
148
|
+
- ".gitattributes"
|
149
|
+
- ".gitignore"
|
150
|
+
- ".travis.yml"
|
151
|
+
- Appraisals
|
152
|
+
- Gemfile
|
153
|
+
- Gemfile.lock
|
154
|
+
- LICENSE
|
155
|
+
- README.md
|
156
|
+
- Rakefile
|
157
|
+
- app/controllers/reji/payment_controller.rb
|
158
|
+
- app/controllers/reji/webhook_controller.rb
|
159
|
+
- app/views/payment.html.erb
|
160
|
+
- app/views/receipt.html.erb
|
161
|
+
- bin/setup
|
162
|
+
- config/routes.rb
|
163
|
+
- gemfiles/rails_5.0.gemfile
|
164
|
+
- gemfiles/rails_5.1.gemfile
|
165
|
+
- gemfiles/rails_5.2.gemfile
|
166
|
+
- gemfiles/rails_6.0.gemfile
|
167
|
+
- lib/generators/reji/install/install_generator.rb
|
168
|
+
- lib/generators/reji/install/templates/db/migrate/add_reji_to_users.rb.erb
|
169
|
+
- lib/generators/reji/install/templates/db/migrate/create_subscription_items.rb.erb
|
170
|
+
- lib/generators/reji/install/templates/db/migrate/create_subscriptions.rb.erb
|
171
|
+
- lib/generators/reji/install/templates/reji.rb
|
172
|
+
- lib/reji.rb
|
173
|
+
- lib/reji/billable.rb
|
174
|
+
- lib/reji/concerns/interacts_with_payment_behavior.rb
|
175
|
+
- lib/reji/concerns/manages_customer.rb
|
176
|
+
- lib/reji/concerns/manages_invoices.rb
|
177
|
+
- lib/reji/concerns/manages_payment_methods.rb
|
178
|
+
- lib/reji/concerns/manages_subscriptions.rb
|
179
|
+
- lib/reji/concerns/performs_charges.rb
|
180
|
+
- lib/reji/concerns/prorates.rb
|
181
|
+
- lib/reji/configuration.rb
|
182
|
+
- lib/reji/engine.rb
|
183
|
+
- lib/reji/errors.rb
|
184
|
+
- lib/reji/invoice.rb
|
185
|
+
- lib/reji/invoice_line_item.rb
|
186
|
+
- lib/reji/payment.rb
|
187
|
+
- lib/reji/payment_method.rb
|
188
|
+
- lib/reji/subscription.rb
|
189
|
+
- lib/reji/subscription_builder.rb
|
190
|
+
- lib/reji/subscription_item.rb
|
191
|
+
- lib/reji/tax.rb
|
192
|
+
- lib/reji/version.rb
|
193
|
+
- reji.gemspec
|
194
|
+
- spec/dummy/app/models/user.rb
|
195
|
+
- spec/dummy/application.rb
|
196
|
+
- spec/dummy/config/database.yml
|
197
|
+
- spec/dummy/db/schema.rb
|
198
|
+
- spec/feature/charges_spec.rb
|
199
|
+
- spec/feature/customer_spec.rb
|
200
|
+
- spec/feature/invoices_spec.rb
|
201
|
+
- spec/feature/multiplan_subscriptions_spec.rb
|
202
|
+
- spec/feature/payment_methods_spec.rb
|
203
|
+
- spec/feature/pending_updates_spec.rb
|
204
|
+
- spec/feature/subscriptions_spec.rb
|
205
|
+
- spec/feature/webhooks_spec.rb
|
206
|
+
- spec/spec_helper.rb
|
207
|
+
- spec/support/feature_helpers.rb
|
208
|
+
- spec/unit/customer_spec.rb
|
209
|
+
- spec/unit/invoice_line_item_spec.rb
|
210
|
+
- spec/unit/invoice_spec.rb
|
211
|
+
- spec/unit/payment_spec.rb
|
212
|
+
- spec/unit/subscription_spec.rb
|
213
|
+
homepage: https://github.com/cuonggt/reji
|
214
|
+
licenses:
|
215
|
+
- MIT
|
216
|
+
metadata: {}
|
217
|
+
post_install_message:
|
218
|
+
rdoc_options: []
|
219
|
+
require_paths:
|
220
|
+
- lib
|
221
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
222
|
+
requirements:
|
223
|
+
- - ">="
|
224
|
+
- !ruby/object:Gem::Version
|
225
|
+
version: 2.4.0
|
226
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - ">="
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: '0'
|
231
|
+
requirements: []
|
232
|
+
rubygems_version: 3.1.2
|
233
|
+
signing_key:
|
234
|
+
specification_version: 4
|
235
|
+
summary: Reji provides an expressive, fluent interface to Stripe's subscription billing
|
236
|
+
services.
|
237
|
+
test_files: []
|