rhino_project_subscriptions 0.20.0.beta.22
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +28 -0
- data/Rakefile +34 -0
- data/app/assets/config/rhino_subscriptions_manifest.js +0 -0
- data/app/controllers/rhino/stripe_controller.rb +101 -0
- data/app/models/rhino/stripe_customer.rb +8 -0
- data/app/policies/stripe_policy.rb +12 -0
- data/config/routes.rb +12 -0
- data/config/stripe.rb +6 -0
- data/db/migrate/20210302208003_rhino_create_stripe_customers.rb +12 -0
- data/db/migrate/20210302299092_rhino_alter_stripe_customers.rb +7 -0
- data/lib/generators/rhino_subscriptions/install/install_generator.rb +12 -0
- data/lib/rhino_project_subscriptions.rb +8 -0
- data/lib/rhino_subscriptions/engine.rb +20 -0
- data/lib/rhino_subscriptions/version.rb +17 -0
- data/lib/tasks/rhino_subscriptions.rake +15 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 02b2d359cccefcfbdcc3b7b6ac6fa1778bd519d1bd6737cc5c28facf98abee40
|
4
|
+
data.tar.gz: 600f1c98f66cbb6725197cf027b0ee9ae078da483b84271ed2072e1e3e62f445
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b5bc3616717cfd19c9d99f269253fcf2c9aedeca054551a1e087ad7423d900aaff8c34b8eb23534c33322abc29d5d4808806c6c8d944e0fb5938c9fa195f43f
|
7
|
+
data.tar.gz: 79b8798c411eced462c504447de357f12ab66be659738ca422129291088cfe7f87452b693152d0c03302ec9961cce9a306a165b1240375a382360ff08b910582
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020-present Nubinary, Inc.
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# RhinoSubscriptions
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'rhino_subscriptions'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install rhino_subscriptions
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
task :package
|
10
|
+
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.rdoc_dir = 'rdoc'
|
13
|
+
rdoc.title = 'RhinoSubscriptions'
|
14
|
+
rdoc.options << '--line-numbers'
|
15
|
+
rdoc.rdoc_files.include('README.md')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
20
|
+
load 'rails/tasks/engine.rake'
|
21
|
+
|
22
|
+
load 'rails/tasks/statistics.rake'
|
23
|
+
|
24
|
+
require 'bundler/gem_tasks'
|
25
|
+
|
26
|
+
require 'rake/testtask'
|
27
|
+
|
28
|
+
Rake::TestTask.new(:test) do |t|
|
29
|
+
t.libs << 'test'
|
30
|
+
t.pattern = 'test/**/*_test.rb'
|
31
|
+
t.verbose = false
|
32
|
+
end
|
33
|
+
|
34
|
+
task default: :test
|
File without changes
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "stripe"
|
4
|
+
require "rhino/stripe_customer"
|
5
|
+
|
6
|
+
::Stripe.api_key = ENV["STRIPE_SECRET_KEY"]
|
7
|
+
|
8
|
+
module Rhino
|
9
|
+
class StripeController < Rhino::BaseController
|
10
|
+
include Rhino::Authenticated
|
11
|
+
|
12
|
+
def prices
|
13
|
+
list = ::Stripe::Price.list({ limit: 5 })
|
14
|
+
prices = list["data"].map do |column|
|
15
|
+
{ id: column["id"], name: column["nickname"], amount: column["unit_amount"] }
|
16
|
+
end
|
17
|
+
render json: {
|
18
|
+
publishableKey: ENV["STRIPE_PUBLISHABLE_KEY"],
|
19
|
+
prices:
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_checkout_session
|
24
|
+
authorize nil
|
25
|
+
sc = get_stripe_customer(params["base_owner_id"])
|
26
|
+
session = checkout_session(sc.customer_id, params)
|
27
|
+
sc.current_stripe_session_id = session.id
|
28
|
+
sc.save
|
29
|
+
|
30
|
+
render json: {
|
31
|
+
sessionId: session.id
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def customer
|
36
|
+
stripe_customer = Rhino::StripeCustomer.find_by(base_owner_id: params["base_owner_id"])
|
37
|
+
if stripe_customer
|
38
|
+
customer = ::Stripe::Customer.retrieve({
|
39
|
+
id: stripe_customer["customer_id"]
|
40
|
+
})
|
41
|
+
render json: {
|
42
|
+
customer: customer.data[0]
|
43
|
+
}
|
44
|
+
else
|
45
|
+
render json: {}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def subscriptions
|
50
|
+
stripe_customer = Rhino::StripeCustomer.find_by(base_owner_id: params["base_owner_id"])
|
51
|
+
|
52
|
+
if stripe_customer
|
53
|
+
customer = ::Stripe::Customer.retrieve({
|
54
|
+
id: stripe_customer["customer_id"],
|
55
|
+
expand: ["subscriptions"]
|
56
|
+
})
|
57
|
+
|
58
|
+
render json: {
|
59
|
+
subscriptions: customer.subscriptions.data
|
60
|
+
}
|
61
|
+
|
62
|
+
else
|
63
|
+
render json: {}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def check_session_id
|
68
|
+
stripe_customer = Rhino::StripeCustomer.find_by(base_owner_id: params["base_owner_id"])
|
69
|
+
render json: {
|
70
|
+
session_matched: ((stripe_customer && stripe_customer["current_stripe_session_id"]) == params["session_id"])
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
def checkout_session(customer_id, args)
|
76
|
+
::Stripe::Checkout::Session.create(
|
77
|
+
success_url: ENV["FRONT_END_URL"] + args["success_url"],
|
78
|
+
cancel_url: ENV["FRONT_END_URL"] + args["cancel_url"],
|
79
|
+
payment_method_types: ["card"],
|
80
|
+
mode: "subscription",
|
81
|
+
line_items: [{
|
82
|
+
quantity: 1,
|
83
|
+
price: args["price"]
|
84
|
+
}],
|
85
|
+
customer: customer_id
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_stripe_customer(_base_owner_id)
|
90
|
+
Rhino::StripeCustomer.find_or_create_by!(base_owner_id: params["base_owner_id"]) do |stripe_customer|
|
91
|
+
customer = ::Stripe::Customer.create(email: current_user.email)
|
92
|
+
stripe_customer.customer_id = customer.id
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
protected
|
97
|
+
def policy(record = nil)
|
98
|
+
StripePolicy.new(current_user, record)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
|
3
|
+
scope Rhino.namespace do
|
4
|
+
|
5
|
+
get 'subscription/prices' , to: 'rhino/stripe#prices'
|
6
|
+
post 'subscription/customer' ,to: 'rhino/stripe#customer'
|
7
|
+
get 'subscription/subscriptions' ,to: 'rhino/stripe#subscriptions'
|
8
|
+
post 'subscription/create-checkout-session' ,to: 'rhino/stripe#create_checkout_session'
|
9
|
+
get 'subscription/check_session_id' ,to: 'rhino/stripe#check_session_id'
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
data/config/stripe.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
class RhinoCreateStripeCustomers < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :stripe_customers do |t|
|
4
|
+
t.references :user, null: false, foreign_key: true
|
5
|
+
t.string :customer_id
|
6
|
+
t.string :current_stripe_session_id
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rhino/engine'
|
4
|
+
require 'active_support'
|
5
|
+
|
6
|
+
module RhinoSubscriptions
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
config.autoload_paths << File.expand_path('../../lib', __dir__)
|
9
|
+
|
10
|
+
initializer 'rhino_subscriptions.register_module' do
|
11
|
+
config.after_initialize do
|
12
|
+
if ENV['STRIPE_SECRET_KEY']
|
13
|
+
Rhino.registered_modules[:rhino_subscriptions] = {
|
14
|
+
version: RhinoSubscriptions::VERSION
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rhino
|
4
|
+
# Returns the currently loaded version of Rhino core as a +Gem::Version+.
|
5
|
+
def self.gem_version
|
6
|
+
Gem::Version.new VERSION::STRING
|
7
|
+
end
|
8
|
+
|
9
|
+
module VERSION
|
10
|
+
MAJOR = 0
|
11
|
+
MINOR = 20
|
12
|
+
TINY = 0
|
13
|
+
PRE = "beta.22"
|
14
|
+
|
15
|
+
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :rhino_subscriptions do
|
4
|
+
# Prevent migration installation task from showing up twice.
|
5
|
+
if Rake::Task.task_defined?("rhino_subscriptions_engine:install:migrations")
|
6
|
+
Rake::Task["rhino_subscriptions_engine:install:migrations"].clear_comments
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Install rhino_subscriptions"
|
10
|
+
task install: :environment do
|
11
|
+
Rake::Task["rhino_subscriptions_engine:install:migrations"].invoke if Rake::Task.task_defined?("rhino_subscriptions_engine:install:migrations")
|
12
|
+
|
13
|
+
Rails::Command.invoke :generate, ["rhino_subscriptions:install"]
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rhino_project_subscriptions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.20.0.beta.22
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- JP Rosevear
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-02-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 7.0.0
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 7.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 7.0.0
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 7.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rhino_project_core
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.20.0.beta.22
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.20.0.beta.22
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: stripe
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 5.28.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 5.28.0
|
61
|
+
description: ''
|
62
|
+
email:
|
63
|
+
- jprosevear@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- app/assets/config/rhino_subscriptions_manifest.js
|
72
|
+
- app/controllers/rhino/stripe_controller.rb
|
73
|
+
- app/models/rhino/stripe_customer.rb
|
74
|
+
- app/policies/stripe_policy.rb
|
75
|
+
- config/routes.rb
|
76
|
+
- config/stripe.rb
|
77
|
+
- db/migrate/20210302208003_rhino_create_stripe_customers.rb
|
78
|
+
- db/migrate/20210302299092_rhino_alter_stripe_customers.rb
|
79
|
+
- lib/generators/rhino_subscriptions/install/install_generator.rb
|
80
|
+
- lib/rhino_project_subscriptions.rb
|
81
|
+
- lib/rhino_subscriptions/engine.rb
|
82
|
+
- lib/rhino_subscriptions/version.rb
|
83
|
+
- lib/tasks/rhino_subscriptions.rake
|
84
|
+
homepage: ''
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.3.1
|
102
|
+
requirements: []
|
103
|
+
rubygems_version: 3.3.26
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: ''
|
107
|
+
test_files: []
|