Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc(payment): Factorise logic for payment_url generation #3238

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vincent-pochet
Copy link
Collaborator

Context

A lot of business logic is duplicated in all services related to the generation of the payment url.

Description

This PR:

  • extract the should_process_payment? and deliver_error_webhook from Invoices::Adyen|Cashfree|StripeService and PaymentRequests::Adyen|Cashfree|StripeService into Invoices|PaymentRequests::GeneratePaymentUrlService to avoid duplication
  • Handles provider errors and returns a ThirdPartyFailure with the detail of the error, allowing a better handling of these failures (See discussions on feat(api): Introduce new error #3215, about a potential renaming of this type of service failure)

@vincent-pochet vincent-pochet force-pushed the misc-payment-url-refact branch 2 times, most recently from 81cf37c to 064605e Compare February 21, 2025 14:54
@vincent-pochet vincent-pochet force-pushed the misc-payment-url-refact branch from 064605e to f8ec67e Compare February 21, 2025 15:02
Copy link
Collaborator

@rsempe rsempe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

@julienbourdeau
Copy link
Contributor

Excellent! This is a great improvment so we should get it in.
I'll share some personal opinions that can be addressed now or later.

  1. I'm not a fan of the "Third Party" terminology because we use "Provider" everywhere else.
  2. For external services error, I'd love to have a free form object too where we can just forward more details from the provider (see screenshot)
  3. Ideally, I'd like the provider name to be set in the base service. Something like:
class StripeService < BaseService
  PROVIDER_NAME = "Stripe"
end

class BaseResult
  def thridpartyerror(...)
    fail_with_error(provider: PROVIDER_NAME, ...)
  end
end

CleanShot 2025-02-18 at 12 39 48@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants