Skip to content

[STA-6] misc(payment): Migrate to TypedResult#5930

Open
vincent-pochet wants to merge 1 commit into
mainfrom
misc-payment-service-result2
Open

[STA-6] misc(payment): Migrate to TypedResult#5930
vincent-pochet wants to merge 1 commit into
mainfrom
misc-payment-service-result2

Conversation

@vincent-pochet

Copy link
Copy Markdown
Collaborator

Context

The TypedResults concern was introduced to let legacy multi-method services return typed Results instead of the deprecated LegacyResult (OpenStruct), as an intermediate step before a full single-call refactor.

Description

This PR applies the pattern to the Invoices::Payments sub-services (Stripe, Adyen, Cashfree, Flutterwave, Gocardless, Moneyhash).

Each service now includes the concern, declares a RESULTS constant mapping every method to its typed Result, and exposes those methods as private — reached through Service.call(:method_name, *args). The former per-instance constructor is dropped in favor of arguments passed to each method.

Call sites are updated accordingly: jobs use call!, Factory#new_instance is removed in favor of Factory.for(provider_customer), and specs exercise the services through the .call(:method)` entry point.

@vincent-pochet vincent-pochet force-pushed the misc-payment-service-result2 branch from 6639576 to df98a2d Compare July 13, 2026 11:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the Invoices::Payments::*Service provider implementations (Stripe, Adyen, Cashfree, Flutterwave, GoCardless, Moneyhash) to the TypedResults multi-method bridge so they return typed BaseResult objects via Service.call(:method, ...) / call!, and updates provider webhook handlers and specs to use the new call style.

Changes:

  • Introduce TypedResults + RESULTS maps in Invoices::Payments::*Service classes and route method calls through .call(:method, ...).
  • Update webhook event handlers to call klass.call(:update_payment_status, ...) when the target service supports TypedResults, with a temporary fallback for legacy services.
  • Update factories, payment intent services, and specs to use Factory.for(invoice) + provider_class.call!/call instead of instantiating provider services.

Reviewed changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
spec/services/payment_providers/moneyhash/handle_event_service_spec.rb Stubs provider payment update via .call entry point.
spec/services/payment_providers/gocardless/handle_event_service_spec.rb Verifies GoCardless event routing now uses .call(:update_payment_status, ...).
spec/services/payment_providers/flutterwave/webhooks/charge_completed_service_spec.rb Adjusts webhook specs for typed-results call path and result objects.
spec/services/payment_providers/cashfree/webhooks/payment_link_event_service_spec.rb Updates expectations to .call(:update_payment_status, ...).
spec/services/payment_providers/adyen/handle_event_service_spec.rb Updates Adyen webhook routing expectations to .call(...).
spec/services/payment_intents/fetch_service_spec.rb Switches to Factory.for(invoice) returning a provider class and calling call!.
spec/services/payment_intents/expire_service_spec.rb Switches to Factory.for(invoice) and call! for expiring provider URLs.
spec/services/invoices/payments/stripe_service_spec.rb Refactors tests to exercise .call(:method) while still testing internal helpers.
spec/services/invoices/payments/payment_providers/factory_spec.rb Updates factory contract: .for(invoice) returns a provider service class.
spec/services/invoices/payments/moneyhash_service_spec.rb Updates Moneyhash invoice-payment service specs to .call(:method, ...).
spec/services/invoices/payments/gocardless_service_spec.rb Updates GoCardless invoice-payment service specs to .call(:update_payment_status, ...).
spec/services/invoices/payments/generate_payment_url_service_spec.rb Updates stubs to reflect provider services being called via .call.
spec/services/invoices/payments/flutterwave_service_spec.rb Updates Flutterwave invoice-payment service specs to .call(:method, ...).
spec/services/invoices/payments/cashfree_service_spec.rb Updates Cashfree invoice-payment service specs to .call(:method, ...).
spec/services/invoices/payments/adyen_service_spec.rb Updates Adyen invoice-payment service specs to .call(:method, ...).
app/services/payment_providers/stripe/webhooks/base_service.rb Adds temporary TypedResults/legacy branching for payment status updates.
app/services/payment_providers/moneyhash/handle_event_service.rb Routes Moneyhash events through TypedResults when supported, else legacy path.
app/services/payment_providers/gocardless/handle_event_service.rb Routes GoCardless events through TypedResults when supported, else legacy path.
app/services/payment_providers/flutterwave/webhooks/charge_completed_service.rb Routes Flutterwave webhook through TypedResults when supported, else legacy path.
app/services/payment_providers/cashfree/webhooks/payment_link_event_service.rb Routes Cashfree webhook through TypedResults when supported, else legacy path.
app/services/payment_providers/adyen/handle_event_service.rb Routes Adyen webhook updates through TypedResults when supported, else legacy path.
app/services/payment_intents/fetch_service.rb Uses Factory.for(invoice).call! to generate provider URLs.
app/services/payment_intents/expire_service.rb Uses Factory.for(invoice).call! to expire provider sessions.
app/services/invoices/payments/stripe_service.rb Adds TypedResults + typed RESULTS; updates method signatures for .call dispatch.
app/services/invoices/payments/payment_providers/factory.rb Changes factory to return a provider service class via .for(invoice).
app/services/invoices/payments/moneyhash_service.rb Adds TypedResults + typed RESULTS; updates URL generation signature for .call.
app/services/invoices/payments/gocardless_service.rb Adds TypedResults + typed RESULTS; routes updates via .call.
app/services/invoices/payments/flutterwave_service.rb Adds TypedResults + typed RESULTS; updates URL generation signature for .call.
app/services/invoices/payments/cashfree_service.rb Adds TypedResults + typed RESULTS; updates URL generation signature for .call.
app/services/invoices/payments/adyen_service.rb Adds TypedResults + typed RESULTS; updates URL generation signature for .call.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/services/invoices/payments/moneyhash_service.rb
Comment thread spec/services/invoices/payments/stripe_service_spec.rb
Comment thread spec/services/invoices/payments/cashfree_service_spec.rb
Comment thread spec/services/invoices/payments/adyen_service_spec.rb
Comment thread spec/services/invoices/payments/flutterwave_service_spec.rb
@vincent-pochet vincent-pochet force-pushed the misc-payment-service-result2 branch from df98a2d to 2e21b5c Compare July 13, 2026 15:32
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