slack-ruby-bot-server-stripe 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +18 -0
  5. data/.rubocop_todo.yml +29 -0
  6. data/.travis.yml +29 -0
  7. data/CHANGELOG.md +5 -0
  8. data/CONTRIBUTING.md +125 -0
  9. data/Dangerfile +1 -0
  10. data/Gemfile +42 -0
  11. data/LICENSE +21 -0
  12. data/README.md +278 -0
  13. data/RELEASING.md +61 -0
  14. data/Rakefile +14 -0
  15. data/lib/slack-ruby-bot-server-stripe.rb +15 -0
  16. data/lib/slack-ruby-bot-server-stripe/api.rb +1 -0
  17. data/lib/slack-ruby-bot-server-stripe/api/endpoints.rb +1 -0
  18. data/lib/slack-ruby-bot-server-stripe/api/endpoints/subscriptions_endpoint.rb +44 -0
  19. data/lib/slack-ruby-bot-server-stripe/commands.rb +2 -0
  20. data/lib/slack-ruby-bot-server-stripe/commands/subscription.rb +14 -0
  21. data/lib/slack-ruby-bot-server-stripe/commands/unsubscribe.rb +34 -0
  22. data/lib/slack-ruby-bot-server-stripe/config.rb +41 -0
  23. data/lib/slack-ruby-bot-server-stripe/errors.rb +10 -0
  24. data/lib/slack-ruby-bot-server-stripe/lifecycle.rb +17 -0
  25. data/lib/slack-ruby-bot-server-stripe/models.rb +2 -0
  26. data/lib/slack-ruby-bot-server-stripe/models/activerecord.rb +18 -0
  27. data/lib/slack-ruby-bot-server-stripe/models/methods.rb +317 -0
  28. data/lib/slack-ruby-bot-server-stripe/models/mongoid.rb +27 -0
  29. data/lib/slack-ruby-bot-server-stripe/public/img/icon.png +0 -0
  30. data/lib/slack-ruby-bot-server-stripe/public/img/stripe.png +0 -0
  31. data/lib/slack-ruby-bot-server-stripe/public/subscribe.html.erb +99 -0
  32. data/lib/slack-ruby-bot-server-stripe/version.rb +5 -0
  33. data/lib/slack-ruby-bot-server/api.rb +2 -0
  34. data/lib/slack-ruby-bot-server/api/endpoints.rb +9 -0
  35. data/lib/slack-ruby-bot-server/api/presenters.rb +2 -0
  36. data/lib/slack-ruby-bot-server/api/presenters/root_presenter.rb +11 -0
  37. data/lib/slack-ruby-bot-server/api/presenters/team_presenter.rb +10 -0
  38. data/slack-ruby-bot-server-stripe.gemspec +19 -0
  39. metadata +107 -0
