bullet_train-integrations-stripe 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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/oauth/stripe_account.rb +1 -51
- data/app/models/webhooks/incoming/oauth/stripe_account_webhook.rb +1 -31
- data/lib/bullet_train/integrations/stripe/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6725113b0b72922229fe124a7832ee8eaa869eaed3952215915dabf0c1fd0e5
|
4
|
+
data.tar.gz: 5e576403715a63ad350964004995caba8fb74fdefe4dac40f10cd0fea9baed4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d215c921514dba70f674ce3afda981e6ecc084b817d08f8d0d400f63d8d34fe93e134d44d6ae533fde2dcd53f2cb6f33c5ebd8fa2b74362f9d645acc94f815b
|
7
|
+
data.tar.gz: 9508e0f4ffd9a2d0d9635b41d96d9ed263640aaec071e1337743fad4178d485490a87d5729551e32f86a04fe71e56ce3026fdcfd8a2046e13dc23611576c7e30
|
@@ -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
|
@@ -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
|
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.1
|
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-01-
|
11
|
+
date: 2022-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,6 +38,9 @@ files:
|
|
38
38
|
- app/controllers/account/integrations/stripe_installations_controller.rb
|
39
39
|
- app/controllers/account/oauth/stripe_accounts_controller.rb
|
40
40
|
- app/controllers/webhooks/incoming/oauth/stripe_account_webhooks_controller.rb
|
41
|
+
- app/models/concerns/integrations/stripe_installations/base.rb
|
42
|
+
- app/models/concerns/oauth/stripe_accounts/base.rb
|
43
|
+
- app/models/concerns/webhooks/incoming/oauth/stripe_account_webhooks/base.rb
|
41
44
|
- app/models/integrations/stripe_installation.rb
|
42
45
|
- app/models/oauth/stripe_account.rb
|
43
46
|
- app/models/webhooks/incoming/oauth/stripe_account_webhook.rb
|