puma-plugin-stripe 1.0.0 → 1.1.0
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/CHANGELOG.md +4 -0
- data/README.md +50 -7
- data/lib/puma/plugin/stripe.rb +10 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c76aed04efe1e981e30c9905002e67f5161cc2007fc8785a5c98150761520656
|
4
|
+
data.tar.gz: 77fff50a094e6382809410798ec86c8b8289a9d0a8641dd12b806b390218f38f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2d3b4db1b4f58029d17ea7c1de51050b9ddb79540e9b84eb232c0ea9c641b43d8461419b116dfba2cdb18c4754006f8521f34ee88b6d8373bce8c2431c2066f
|
7
|
+
data.tar.gz: 7587235b2582950156bf500b8763591fdd00ccac9b85ed8356023f673137666d04705138f4ba160577517e5c338907965c81d0044d718fa21164284ba6bca6a4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,26 +1,69 @@
|
|
1
|
-
# Puma
|
1
|
+
# Stripe Puma Plugin
|
2
2
|
|
3
3
|
Forward Stripe webhook events to your web server.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
Install the gem and add to the application's Gemfile by executing:
|
7
|
+
Install the [Stripe CLI](https://docs.stripe.com/stripe-cli#install), then install the gem and add to the application's Gemfile by executing:
|
10
8
|
|
11
9
|
```bash
|
12
|
-
bundle add
|
10
|
+
bundle add puma-plugin-stripe
|
13
11
|
```
|
14
12
|
|
15
13
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
14
|
|
17
15
|
```bash
|
18
|
-
gem install
|
16
|
+
gem install puma-plugin-stripe
|
19
17
|
```
|
20
18
|
|
21
19
|
## Usage
|
22
20
|
|
23
|
-
|
21
|
+
Make sure `Stripe.api_key` is set, e.g. in `config/initializers/stripe.rb`:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Stripe.api_key = "sk_test_..."
|
25
|
+
```
|
26
|
+
|
27
|
+
Add `plugin :stripe` to `puma.rb` configuration:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# Run stripe cli only in development.
|
31
|
+
plugin :stripe if ENV["RAILS_ENV"] == "development"
|
32
|
+
```
|
33
|
+
|
34
|
+
By default, events will be forwarded to `/stripe_events`, this can be configured using `stripe_forward_to "/stripe/webhook"` in `puma.rb`.
|
35
|
+
|
36
|
+
You can grab your *signing secret* using `Puma::Plugin::Stripe.signing_secret`. For example:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
class StripeEventsController < ActionController::API
|
40
|
+
before_action :set_event
|
41
|
+
|
42
|
+
def create
|
43
|
+
case event.type
|
44
|
+
when 'payment_intent.succeeded'
|
45
|
+
payment_intent = event.data.object
|
46
|
+
# ...
|
47
|
+
end
|
48
|
+
|
49
|
+
head :ok
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def event
|
55
|
+
@event ||= Stripe::Webhook.construct_event(
|
56
|
+
request.body.read,
|
57
|
+
request.headers["stripe-signature"],
|
58
|
+
Puma::Plugin::Stripe.signing_secret(Stripe.api_key)
|
59
|
+
)
|
60
|
+
rescue => error
|
61
|
+
logger.error error
|
62
|
+
head :bad_request
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
```
|
24
67
|
|
25
68
|
## Development
|
26
69
|
|
data/lib/puma/plugin/stripe.rb
CHANGED
@@ -3,6 +3,16 @@
|
|
3
3
|
require "stripe"
|
4
4
|
require "puma/plugin"
|
5
5
|
|
6
|
+
module Puma::Plugin::Stripe
|
7
|
+
def self.signing_secret(api_key)
|
8
|
+
secret = `stripe listen --api-key "#{api_key}" --print-secret`.chomp
|
9
|
+
return nil unless $?.success?
|
10
|
+
secret unless secret.empty?
|
11
|
+
rescue
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
6
16
|
Puma::Plugin.create do
|
7
17
|
def start(launcher)
|
8
18
|
@launcher = launcher
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puma-plugin-stripe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zacharias Knudsen
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-03-27 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: puma
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
|
-
rubygems_version: 3.6.
|
85
|
+
rubygems_version: 3.6.2
|
86
86
|
specification_version: 4
|
87
87
|
summary: Forward Stripe webhook events to your web server.
|
88
88
|
test_files: []
|