bullet_train-integrations-stripe 1.0.0 → 1.0.3
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/app/models/concerns/integrations/stripe_installations/base.rb +25 -0
- data/app/models/concerns/oauth/stripe_accounts/base.rb +48 -0
- data/app/models/concerns/webhooks/incoming/oauth/stripe_account_webhooks/base.rb +37 -0
- data/app/models/integrations/stripe_installation.rb +2 -24
- data/app/models/integrations.rb +5 -0
- data/app/models/oauth/stripe_account.rb +1 -51
- data/app/models/oauth.rb +5 -0
- data/app/models/webhooks/incoming/oauth/stripe_account_webhook.rb +1 -31
- data/app/models/webhooks/incoming/oauth.rb +5 -0
- data/app/models/webhooks/incoming.rb +5 -0
- data/app/models/webhooks.rb +5 -0
- data/lib/bullet_train/integrations/stripe/version.rb +1 -1
- data/lib/bullet_train/integrations/stripe.rb +8 -0
- metadata +68 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d551423739ff79d107af342581c998d3ce4a535f5dfc73bd6526cd3e16a72f3f
|
4
|
+
data.tar.gz: a175914574e7da1ee6f51ebf633633b233161fa68b28c3c89377654e6cb8ecdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1525401dcf27fd7ba5d51f62cb7da99b12557ab9b8f4dbd6844254ef1dcb4e17eb5c8d5be1d9471ea0cc59020b66716a95641c6a93b27f0eb60273e4aff402dc
|
7
|
+
data.tar.gz: bbb42ebddcc49c0291fa85a7a1bdde9a43af58b8a518aca52cd4ea3b6223c6b6aaadc2dac5434269b1abd5a5059a3908d015216b54bbaf281a32decec47f536f
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Integrations::StripeInstallations::Base
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
# 🚅 add concerns above.
|
4
|
+
|
5
|
+
included do
|
6
|
+
belongs_to :team
|
7
|
+
belongs_to :oauth_stripe_account, class_name: "Oauth::StripeAccount"
|
8
|
+
# 🚅 add belongs_to associations above.
|
9
|
+
|
10
|
+
# 🚅 add has_many associations above.
|
11
|
+
|
12
|
+
# 🚅 add has_one associations above.
|
13
|
+
|
14
|
+
# 🚅 add scopes above.
|
15
|
+
|
16
|
+
validates :name, presence: true
|
17
|
+
# 🚅 add validations above.
|
18
|
+
|
19
|
+
# 🚅 add callbacks above.
|
20
|
+
|
21
|
+
# 🚅 add delegations above.
|
22
|
+
end
|
23
|
+
|
24
|
+
# 🚅 add methods above.
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Oauth::StripeAccounts::Base
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
# 🚅 add concerns above.
|
4
|
+
|
5
|
+
included do
|
6
|
+
belongs_to :user, optional: true
|
7
|
+
# 🚅 add belongs_to associations above.
|
8
|
+
|
9
|
+
has_many :webhooks_incoming_oauth_stripe_account_webhooks, class_name: "Webhooks::Incoming::Oauth::StripeAccountWebhook", foreign_key: "oauth_stripe_account_id"
|
10
|
+
has_many :integrations_stripe_installations, class_name: "Integrations::StripeInstallation", foreign_key: "oauth_stripe_account_id"
|
11
|
+
# 🚅 add has_many associations above.
|
12
|
+
|
13
|
+
# 🚅 add has_one associations above.
|
14
|
+
|
15
|
+
# 🚅 add scopes above.
|
16
|
+
|
17
|
+
validates :uid, presence: true
|
18
|
+
# 🚅 add validations above.
|
19
|
+
|
20
|
+
# 🚅 add callbacks above.
|
21
|
+
|
22
|
+
# 🚅 add delegations above.
|
23
|
+
end
|
24
|
+
|
25
|
+
def label_string
|
26
|
+
name
|
27
|
+
end
|
28
|
+
|
29
|
+
# TODO You should update this with an implementation appropriate for the provider you're integrating with.
|
30
|
+
# This must return _something_, otherwise new installations won't save.
|
31
|
+
def name
|
32
|
+
data.dig("info", "name").presence || "Stripe Account"
|
33
|
+
rescue
|
34
|
+
"Stripe Account"
|
35
|
+
end
|
36
|
+
|
37
|
+
def name_was
|
38
|
+
name
|
39
|
+
end
|
40
|
+
|
41
|
+
def update_from_oauth(auth)
|
42
|
+
self.uid = auth.uid
|
43
|
+
self.data = auth
|
44
|
+
save
|
45
|
+
end
|
46
|
+
|
47
|
+
# 🚅 add methods above.
|
48
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Webhooks::Incoming::Oauth::StripeAccountWebhooks::Base
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
include Webhooks::Incoming::Webhook
|
6
|
+
|
7
|
+
belongs_to :oauth_stripe_account, class_name: "Oauth::StripeAccount", optional: true
|
8
|
+
end
|
9
|
+
|
10
|
+
def process
|
11
|
+
# if this is a stripe connect webhook ..
|
12
|
+
if data["account"]
|
13
|
+
|
14
|
+
# if we're able to find an account in our system that this webhook should be routed to ..
|
15
|
+
if (self.oauth_stripe_account = Oauth::StripeAccount.find_by(uid: data["account"]))
|
16
|
+
|
17
|
+
# save the reference to the account.
|
18
|
+
save
|
19
|
+
|
20
|
+
# delegate processing to that account.
|
21
|
+
oauth_stripe_account.process_webhook(self)
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
# if we didn't find an account for the webhook, they've probably deleted their account. we'll just ignore it for
|
26
|
+
# now, but it's still in our database for debugging purposes. we'll probably want to send a request to stripe
|
27
|
+
# in order to disconnect their account from our application so we stop receiving webhooks.
|
28
|
+
|
29
|
+
else
|
30
|
+
|
31
|
+
# it's possible we're receiving a general webhook that isn't specific to an account.
|
32
|
+
# however, we want to know about these, so raise an error.
|
33
|
+
raise "received a webhook we weren't expecting"
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,29 +1,7 @@
|
|
1
1
|
class Integrations::StripeInstallation < ApplicationRecord
|
2
|
-
|
3
|
-
|
4
|
-
belongs_to :team
|
5
|
-
belongs_to :oauth_stripe_account, class_name: "Oauth::StripeAccount"
|
6
|
-
# 🚅 add belongs_to associations above.
|
7
|
-
|
8
|
-
# 🚅 add has_many associations above.
|
9
|
-
|
10
|
-
# 🚅 add has_one associations above.
|
11
|
-
|
12
|
-
# 🚅 add scopes above.
|
13
|
-
|
14
|
-
validates :name, presence: true
|
15
|
-
# 🚅 add validations above.
|
16
|
-
|
17
|
-
# 🚅 add callbacks above.
|
18
|
-
|
19
|
-
# 🚅 add delegations above.
|
2
|
+
include Integrations::StripeInstallations::Base
|
20
3
|
|
21
4
|
def process_webhook(webhook)
|
22
|
-
|
23
|
-
# errors on the web where they see a red screen of death. instead, sidekiq will reattempt the processing of the
|
24
|
-
# entire webhook, which means that earlier portions of your logic will be run more than once unless you're careful
|
25
|
-
# to avoid it.
|
5
|
+
raise "You should implement a `Integrations::StripeInstallation` model in your application that has `include Integrations::StripeInstallations::Base` and implements a `def process_webhook(webhook)` method."
|
26
6
|
end
|
27
|
-
|
28
|
-
# 🚅 add methods above.
|
29
7
|
end
|
@@ -1,53 +1,3 @@
|
|
1
1
|
class Oauth::StripeAccount < ApplicationRecord
|
2
|
-
|
3
|
-
|
4
|
-
belongs_to :user, optional: true
|
5
|
-
# 🚅 add belongs_to associations above.
|
6
|
-
|
7
|
-
has_many :webhooks_incoming_oauth_stripe_account_webhooks, class_name: "Webhooks::Incoming::Oauth::StripeAccountWebhook", foreign_key: "oauth_stripe_account_id"
|
8
|
-
has_many :integrations_stripe_installations, class_name: "Integrations::StripeInstallation", foreign_key: "oauth_stripe_account_id"
|
9
|
-
# 🚅 add has_many associations above.
|
10
|
-
|
11
|
-
# 🚅 add has_one associations above.
|
12
|
-
|
13
|
-
# 🚅 add scopes above.
|
14
|
-
|
15
|
-
validates :uid, presence: true
|
16
|
-
# 🚅 add validations above.
|
17
|
-
|
18
|
-
# 🚅 add callbacks above.
|
19
|
-
|
20
|
-
# 🚅 add delegations above.
|
21
|
-
|
22
|
-
def label_string
|
23
|
-
name
|
24
|
-
end
|
25
|
-
|
26
|
-
# TODO You should update this with an implementation appropriate for the provider you're integrating with.
|
27
|
-
# This must return _something_, otherwise new installations won't save.
|
28
|
-
def name
|
29
|
-
data.dig("info", "name").presence || "Stripe Account"
|
30
|
-
rescue
|
31
|
-
"Stripe Account"
|
32
|
-
end
|
33
|
-
|
34
|
-
def name_was
|
35
|
-
name
|
36
|
-
end
|
37
|
-
|
38
|
-
def update_from_oauth(auth)
|
39
|
-
self.uid = auth.uid
|
40
|
-
self.data = auth
|
41
|
-
save
|
42
|
-
end
|
43
|
-
|
44
|
-
# webhooks received for this account will be routed here asynchronously for processing on a worker.
|
45
|
-
def process_webhook(webhook)
|
46
|
-
# we delegate processing to any active installations.
|
47
|
-
integrations_stripe_installations.order(:id).each do |installation|
|
48
|
-
installation.process_webhook(webhook)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# 🚅 add methods above.
|
2
|
+
include Oauth::StripeAccounts::Base
|
53
3
|
end
|
data/app/models/oauth.rb
ADDED
@@ -1,33 +1,3 @@
|
|
1
1
|
class Webhooks::Incoming::Oauth::StripeAccountWebhook < ApplicationRecord
|
2
|
-
include Webhooks::Incoming::
|
3
|
-
|
4
|
-
belongs_to :oauth_stripe_account, class_name: "Oauth::StripeAccount", optional: true
|
5
|
-
|
6
|
-
def process
|
7
|
-
# if this is a stripe connect webhook ..
|
8
|
-
if data["account"]
|
9
|
-
|
10
|
-
# if we're able to find an account in our system that this webhook should be routed to ..
|
11
|
-
if (self.oauth_stripe_account = Oauth::StripeAccount.find_by(uid: data["account"]))
|
12
|
-
|
13
|
-
# save the reference to the account.
|
14
|
-
save
|
15
|
-
|
16
|
-
# delegate processing to that account.
|
17
|
-
oauth_stripe_account.process_webhook(self)
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
# if we didn't find an account for the webhook, they've probably deleted their account. we'll just ignore it for
|
22
|
-
# now, but it's still in our database for debugging purposes. we'll probably want to send a request to stripe
|
23
|
-
# in order to disconnect their account from our application so we stop receiving webhooks.
|
24
|
-
|
25
|
-
else
|
26
|
-
|
27
|
-
# it's possible we're receiving a general webhook that isn't specific to an account.
|
28
|
-
# however, we want to know about these, so raise an error.
|
29
|
-
raise "received a webhook we weren't expecting"
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
2
|
+
include Webhooks::Incoming::Oauth::StripeAccountWebhooks::Base
|
33
3
|
end
|
@@ -1,6 +1,14 @@
|
|
1
1
|
require "bullet_train/integrations/stripe/version"
|
2
2
|
require "bullet_train/integrations/stripe/engine"
|
3
3
|
|
4
|
+
require "stripe"
|
5
|
+
require "omniauth"
|
6
|
+
require "omniauth-stripe-connect"
|
7
|
+
|
8
|
+
# TODO Remove when we're able to properly upgrade Omniauth.
|
9
|
+
# https://github.com/omniauth/omniauth/wiki/Resolving-CVE-2015-9284
|
10
|
+
require "omniauth/rails_csrf_protection"
|
11
|
+
|
4
12
|
module BulletTrain
|
5
13
|
module Integrations
|
6
14
|
module Stripe
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train-integrations-stripe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,70 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.0.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: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: omniauth
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: omniauth-stripe-connect
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: omniauth-rails_csrf_protection
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
27
83
|
description: Example Stripe platform integration for Bullet Train applications.
|
28
84
|
email:
|
29
85
|
- andrew.culver@gmail.com
|
@@ -38,8 +94,16 @@ files:
|
|
38
94
|
- app/controllers/account/integrations/stripe_installations_controller.rb
|
39
95
|
- app/controllers/account/oauth/stripe_accounts_controller.rb
|
40
96
|
- app/controllers/webhooks/incoming/oauth/stripe_account_webhooks_controller.rb
|
97
|
+
- app/models/concerns/integrations/stripe_installations/base.rb
|
98
|
+
- app/models/concerns/oauth/stripe_accounts/base.rb
|
99
|
+
- app/models/concerns/webhooks/incoming/oauth/stripe_account_webhooks/base.rb
|
100
|
+
- app/models/integrations.rb
|
41
101
|
- app/models/integrations/stripe_installation.rb
|
102
|
+
- app/models/oauth.rb
|
42
103
|
- app/models/oauth/stripe_account.rb
|
104
|
+
- app/models/webhooks.rb
|
105
|
+
- app/models/webhooks/incoming.rb
|
106
|
+
- app/models/webhooks/incoming/oauth.rb
|
43
107
|
- app/models/webhooks/incoming/oauth/stripe_account_webhook.rb
|
44
108
|
- app/views/account/integrations/stripe_installations/_breadcrumbs.html.erb
|
45
109
|
- app/views/account/integrations/stripe_installations/_form.html.erb
|