-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc(Payment): Refactor payment processing preconditions (#2935)
## Context This PR follow #2930 in the refactor of the payment processing. The main goal of this refactor will be to: - **Avoid double payment at all cost** - Avoid code duplication between payment processor integration to make maintenance easier ## Description This PR: - Updates the legacy `Invoices::Payments::*CreateJob` to delegate the logic to the new `Invoices::Payments::CreateService#call` rather than directly to `Invoices::Payments::*Service#call` - Share the precondition on invoice status, payment provider presence and invoice amount into the `Invoices::Payments::CreateService#call` to avoid duplication In a next step this last method will be updated to create a payment before delegating the payment processing to the providers and to ensure that no processing payment already exists.
- Loading branch information
1 parent
8c1e97b
commit 087bb3c
Showing
16 changed files
with
191 additions
and
150 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module PaymentProviders | ||
class CreatePaymentFactory | ||
def self.new_instance(provider:, invoice:) | ||
service_class(provider:).new(invoice) | ||
end | ||
|
||
def self.service_class(provider:) | ||
# TODO(payment): refactor Invoices::Payments::*Service#call | ||
# into PaymentProviders::*::Payments::CreateService#call | ||
case provider.to_sym | ||
when :adyen | ||
Invoices::Payments::AdyenService | ||
when :gocardless | ||
Invoices::Payments::GocardlessService | ||
when :stripe | ||
Invoices::Payments::StripeService | ||
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
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
Oops, something went wrong.