RPP / Verification / Connect the duplicate payment prevention service #7411
Labels
category: core
WC Payments core related issues, where it’s obvious.
category: engineering
For product engineering, architecture work, tech debt and so on.
category: projects
For any issues which are part of any project, including bugs, enhancements, etc.
component: checkout
Issues related to Checkout
Description
We should connect the new payment process with the
WCPay\Duplicate_Payment_Prevention_Service
(code).To begin with, the service is relatively simple, and mostly independent. With that in mind, let's duplicate it to
src
under a new namespace,WCPay\Internal\Service\DuplicatePaymentPreventionService
. There are too many small tweaks that need to be done on a relatively small and active piece of functionality, which is why it makes more sense to do it cleanly and independently.src
and the new namespace.WCPay\Internal\DependencyManagement\ServiceProvider\PaymentsServiceProvider
.$gateway->get_return_url()
can be safely replaced with$order->get_checkout_order_received_url()
. If coded properly, this should not be needed, as the gateway would be the one to generate those URLs.OrderService
class. This will require new methods in the order service, seems like those would be:get_intent_id( $order_id )
instead of accessing meta directly.get_cart_hash( $order_id )
to compare orders directly.is_paid( $order_id )
instead of$order->has_status( wc_get_is_paid_statuses() )
add_note( $order_id, $note )
delete( $order_id )
update_order_status_from_intent
to the new order service.Now that the service is suitable for
src
, it will need to be implemented within the new payment process. This involves a few moving pieces:maybe_update_session_processing_order
,remove_session_processing_order
, andclear_session_processing_order_after_landing_order_received_page
in the right place. Those are essentially hooks to allow the service to store/clear the needed data.Handling previously paid orders
Use
check_against_session_processing_order
to bail early if a similar order was already paid. This will require creating a newSimilarOrderDetectedState
, and transitioning to it before any actions are performed. The gateway should know how to handle this state, especially regarding return URLs.Ideally, the gateway should be able to do something like this:
Handling existing successful intents
Use
check_payment_intent_attached_to_order_succeeded
to use an existing intent, rather than creating a new one.This one is a bit more complicated, as it will require splitting
InitialState
intoInitialState
(where verification and preparation are done), aPreparedState
orVerifiedState
where intents are created (this one will be skipped), and aProcessed
state. If there is an intent already, it should be loaded from the API, stored in the context, and then we'd transition straight toProcessedState
to complete post-processing.Example:
Acceptance criteria
src
.Testing instructions
Same as the standard duplicate payment duplication prevention service.
Dev notes
Something similar was already implemented in the states PoC: https://github.com/Automattic/woocommerce-payments/pull/6287/files#diff-3bb8d0eedea7f88f28b34f5a291c5bf8c29621f783eadbf0cde7498589569a77
Additional context
Epic: #6673
Project: paJDYF-9hL-p2
The text was updated successfully, but these errors were encountered: