\Drupal\commerce_payment\PaymentOptionsBuilder::buildOptions does not filter out payment gateways which has a mismatching mode to the currently configured payment gateway mode.

Comments

thejacer87 created an issue. See original summary.

mglaman’s picture

The problem can be seen in #2965800: After update to latest dev, "paymentProfileId' element is invalid" error.

When there is no "owner ID" we assume the user is anonymous. So we try to extract the remote customer profile ID and remote payment ID from the payment method ID. When the user is logged in, the payment method remote ID is only the remote payment profile ID.

We can do a fix in Authorize.net but we should be filtering payment methods.

After

$payment_gateways_with_payment_methods = array_filter($payment_gateways, function ($payment_gateway) {
      /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
      return $payment_gateway->getPlugin() instanceof SupportsStoredPaymentMethodsInterface;
    });

We should then filter out payment methods whose payment_gateway_mode do not match the payment gateway's getMode result.

thejacer87’s picture

Status: Active » Needs review
StatusFileSize
new1.31 KB

upon initial testing, this seemed to filter out the methods for me

bojanz’s picture

         $payment_methods = $payment_method_storage->loadReusable($customer, $payment_gateway, $billing_countries);

Wouldn't it make more sense to perform the filtering here, in PaymentMethodStorage::loadReusable()? That would also allow it to be performed on the query level.

thejacer87’s picture

StatusFileSize
new700 bytes

here's the new patch, pretty sure $payment_gateway->getPluginConfiguration()['mode'] is the best way to get the gateway's mode

mglaman’s picture

Issue tags: +Needs tests

I'd like to have test coverage here. I think we're missing generic coverage of our payment gateway mode logics.

Status: Needs review » Needs work

The last submitted patch, 5: commerce-filter-payment-modes-2968614-5.patch, failed testing. View results

mglaman’s picture

Assigned: Unassigned » mglaman

We should use $payment_gateway->getPlugin()->getMode(). Writing tests and wrapping this up.

mglaman’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.24 KB

Here is fix using proper method and tests that changing the payment gateway's mode does not load the previous payment methods as being reusable.

  • mglaman committed b6395dc on 8.x-2.x
    Issue #2968614 by thejacer87, mglaman: PaymentOptionsBuilder::...
mglaman’s picture

Status: Needs review » Fixed

Fixed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.