fix: #3631059 Order reuses the stored payment method's billing profile entity for off-site gateways instead of copying it

Issue: https://www.drupal.org/project/commerce/issues/3631059

When a stored payment method of an off-site gateway is selected, PaymentInformation::submitPaneForm() now copies the payment method's billing profile into the order, instead of giving the order the payment method's own profile entity.

Why not just createDuplicate()?

The Payment information pane can be submitted several times for the same order: the customer goes back from review, switches cards, or a validation error sends them back to the step. If every submit called $payment_method_profile->createDuplicate(), each one would replace the order's billing profile with a new entity. The previous profile would be left orphaned, with no owner and no reference, and nothing would clean it up.

So the fix combines both:

  • If the order already has its own billing profile, it is updated in place with populateFromProfile(), including data. This is what the on-site (SupportsCreatingPaymentMethodsInterface) branch above already does since #3281185, so both branches now behave the same.
  • If the order has no billing profile, or still references the payment method's profile (orders affected by this bug), it gets a copy made with createDuplicate().

Tests

testCheckoutWithStoredOffsiteRedirectPost() now submits the pane twice for the second order. It checks that the order keeps the same billing profile ID, that this ID differs from the payment method's, and that the addresses match.

Merge request reports

Loading
Loading