-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc(PaymentProviders): Refact Webhooks folder structure
- Loading branch information
1 parent
5abc45b
commit 3e0dd92
Showing
14 changed files
with
83 additions
and
61 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
app/services/payment_providers/adyen/webhooks/base_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module PaymentProviders | ||
module Adyen | ||
module Webhooks | ||
class BaseService < BaseService | ||
def initialize(organization_id:, event_json:) | ||
@organization = Organization.find(organization_id) | ||
@event_json = event_json | ||
|
||
super | ||
end | ||
|
||
private | ||
|
||
attr_reader :organization, :event_json | ||
|
||
def event | ||
@event ||= JSON.parse(event_json)['notificationItems'].first&.dig('NotificationRequestItem') | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
app/services/payment_providers/stripe/webhooks/base_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module PaymentProviders | ||
module Stripe | ||
module Webhooks | ||
class BaseService < BaseService | ||
def initialize(organization_id:, event_json:) | ||
@organization = Organization.find(organization_id) | ||
@event_json = event_json | ||
|
||
super | ||
end | ||
|
||
private | ||
|
||
attr_reader :organization, :event_json | ||
|
||
def event | ||
@event ||= ::Stripe::Event.construct_from(JSON.parse(event_json)) | ||
end | ||
|
||
def metadata | ||
@metadata ||= event.data.object.metadata.to_h.symbolize_keys | ||
end | ||
|
||
def handle_missing_customer | ||
# NOTE: Stripe customer was not created from lago | ||
return result unless metadata&.key?(:lago_customer_id) | ||
|
||
# NOTE: Customer does not belong to this lago instance or | ||
# exists but does not belong to the organizations | ||
# (Happens when the Stripe API key is shared between organizations) | ||
return result if Customer.find_by(id: metadata[:lago_customer_id], organization_id: organization.id).nil? | ||
|
||
result.not_found_failure!(resource: 'stripe_customer') | ||
end | ||
end | ||
end | ||
end | ||
end |
4 changes: 2 additions & 2 deletions
4
...s/stripe/charge_dispute_closed_service.rb → ...webhooks/charge_dispute_closed_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...bhooks/stripe/customer_updated_service.rb → ...ripe/webhooks/customer_updated_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../stripe/setup_intent_succeeded_service.rb → ...ebhooks/setup_intent_succeeded_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters