nocheckout 0.1.0 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +151 -9
- data/README.md +61 -39
- data/Rakefile +1 -1
- data/app/controllers/nocheckout/stripe/checkout_sessions_controller.rb +99 -0
- data/app/controllers/nocheckout/stripe/webhooks_controller.rb +2 -2
- data/app/controllers/nocheckout/stripe.rb +8 -0
- data/config/initializers/inflections.rb +3 -0
- data/config/initializers/stripe.rb +3 -0
- data/config/routes.rb +2 -0
- data/lib/nocheckout/engine.rb +3 -1
- data/lib/nocheckout/version.rb +1 -1
- data/lib/nocheckout.rb +2 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9db06290291d396f599cd4480858528a842f818be68f58e154ad7e5f5f8b6299
|
4
|
+
data.tar.gz: '06974973a6ac44a4c909e48bc82737c3f16639981016d3ee9e4b815c74b38203'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d900112610418b2b15882d3e2b58ba13bd6ced82e6fa01dbcfa84442436a941fb1454a754c8e2b5e76d2ef861bf7abf3653f3b02a4f6ecfc297d5d9e7ab8995
|
7
|
+
data.tar.gz: 44e17d5ff40f48f7744711871cbb68ef9522248e521a2e0743b66486458f4ae4be6a15b41ab5bc0826b16534c168566234aa94a77d633db91bbb5e7ec7ebd38b
|
data/Gemfile.lock
CHANGED
@@ -1,23 +1,156 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nocheckout (0.1.
|
4
|
+
nocheckout (0.1.2)
|
5
|
+
rails (~> 7.0)
|
5
6
|
stripe (>= 7.0)
|
6
7
|
zeitwerk (~> 2.0)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
12
|
+
actioncable (7.0.8)
|
13
|
+
actionpack (= 7.0.8)
|
14
|
+
activesupport (= 7.0.8)
|
15
|
+
nio4r (~> 2.0)
|
16
|
+
websocket-driver (>= 0.6.1)
|
17
|
+
actionmailbox (7.0.8)
|
18
|
+
actionpack (= 7.0.8)
|
19
|
+
activejob (= 7.0.8)
|
20
|
+
activerecord (= 7.0.8)
|
21
|
+
activestorage (= 7.0.8)
|
22
|
+
activesupport (= 7.0.8)
|
23
|
+
mail (>= 2.7.1)
|
24
|
+
net-imap
|
25
|
+
net-pop
|
26
|
+
net-smtp
|
27
|
+
actionmailer (7.0.8)
|
28
|
+
actionpack (= 7.0.8)
|
29
|
+
actionview (= 7.0.8)
|
30
|
+
activejob (= 7.0.8)
|
31
|
+
activesupport (= 7.0.8)
|
32
|
+
mail (~> 2.5, >= 2.5.4)
|
33
|
+
net-imap
|
34
|
+
net-pop
|
35
|
+
net-smtp
|
36
|
+
rails-dom-testing (~> 2.0)
|
37
|
+
actionpack (7.0.8)
|
38
|
+
actionview (= 7.0.8)
|
39
|
+
activesupport (= 7.0.8)
|
40
|
+
rack (~> 2.0, >= 2.2.4)
|
41
|
+
rack-test (>= 0.6.3)
|
42
|
+
rails-dom-testing (~> 2.0)
|
43
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
44
|
+
actiontext (7.0.8)
|
45
|
+
actionpack (= 7.0.8)
|
46
|
+
activerecord (= 7.0.8)
|
47
|
+
activestorage (= 7.0.8)
|
48
|
+
activesupport (= 7.0.8)
|
49
|
+
globalid (>= 0.6.0)
|
50
|
+
nokogiri (>= 1.8.5)
|
51
|
+
actionview (7.0.8)
|
52
|
+
activesupport (= 7.0.8)
|
53
|
+
builder (~> 3.1)
|
54
|
+
erubi (~> 1.4)
|
55
|
+
rails-dom-testing (~> 2.0)
|
56
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
57
|
+
activejob (7.0.8)
|
58
|
+
activesupport (= 7.0.8)
|
59
|
+
globalid (>= 0.3.6)
|
60
|
+
activemodel (7.0.8)
|
61
|
+
activesupport (= 7.0.8)
|
62
|
+
activerecord (7.0.8)
|
63
|
+
activemodel (= 7.0.8)
|
64
|
+
activesupport (= 7.0.8)
|
65
|
+
activestorage (7.0.8)
|
66
|
+
actionpack (= 7.0.8)
|
67
|
+
activejob (= 7.0.8)
|
68
|
+
activerecord (= 7.0.8)
|
69
|
+
activesupport (= 7.0.8)
|
70
|
+
marcel (~> 1.0)
|
71
|
+
mini_mime (>= 1.1.0)
|
72
|
+
activesupport (7.0.8)
|
73
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
74
|
+
i18n (>= 1.6, < 2)
|
75
|
+
minitest (>= 5.1)
|
76
|
+
tzinfo (~> 2.0)
|
11
77
|
ast (2.4.2)
|
78
|
+
base64 (0.1.1)
|
79
|
+
builder (3.2.4)
|
80
|
+
concurrent-ruby (1.2.2)
|
81
|
+
crass (1.0.6)
|
82
|
+
date (3.3.3)
|
12
83
|
diff-lcs (1.5.0)
|
84
|
+
erubi (1.12.0)
|
85
|
+
globalid (1.2.1)
|
86
|
+
activesupport (>= 6.1)
|
87
|
+
i18n (1.14.1)
|
88
|
+
concurrent-ruby (~> 1.0)
|
13
89
|
json (2.6.3)
|
14
90
|
language_server-protocol (3.17.0.3)
|
15
91
|
lint_roller (1.1.0)
|
92
|
+
loofah (2.21.3)
|
93
|
+
crass (~> 1.0.2)
|
94
|
+
nokogiri (>= 1.12.0)
|
95
|
+
mail (2.8.1)
|
96
|
+
mini_mime (>= 0.1.1)
|
97
|
+
net-imap
|
98
|
+
net-pop
|
99
|
+
net-smtp
|
100
|
+
marcel (1.0.2)
|
101
|
+
method_source (1.0.0)
|
102
|
+
mini_mime (1.1.5)
|
103
|
+
minitest (5.20.0)
|
104
|
+
net-imap (0.3.7)
|
105
|
+
date
|
106
|
+
net-protocol
|
107
|
+
net-pop (0.1.2)
|
108
|
+
net-protocol
|
109
|
+
net-protocol (0.2.1)
|
110
|
+
timeout
|
111
|
+
net-smtp (0.3.3)
|
112
|
+
net-protocol
|
113
|
+
nio4r (2.5.9)
|
114
|
+
nokogiri (1.15.4-arm64-darwin)
|
115
|
+
racc (~> 1.4)
|
116
|
+
nokogiri (1.15.4-x86_64-linux)
|
117
|
+
racc (~> 1.4)
|
16
118
|
parallel (1.23.0)
|
17
119
|
parser (3.2.2.3)
|
18
120
|
ast (~> 2.4.1)
|
19
121
|
racc
|
20
122
|
racc (1.7.1)
|
123
|
+
rack (2.2.8)
|
124
|
+
rack-test (2.1.0)
|
125
|
+
rack (>= 1.3)
|
126
|
+
rails (7.0.8)
|
127
|
+
actioncable (= 7.0.8)
|
128
|
+
actionmailbox (= 7.0.8)
|
129
|
+
actionmailer (= 7.0.8)
|
130
|
+
actionpack (= 7.0.8)
|
131
|
+
actiontext (= 7.0.8)
|
132
|
+
actionview (= 7.0.8)
|
133
|
+
activejob (= 7.0.8)
|
134
|
+
activemodel (= 7.0.8)
|
135
|
+
activerecord (= 7.0.8)
|
136
|
+
activestorage (= 7.0.8)
|
137
|
+
activesupport (= 7.0.8)
|
138
|
+
bundler (>= 1.15.0)
|
139
|
+
railties (= 7.0.8)
|
140
|
+
rails-dom-testing (2.2.0)
|
141
|
+
activesupport (>= 5.0.0)
|
142
|
+
minitest
|
143
|
+
nokogiri (>= 1.6)
|
144
|
+
rails-html-sanitizer (1.6.0)
|
145
|
+
loofah (~> 2.21)
|
146
|
+
nokogiri (~> 1.14)
|
147
|
+
railties (7.0.8)
|
148
|
+
actionpack (= 7.0.8)
|
149
|
+
activesupport (= 7.0.8)
|
150
|
+
method_source
|
151
|
+
rake (>= 12.2)
|
152
|
+
thor (~> 1.0)
|
153
|
+
zeitwerk (~> 2.5)
|
21
154
|
rainbow (3.1.1)
|
22
155
|
rake (13.0.6)
|
23
156
|
regexp_parser (2.8.1)
|
@@ -35,36 +168,45 @@ GEM
|
|
35
168
|
diff-lcs (>= 1.2.0, < 2.0)
|
36
169
|
rspec-support (~> 3.12.0)
|
37
170
|
rspec-support (3.12.1)
|
38
|
-
rubocop (1.
|
171
|
+
rubocop (1.56.3)
|
172
|
+
base64 (~> 0.1.1)
|
39
173
|
json (~> 2.3)
|
174
|
+
language_server-protocol (>= 3.17.0)
|
40
175
|
parallel (~> 1.10)
|
41
176
|
parser (>= 3.2.2.3)
|
42
177
|
rainbow (>= 2.2.2, < 4.0)
|
43
178
|
regexp_parser (>= 1.8, < 3.0)
|
44
179
|
rexml (>= 3.2.5, < 4.0)
|
45
|
-
rubocop-ast (>= 1.28.
|
180
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
46
181
|
ruby-progressbar (~> 1.7)
|
47
182
|
unicode-display_width (>= 2.4.0, < 3.0)
|
48
183
|
rubocop-ast (1.29.0)
|
49
184
|
parser (>= 3.2.1.0)
|
50
|
-
rubocop-performance (1.
|
185
|
+
rubocop-performance (1.19.0)
|
51
186
|
rubocop (>= 1.7.0, < 2.0)
|
52
187
|
rubocop-ast (>= 0.4.0)
|
53
188
|
ruby-progressbar (1.13.0)
|
54
|
-
standard (1.
|
189
|
+
standard (1.31.1)
|
55
190
|
language_server-protocol (~> 3.17.0.2)
|
56
191
|
lint_roller (~> 1.0)
|
57
|
-
rubocop (~> 1.
|
192
|
+
rubocop (~> 1.56.2)
|
58
193
|
standard-custom (~> 1.0.0)
|
59
|
-
standard-performance (~> 1.
|
194
|
+
standard-performance (~> 1.2)
|
60
195
|
standard-custom (1.0.2)
|
61
196
|
lint_roller (~> 1.0)
|
62
197
|
rubocop (~> 1.50)
|
63
|
-
standard-performance (1.
|
198
|
+
standard-performance (1.2.0)
|
64
199
|
lint_roller (~> 1.1)
|
65
|
-
rubocop-performance (~> 1.
|
200
|
+
rubocop-performance (~> 1.19.0)
|
66
201
|
stripe (9.2.0)
|
202
|
+
thor (1.2.2)
|
203
|
+
timeout (0.4.0)
|
204
|
+
tzinfo (2.0.6)
|
205
|
+
concurrent-ruby (~> 1.0)
|
67
206
|
unicode-display_width (2.4.2)
|
207
|
+
websocket-driver (0.7.6)
|
208
|
+
websocket-extensions (>= 0.1.0)
|
209
|
+
websocket-extensions (0.1.5)
|
68
210
|
zeitwerk (2.6.11)
|
69
211
|
|
70
212
|
PLATFORMS
|
data/README.md
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# NoCheckout
|
2
2
|
|
3
|
-
|
3
|
+
> [!IMPORTANT]
|
4
|
+
> This project is a work in progress. This README was written to better understand the implementation for developers. **Some of the APIs may not have yet been implemented, renamed, or removed**. When the API settles down and is running in production for a while, a 1.0 release will be cut and this notice removed.
|
4
5
|
|
5
|
-
|
6
|
+
NoCheckout is a set of Rails controllers that does the least amount possible to integrate with Stripe. That might sound lazy at first, and it is, but if you try to roll your own signup and payment form and keep your Rails database sync'ed with your payment info, you'll quickly find out there's better things in life to worry about. Its best to delegate as much payment collection, processing, and reporting to your payment processor as you can. Fortunately Stripe does a great job sweating all the details in checkout UX and reporting that I'm OK delegating everything out to them.
|
6
7
|
|
7
|
-
|
8
|
+
This gem does that--it sends your users down the [Stripe Checkout](https://stripe.com/docs/payments/checkout/how-checkout-works) path for buying stuff, then sends them back to your site via the CheckoutSessions controller. There's also a StripeWebhooks controller that handles Stripe's callbacks in a plain 'ol controller. You don't even have to include the `stripe.js` file on your website, which means your users experience a faster, more private browsing session.
|
9
|
+
|
10
|
+
That's it! There's not much to it and that's the point.
|
8
11
|
|
9
12
|
## Installation
|
10
13
|
|
@@ -16,13 +19,65 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
16
19
|
|
17
20
|
$ gem install nocheckout
|
18
21
|
|
22
|
+
## Get a Stripe API key
|
23
|
+
|
24
|
+
Before you do anything you'll need to go to https://dashboard.stripe.com/test/apikeys and get the "Secret Key". You can set the `STRIPE_SECRET_KEY` environment variable or create an initializer using your configuration manager of choice:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# Set the API key in ./config/initializers/stripe.rb
|
28
|
+
Stripe.api_key = Rails.configuration.stripe[:secret_key]
|
29
|
+
```
|
30
|
+
|
19
31
|
## Usage
|
20
32
|
|
21
33
|
This library comes with two controllers, both map closely to their respective Stripe docs.
|
22
34
|
|
35
|
+
### Checkout Sessions Controller
|
36
|
+
|
37
|
+
[Stripe Checkout Sessions](https://stripe.com/docs/api/checkout/sessions) send users from your website to a branded stripe.com page where they can enter their credit card details and complete the purchase. Once the purchase is complete, the user is redirected back to your website.
|
38
|
+
|
39
|
+
The NoCheckout::CheckoutSessionsController handles the interface between Stripe and your Rails application and tries to be as small as possible.
|
40
|
+
|
41
|
+
To get started, create a base CheckoutSessionsController that maps the Users from your application with [Stripe Customers](https://stripe.com/docs/api/customers).
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class CheckoutSessionsController < NoCheckout::Stripe::CheckoutSessionsController
|
45
|
+
protected
|
46
|
+
def customer_id
|
47
|
+
user.id
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_customer
|
51
|
+
Stripe::Customer.create(
|
52
|
+
id: customer_id,
|
53
|
+
name: user.name,
|
54
|
+
email: user.email
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
Then, for each product you want to offer, create a controller and inherit the `CheckoutSessionsController`.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
class PlusCheckoutSessionsController < PaymentsController
|
64
|
+
STRIPE_PRICE = "price_..."
|
65
|
+
|
66
|
+
protected
|
67
|
+
def create_checkout_session
|
68
|
+
create_stripe_checkout_session line_items: [{
|
69
|
+
price: STRIPE_PRICE,
|
70
|
+
quantity: 1
|
71
|
+
}]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
There's a lot of different ways you can wire up the controllers depending on how many Stripe prices are in your application. This README assumes you're selling just a few products, so the prices are hard coded as constants in the controller. This could easily be populated from a database.
|
77
|
+
|
23
78
|
### Webhooks Controller
|
24
79
|
|
25
|
-
[Stripe Webhooks](https://stripe.com/docs/webhooks) are extensive and keep your application up-to-date with what Stripe
|
80
|
+
[Stripe Webhooks](https://stripe.com/docs/webhooks) are extensive and keep your application up-to-date with what Stripe. In this example, we'll look at how to handle a subscription that's expiring and update a User record in our database.
|
26
81
|
|
27
82
|
```ruby
|
28
83
|
class StripesController < NoCheckout::Stripe::WebhooksController
|
@@ -48,39 +103,6 @@ class StripesController < NoCheckout::Stripe::WebhooksController
|
|
48
103
|
end
|
49
104
|
```
|
50
105
|
|
51
|
-
### Checkouts Controller
|
52
|
-
|
53
|
-
First you need to create a base Payments controller that includes credentials and how a customer is created.
|
54
|
-
|
55
|
-
```ruby
|
56
|
-
class PaymentsController < NoCheckout::Stripe::PaymentsController
|
57
|
-
STRIPE_PUBLIC_KEY = ENV["STRIPE_PUBLIC_KEY"]
|
58
|
-
STRIPE_PRIVATE_KEY = ENV["STRIPE_PRIVATE_KEY"]
|
59
|
-
|
60
|
-
protected
|
61
|
-
def customer_id
|
62
|
-
user.id
|
63
|
-
end
|
64
|
-
|
65
|
-
def create_customer
|
66
|
-
Stripe::Customer.create(
|
67
|
-
id: customer_id,
|
68
|
-
name: user.name,
|
69
|
-
email: user.email
|
70
|
-
)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
```
|
74
|
-
|
75
|
-
Then, for each product you want to offer, create a controller and inherit the `PaymentsController`
|
76
|
-
|
77
|
-
```ruby
|
78
|
-
class PlusPlanPaymentsController < PaymentsController
|
79
|
-
def create_checkout_session
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
106
|
## Development
|
85
107
|
|
86
108
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -89,7 +111,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
89
111
|
|
90
112
|
## Contributing
|
91
113
|
|
92
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
114
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rubymonolith/nocheckout. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/rubymonolith/nocheckout/blob/main/CODE_OF_CONDUCT.md).
|
93
115
|
|
94
116
|
## License
|
95
117
|
|
@@ -97,4 +119,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
97
119
|
|
98
120
|
## Code of Conduct
|
99
121
|
|
100
|
-
Everyone interacting in the NoCheckout project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
122
|
+
Everyone interacting in the NoCheckout project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rubymonolith/nocheckout/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
@@ -0,0 +1,99 @@
|
|
1
|
+
module NoCheckout::Stripe
|
2
|
+
class CheckoutSessionsController < ApplicationController
|
3
|
+
def new
|
4
|
+
redirect_to checkout_session.url, allow_other_host: true
|
5
|
+
end
|
6
|
+
|
7
|
+
protected
|
8
|
+
def checkout_session
|
9
|
+
@checkout_session ||= find_or_create_checkout_session
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_checkout_session
|
13
|
+
raise "Implement a method here that returns a Stripe::Checkout::Session"
|
14
|
+
end
|
15
|
+
|
16
|
+
def customer_id
|
17
|
+
current_user.id
|
18
|
+
end
|
19
|
+
|
20
|
+
# Actually creates a Stripe checkout session. The reason I had to create
|
21
|
+
# this method is so I could "curry" the values within so the `create_checkout_session`
|
22
|
+
# could be a bit more readable and work better with inheritance.
|
23
|
+
def create_stripe_checkout_session(**attributes)
|
24
|
+
Stripe::Checkout::Session.create \
|
25
|
+
mode: "subscription",
|
26
|
+
customer: stripe_customer,
|
27
|
+
success_url: success_url,
|
28
|
+
cancel_url: cancel_url,
|
29
|
+
**attributes
|
30
|
+
end
|
31
|
+
|
32
|
+
def callback_url(**kwargs)
|
33
|
+
# Yuck! I have to do the append at the end because rails params escape the `{CHECKOUT_SESSION_ID}` values
|
34
|
+
# to `session_id=%7BCHECKOUT_SESSION_ID%7D`. This will work though, but its def not pretty and feels a tad
|
35
|
+
# dangerous.
|
36
|
+
concat_unescaped_stripe_checkout_session_id url_for(action: :show, only_path: false, **kwargs)
|
37
|
+
end
|
38
|
+
|
39
|
+
STRIPE_CALLBACK_PARAMETER = "checkout_session_id={CHECKOUT_SESSION_ID}"
|
40
|
+
|
41
|
+
# For some reason Stripe decided to not escape the `{CHECKOUT_SESSION_ID}`, if we try to
|
42
|
+
# pass it through Rails URL builders or the URI object, it will URL encode the value and
|
43
|
+
# not work with stripe. Consequently, we have to do some weirdness here to append the callback.
|
44
|
+
#
|
45
|
+
# More information at https://stripe.com/docs/payments/checkout/custom-success-page#modify-success-url
|
46
|
+
def concat_unescaped_stripe_checkout_session_id(url)
|
47
|
+
if URI(url).query
|
48
|
+
url.concat("&#{STRIPE_CALLBACK_PARAMETER}")
|
49
|
+
else
|
50
|
+
url.concat("?#{STRIPE_CALLBACK_PARAMETER}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def success_url
|
55
|
+
callback_url(state: :success)
|
56
|
+
end
|
57
|
+
|
58
|
+
def cancel_url
|
59
|
+
callback_url(state: :cancel)
|
60
|
+
end
|
61
|
+
|
62
|
+
def stripe_customer
|
63
|
+
@stripe_customer ||= find_or_create_customer
|
64
|
+
end
|
65
|
+
|
66
|
+
def create_customer
|
67
|
+
Stripe::Customer.create(
|
68
|
+
id: String(customer_id),
|
69
|
+
name: current_user.name,
|
70
|
+
email: current_user.email
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
def find_or_create_checkout_session
|
75
|
+
if params.key? :checkout_session_id
|
76
|
+
Stripe::Checkout::Session.retrieve params.fetch(:checkout_session_id)
|
77
|
+
else
|
78
|
+
create_checkout_session
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def find_or_create_customer
|
83
|
+
return nil if customer_id.blank?
|
84
|
+
|
85
|
+
begin
|
86
|
+
Stripe::Customer.retrieve(String(customer_id))
|
87
|
+
# Blurg ... wish Stripe just returned a response object that's not an exception.
|
88
|
+
rescue Stripe::InvalidRequestError => e
|
89
|
+
case e.response.data
|
90
|
+
in error: { code: "resource_missing" }
|
91
|
+
create_customer
|
92
|
+
else
|
93
|
+
raise
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module NoCheckout
|
2
|
-
class
|
1
|
+
module NoCheckout::Stripe
|
2
|
+
class WebhooksController < NoCheckout::WebhooksController
|
3
3
|
STRIPE_SIGNING_SECRET = ENV["STRIPE_SIGNING_SECRET"]
|
4
4
|
|
5
5
|
rescue_from JSON::ParserError, with: :invalid_payload
|
data/config/routes.rb
ADDED
data/lib/nocheckout/engine.rb
CHANGED
data/lib/nocheckout/version.rb
CHANGED
data/lib/nocheckout.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nocheckout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Gessler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '7.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '7.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '7.0'
|
41
55
|
description: Rails controllers for Stripe Checkout Sessions and Webhooks
|
42
56
|
email:
|
43
57
|
- bradgessler@gmail.com
|
@@ -54,8 +68,13 @@ files:
|
|
54
68
|
- LICENSE.txt
|
55
69
|
- README.md
|
56
70
|
- Rakefile
|
71
|
+
- app/controllers/nocheckout/stripe.rb
|
72
|
+
- app/controllers/nocheckout/stripe/checkout_sessions_controller.rb
|
57
73
|
- app/controllers/nocheckout/stripe/webhooks_controller.rb
|
58
74
|
- app/controllers/nocheckout/webhooks_controller.rb
|
75
|
+
- config/initializers/inflections.rb
|
76
|
+
- config/initializers/stripe.rb
|
77
|
+
- config/routes.rb
|
59
78
|
- lib/nocheckout.rb
|
60
79
|
- lib/nocheckout/engine.rb
|
61
80
|
- lib/nocheckout/version.rb
|