@@ -0,0 +1,27 @@
1
+ require_relative 'methods'
2
+
3
+ module SlackRubyBotServer
4
+ module Stripe
5
+ module Models
6
+ module Mongoid
7
+ extend ActiveSupport::Concern
8
+ include Methods
9
+
10
+ included do
11
+ field :stripe_customer_id, type: String
12
+ field :subscribed, type: Boolean, default: false
13
+ field :subscribed_at, type: DateTime
14
+ field :subscription_expired_at, type: DateTime
15
+ field :trial_informed_at, type: DateTime
16
+ field :subscription_past_due_at, type: DateTime
17
+ field :subscription_past_due_informed_at, type: DateTime
18
+
19
+ scope :striped, -> { where(subscribed: true, :stripe_customer_id.ne => nil) }
20
+ scope :trials, -> { where(subscribed: false) }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ Team.include SlackRubyBotServer::Stripe::Models::Mongoid
@@ -0,0 +1,99 @@
1
+ <html>
2
+ <head>
3
+ <title>Slack Ruby Bot Server (Stripe): Subscribe</title>
4
+ <script src="/scripts/jquery-1.7.1.min.js"></script>
5
+ <script src="/scripts/url.min.js"></script>
6
+ <script src="/scripts/messages.js"></script>
7
+ <script src='https://checkout.stripe.com/checkout.js'></script>
8
+ <% team = Team.where(team_id: request['team_id']).first %>
9
+ </head>
10
+ <body style="text-align: center">
11
+ <p>
12
+ <img src='img/slack.png' width="120px">
13
+ </p>
14
+ <p id='messages' />
15
+ <p id='subscribe'>
16
+ <form action="" method="POST">
17
+ <script
18
+ src="https://checkout.stripe.com/checkout.js"
19
+ class="stripe-button"
20
+ data-key="<%= SlackRubyBotServer::Stripe.config.stripe_api_publishable_key %>"
21
+ data-image='/img/icon.png'
22
+ data-label='<%= team && team.subscribed? ? "Update Credit Card" : "Pay With Card" %>'
23
+ data-locale="auto">
24
+ </script>
25
+ </form>
26
+ <p>
27
+ <img src='/img/stripe.png' width='119' height='26'></img>
28
+ </p>
29
+ <script>
30
+ $(document).ready(function() {
31
+
32
+ var team = {
33
+ id: '<%= team && team.team_id %>',
34
+ name: '<%= team && team.name %>',
35
+ subscribed: <%= !!(team && team.subscribed) %>,
36
+ }
37
+
38
+ if (team.subscribed) {
39
+ SlackRubyBotServer.message('Update credit card for team <b>' + team.name + '</b>.');
40
+ } else if (team.id && team.name) {
41
+ <% subscription_plan_amount_s = '%.2f' % (SlackRubyBotServer::Stripe.config.subscription_plan_amount.to_f / 100) %>
42
+ SlackRubyBotServer.message('Subscribe team <b>' + team.name + '</b> for $<%= subscription_plan_amount_s %> a year.');
43
+ } else {
44
+ // $('.stripe-button-el').remove();
45
+ SlackRubyBotServer.message('Missing or invalid team ID.');
46
+ }
47
+
48
+ var handler = StripeCheckout.configure({
49
+ key: '<%= SlackRubyBotServer::Stripe.config.stripe_api_publishable_key %>',
50
+ image: '/img/icon.png',
51
+ locale: 'auto',
52
+ allowRememberMe: false,
53
+ token: function(token) {
54
+ $.ajax({
55
+ type: 'POST',
56
+ url: '/api/subscriptions',
57
+ data: {
58
+ stripe_email: token.email,
59
+ stripe_token: token.id,
60
+ stripe_token_type: token.type,
61
+ team_id: team.id
62
+ },
63
+ success: function(data) {
64
+ if (team.subscribed) {
65
+ SlackRubyBotServer.message('Credit card for team <b>' + team.name + '</b> successfully updated.');
66
+ } else {
67
+ SlackRubyBotServer.message('Team <b>' + team.name + '</b> successfully subscribed.');
68
+ }
69
+ $('.stripe-button-el').remove();
70
+ },
71
+ error: SlackRubyBotServer.error
72
+ });
73
+ }
74
+ });
75
+
76
+ $('.stripe-button-el').on('click', function(e) {
77
+ var amount = <%= SlackRubyBotServer::Stripe.config.subscription_plan_amount %>;
78
+ handler.open({
79
+ name: '<%= SlackRubyBotServer::Stripe.config.subscription_plan_id %>',
80
+ description: 'Subscription',
81
+ amount: amount
82
+ });
83
+ e.preventDefault();
84
+ });
85
+
86
+ $(window).on('popstate', function() {
87
+ handler.close();
88
+ });
89
+ });
90
+
91
+ </script>
92
+ </p>
93
+ <p>
94
+ <small>
95
+ made by <a href="https://twitter.com/dblockdotorg" target="_blank">@dblockdotorg</a>, <a href="https://github.com/slack-ruby/slack-ruby-bot-server-stripe" target="_blank">fork me on github</a>
96
+ </small>
97
+ </p>
98
+ </body>
99
+ </html>
@@ -0,0 +1,5 @@
1
+ module SlackRubyBotServer
2
+ module Stripe
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'api/presenters'
2
+ require_relative 'api/endpoints'
@@ -0,0 +1,9 @@
1
+ module SlackRubyBotServer
2
+ module Api
3
+ module Endpoints
4
+ class RootEndpoint
5
+ mount SlackRubyBotServer::Stripe::Api::Endpoints::SubscriptionsEndpoint
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'presenters/root_presenter'
2
+ require_relative 'presenters/team_presenter'
@@ -0,0 +1,11 @@
1
+ module SlackRubyBotServer
2
+ module Api
3
+ module Presenters
4
+ module RootPresenter
5
+ link :subscriptions do |opts|
6
+ "#{base_url(opts)}/api/subscriptions"
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module SlackRubyBotServer
2
+ module Api
3
+ module Presenters
4
+ module TeamPresenter
5
+ property :subscribed, type: Boolean, desc: 'Team is a paid subscriber.'
6
+ property :subscribed_at, type: DateTime, desc: 'Date/time when a subscription was purchased.'
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'slack-ruby-bot-server-stripe/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'slack-ruby-bot-server-stripe'
7
+ spec.version = SlackRubyBotServer::Stripe::VERSION
8
+ spec.authors = ['Daniel Doubrovkine']
9
+ spec.email = ['dblock@dblock.org']
10
+
11
+ spec.summary = 'Stripe extension for slack-ruby-bot-server.'
12
+ spec.homepage = 'https://github.com/slack-ruby/slack-ruby-bot-server-stripe'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
15
+ spec.require_paths = ['lib']
16
+
17
+ spec.add_dependency 'slack-ruby-bot-server', '>= 0.12.0'
18
+ spec.add_dependency 'stripe', '~> 1.58.0'
19
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slack-ruby-bot-server-stripe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Doubrovkine
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slack-ruby-bot-server
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.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: 1.58.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.58.0
41
+ description:
42
+ email:
43
+ - dblock@dblock.org
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - ".rubocop_todo.yml"
52
+ - ".travis.yml"
53
+ - CHANGELOG.md
54
+ - CONTRIBUTING.md
55
+ - Dangerfile
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - RELEASING.md
60
+ - Rakefile
61
+ - lib/slack-ruby-bot-server-stripe.rb
62
+ - lib/slack-ruby-bot-server-stripe/api.rb
63
+ - lib/slack-ruby-bot-server-stripe/api/endpoints.rb
64
+ - lib/slack-ruby-bot-server-stripe/api/endpoints/subscriptions_endpoint.rb
65
+ - lib/slack-ruby-bot-server-stripe/commands.rb
66
+ - lib/slack-ruby-bot-server-stripe/commands/subscription.rb
67
+ - lib/slack-ruby-bot-server-stripe/commands/unsubscribe.rb
68
+ - lib/slack-ruby-bot-server-stripe/config.rb
69
+ - lib/slack-ruby-bot-server-stripe/errors.rb
70
+ - lib/slack-ruby-bot-server-stripe/lifecycle.rb
71
+ - lib/slack-ruby-bot-server-stripe/models.rb
72
+ - lib/slack-ruby-bot-server-stripe/models/activerecord.rb
73
+ - lib/slack-ruby-bot-server-stripe/models/methods.rb
74
+ - lib/slack-ruby-bot-server-stripe/models/mongoid.rb
75
+ - lib/slack-ruby-bot-server-stripe/public/img/icon.png
76
+ - lib/slack-ruby-bot-server-stripe/public/img/stripe.png
77
+ - lib/slack-ruby-bot-server-stripe/public/subscribe.html.erb
78
+ - lib/slack-ruby-bot-server-stripe/version.rb
79
+ - lib/slack-ruby-bot-server/api.rb
80
+ - lib/slack-ruby-bot-server/api/endpoints.rb
81
+ - lib/slack-ruby-bot-server/api/presenters.rb
82
+ - lib/slack-ruby-bot-server/api/presenters/root_presenter.rb
83
+ - lib/slack-ruby-bot-server/api/presenters/team_presenter.rb
84
+ - slack-ruby-bot-server-stripe.gemspec
85
+ homepage: https://github.com/slack-ruby/slack-ruby-bot-server-stripe
86
+ licenses: []
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: '0'
102
+ requirements: []
103
+ rubygems_version: 3.0.3
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Stripe extension for slack-ruby-bot-server.
107
+ test_files: []