nocheckout 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4970cdc6cb5b9329d5a228bef45e87df83cf5669fd734173e847bb0902a60cb7
4
+ data.tar.gz: b58e0b5fc1677cf3b10e9928f4d1bfd468952fb913686193d9eb54efd3aeb328
5
+ SHA512:
6
+ metadata.gz: 124cd374f126fb03beacaf993a8302fe50f8a288caff2463d3f0fd9fa49a8f5c43724b7c1130497928c1679feab4717a7d792740b0e57bfe1a03c04bfa2f5fdc
7
+ data.tar.gz: c55bfc77908c605070ab463ca3a4bd91966a808f26725fe3bf2bdcf6589444dd35443c9cd4dcedd9d8848930bc8adcda81adb82b1d7b94421cf61b7ed6a4b092
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-09-08
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at bradgessler@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in nocheckout.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "standard", "~> 1.3"
13
+
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nocheckout (0.1.0)
5
+ stripe (>= 7.0)
6
+ zeitwerk (~> 2.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ diff-lcs (1.5.0)
13
+ json (2.6.3)
14
+ language_server-protocol (3.17.0.3)
15
+ lint_roller (1.1.0)
16
+ parallel (1.23.0)
17
+ parser (3.2.2.3)
18
+ ast (~> 2.4.1)
19
+ racc
20
+ racc (1.7.1)
21
+ rainbow (3.1.1)
22
+ rake (13.0.6)
23
+ regexp_parser (2.8.1)
24
+ rexml (3.2.6)
25
+ rspec (3.12.0)
26
+ rspec-core (~> 3.12.0)
27
+ rspec-expectations (~> 3.12.0)
28
+ rspec-mocks (~> 3.12.0)
29
+ rspec-core (3.12.2)
30
+ rspec-support (~> 3.12.0)
31
+ rspec-expectations (3.12.3)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.12.0)
34
+ rspec-mocks (3.12.6)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.12.0)
37
+ rspec-support (3.12.1)
38
+ rubocop (1.52.1)
39
+ json (~> 2.3)
40
+ parallel (~> 1.10)
41
+ parser (>= 3.2.2.3)
42
+ rainbow (>= 2.2.2, < 4.0)
43
+ regexp_parser (>= 1.8, < 3.0)
44
+ rexml (>= 3.2.5, < 4.0)
45
+ rubocop-ast (>= 1.28.0, < 2.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (>= 2.4.0, < 3.0)
48
+ rubocop-ast (1.29.0)
49
+ parser (>= 3.2.1.0)
50
+ rubocop-performance (1.18.0)
51
+ rubocop (>= 1.7.0, < 2.0)
52
+ rubocop-ast (>= 0.4.0)
53
+ ruby-progressbar (1.13.0)
54
+ standard (1.30.1)
55
+ language_server-protocol (~> 3.17.0.2)
56
+ lint_roller (~> 1.0)
57
+ rubocop (~> 1.52.0)
58
+ standard-custom (~> 1.0.0)
59
+ standard-performance (~> 1.1.0)
60
+ standard-custom (1.0.2)
61
+ lint_roller (~> 1.0)
62
+ rubocop (~> 1.50)
63
+ standard-performance (1.1.2)
64
+ lint_roller (~> 1.1)
65
+ rubocop-performance (~> 1.18.0)
66
+ stripe (9.2.0)
67
+ unicode-display_width (2.4.2)
68
+ zeitwerk (2.6.11)
69
+
70
+ PLATFORMS
71
+ arm64-darwin-22
72
+ x86_64-linux
73
+
74
+ DEPENDENCIES
75
+ nocheckout!
76
+ rake (~> 13.0)
77
+ rspec (~> 3.0)
78
+ standard (~> 1.3)
79
+
80
+ BUNDLED WITH
81
+ 2.4.8
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Brad Gessler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # NoCheckout
2
+
3
+ NoCheckout is a set of Rails controllers that does the least amount possible to integrate with Stripe. That might sound lazy at first, but when you read between the lines it means less stuff you have to maintain and less stuff that breaks.
4
+
5
+ How does it do the least amount possible? It sends your users down the [Stripe Checkout](https://stripe.com/docs/api/checkout/sessions) path for buying stuff, then sends them back to your site. There's also a StripeWebhooks controller that handles Stripe's callbacks.
6
+
7
+ That's it! You don't even have to include the `stripe.js` file on your website, which means your users get a faster more private browsing session.
8
+
9
+ ## Installation
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add nocheckout
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install nocheckout
18
+
19
+ ## Usage
20
+
21
+ This library comes with two controllers, both map closely to their respective Stripe docs.
22
+
23
+ ### Webhooks Controller
24
+
25
+ [Stripe Webhooks](https://stripe.com/docs/webhooks) are extensive and keep your application up-to-date with what Stripe sees. In this example, we'll look at how to handle a subscriptioh that's expiring to update a User record in our database.
26
+
27
+ ```ruby
28
+ class StripesController < NoCheckout::Stripe::WebhooksController
29
+ STRIPE_SIGNING_SECRET = ENV["STRIPE_SIGNING_SECRET"]
30
+
31
+ protected
32
+
33
+ def customer_subscription_created
34
+ user.subscription_expires_at data.current_period_end
35
+ end
36
+
37
+ def customer_subscription_updated
38
+ user.subscription_expires_at data.current_period_end
39
+ end
40
+
41
+ def customer_subscription_deleted
42
+ user.subscription_expires_at Time.now
43
+ end
44
+
45
+ def user
46
+ @user ||= User.find data.customer
47
+ end
48
+ end
49
+ ```
50
+
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
+ ## Development
85
+
86
+ 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.
87
+
88
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/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/[USERNAME]/nocheckout/blob/main/CODE_OF_CONDUCT.md).
93
+
94
+ ## License
95
+
96
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
97
+
98
+ ## Code of Conduct
99
+
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/[USERNAME]/nocheckout/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
@@ -0,0 +1,81 @@
1
+ module NoCheckout
2
+ class Stripe::WebhooksController < WebhooksController
3
+ STRIPE_SIGNING_SECRET = ENV["STRIPE_SIGNING_SECRET"]
4
+
5
+ rescue_from JSON::ParserError, with: :invalid_payload
6
+ rescue_from Stripe::SignatureVerificationError, with: :signature_verification_failure
7
+
8
+ def customer_subscription_created
9
+ end
10
+
11
+ def customer_subscription_updated
12
+ end
13
+
14
+ def customer_subscription_deleted
15
+ end
16
+
17
+ def customer_subscription_trial_will_end
18
+ end
19
+
20
+ def customer_source_created
21
+ end
22
+
23
+ def customer_updated
24
+ end
25
+
26
+ def invoice_finalized
27
+ end
28
+
29
+ def invoice_created
30
+ end
31
+
32
+ def invoice_paid
33
+ end
34
+
35
+ def invoiceitem_created
36
+ end
37
+
38
+ def invoiceitem_updated
39
+ end
40
+
41
+ def payment_intent_created
42
+ end
43
+
44
+ def payment_intent_succeeded
45
+ end
46
+
47
+ def invoice_payment_succeeded
48
+ end
49
+
50
+ private
51
+ def event
52
+ @event ||= Stripe::Webhook.construct_event(request.body.read, stripe_signature, stripe_signing_secret)
53
+ end
54
+
55
+ def data
56
+ event.data.object
57
+ end
58
+
59
+ def method_name
60
+ event.type.gsub(".", "_")
61
+ end
62
+
63
+ def stripe_signature
64
+ request.env.fetch("HTTP_STRIPE_SIGNATURE")
65
+ end
66
+
67
+ def stripe_signing_secret
68
+ self.class::STRIPE_SIGNING_SECRET
69
+ end
70
+
71
+ def invalid_payload
72
+ logger.error "Could not parse webhook payload."
73
+ head :bad_request
74
+ end
75
+
76
+ def signature_verification_failure
77
+ logger.error "Webhook signature verification failed."
78
+ head :bad_request
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,42 @@
1
+ module NoCheckout
2
+ class WebhooksController < ActionController::Base
3
+ skip_before_action :verify_authenticity_token
4
+
5
+ # Raised when a method is not implemented on the webhook
6
+ # that's needed to handle the hook.
7
+ UnhandledWebhookError = Class.new(RuntimeError)
8
+
9
+ rescue_from UnhandledWebhookError, with: :unhandled_webhook
10
+
11
+ def create
12
+ dispatch_webhook
13
+ head :no_content
14
+ end
15
+
16
+ private
17
+ def dispatch_webhook
18
+ logger.info "Webhook dispatching #{method_name.inspect}"
19
+ if webhook_method_exists?
20
+ public_send method_name
21
+ else
22
+ raise UnhandledWebhookError, "Webhook method #{method_name.inspect} does not exist"
23
+ end
24
+ end
25
+
26
+ def method_name
27
+ raise NotImplementedError
28
+ end
29
+
30
+ def webhook_methods
31
+ public_methods(false)
32
+ end
33
+
34
+ def webhook_method_exists?
35
+ webhook_methods.include? method_name.to_sym
36
+ end
37
+
38
+ def unhandled_webhook
39
+ head :bad_request
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,6 @@
1
+ require "nopassword"
2
+
3
+ module NoCheckout
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NoCheckout
4
+ VERSION = "0.1.0"
5
+ end
data/lib/nocheckout.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "nocheckout/version"
4
+ require "zeitwerk"
5
+
6
+ module NoCheckout
7
+ Loader = Zeitwerk::Loader.for_gem.tap do |loader|
8
+ loader.ignore "#{__dir__}/generators"
9
+ loader.inflector.inflect "nocheckout" => "NoCheckout"
10
+ loader.setup
11
+ end
12
+
13
+ class Error < StandardError; end
14
+ end
@@ -0,0 +1,4 @@
1
+ module NoCheckout
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nocheckout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brad Gessler
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: zeitwerk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: stripe
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '7.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '7.0'
41
+ description: Rails controllers for Stripe Checkout Sessions and Webhooks
42
+ email:
43
+ - bradgessler@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - ".standard.yml"
50
+ - CHANGELOG.md
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - app/controllers/nocheckout/stripe/webhooks_controller.rb
58
+ - app/controllers/nocheckout/webhooks_controller.rb
59
+ - lib/nocheckout.rb
60
+ - lib/nocheckout/engine.rb
61
+ - lib/nocheckout/version.rb
62
+ - sig/nocheckout.rbs
63
+ homepage: https://github.com/rubymonolith/nocheckout
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ allowed_push_host: https://rubygems.org/
68
+ homepage_uri: https://github.com/rubymonolith/nocheckout
69
+ source_code_uri: https://github.com/rubymonolith/nocheckout
70
+ changelog_uri: https://github.com/rubymonolith/nocheckout
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.6.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.4.6
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Rails controllers for Stripe Checkout Sessions and Webhooks
90
+ test_files: []