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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d701a31887818f8b5fa89413988ba8bee2ab34938d03cc421cb04be94a698b68
4
- data.tar.gz: 489fc733af7b69328168a4a131de5c6b57a5b81bb157c548332003ca98868195
3
+ metadata.gz: c76aed04efe1e981e30c9905002e67f5161cc2007fc8785a5c98150761520656
4
+ data.tar.gz: 77fff50a094e6382809410798ec86c8b8289a9d0a8641dd12b806b390218f38f
5
5
  SHA512:
6
- metadata.gz: 64fd0e8a23e58277f78ed72c9766ebbaaf2ff96fb1ab51fc5a4a30c16cc4bd8ac4e6a0d063b238c1eb7781c62a519ff9ecce8371a3fe48bec824cd0b4d63e4e0
7
- data.tar.gz: 30a8d90727a1df042ba595c807ed8a05244560314782b7c30aebd79bf004925c61ba66a54cb8cf7bdaba0d6f7b085350c167f37b789d1eed2e4f322982dd5b15
6
+ metadata.gz: f2d3b4db1b4f58029d17ea7c1de51050b9ddb79540e9b84eb232c0ea9c641b43d8461419b116dfba2cdb18c4754006f8521f34ee88b6d8373bce8c2431c2066f
7
+ data.tar.gz: 7587235b2582950156bf500b8763591fdd00ccac9b85ed8356023f673137666d04705138f4ba160577517e5c338907965c81d0044d718fa21164284ba6bca6a4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.1.0] - 2025-03-27
4
+
5
+ - Add `Puma::Plugin::Stripe.signing_secret`
6
+
3
7
  ## [1.0.0] - 2025-02-19
4
8
 
5
9
  - Initial release
data/README.md CHANGED
@@ -1,26 +1,69 @@
1
- # Puma::Plugin::Stripe
1
+ # Stripe Puma Plugin
2
2
 
3
3
  Forward Stripe webhook events to your web server.
4
4
 
5
5
  ## Installation
6
6
 
7
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
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 UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
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 UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
16
+ gem install puma-plugin-stripe
19
17
  ```
20
18
 
21
19
  ## Usage
22
20
 
23
- Add `plugin :stripe` to `puma.rb`.
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
 
@@ -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.0.0
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-02-19 00:00:00.000000000 Z
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.3
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: []