diff --git a/modules/payment/src/Plugin/Commerce/CheckoutPane/PaymentInformation.php b/modules/payment/src/Plugin/Commerce/CheckoutPane/PaymentInformation.php index 071ad4b3..cd66750e 100644 --- a/modules/payment/src/Plugin/Commerce/CheckoutPane/PaymentInformation.php +++ b/modules/payment/src/Plugin/Commerce/CheckoutPane/PaymentInformation.php @@ -7,6 +7,7 @@ use Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowInterface; use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase; use Drupal\commerce_payment\PaymentOption; use Drupal\commerce_payment\PaymentOptionsBuilderInterface; +use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayInterface; use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsCreatingPaymentInterface; use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsStoredPaymentMethodsInterface; use Drupal\Component\Utility\NestedArray; @@ -208,7 +209,11 @@ class PaymentInformation extends CheckoutPaneBase { $default_payment_gateway_id = $default_option->getPaymentGatewayId(); $payment_gateway = $payment_gateways[$default_payment_gateway_id]; $payment_gateway_plugin = $payment_gateway->getPlugin(); - if ($payment_gateway_plugin instanceof SupportsStoredPaymentMethodsInterface) { + // If this payment gateway plugin supports stored payment methods, we build + // the "add-payment-method" plugin form. However, we skip if this is an + // off-site payment gateway, since payment method creation is part of the + // payment process which occurs later. + if ($payment_gateway_plugin instanceof SupportsStoredPaymentMethodsInterface && !$payment_gateway_plugin instanceof OffsitePaymentGatewayInterface) { $pane_form = $this->buildPaymentMethodForm($pane_form, $form_state, $default_option); } elseif ($payment_gateway_plugin->collectsBillingInformation()) { @@ -368,7 +373,8 @@ class PaymentInformation extends CheckoutPaneBase { return; } - if ($payment_gateway->getPlugin() instanceof SupportsStoredPaymentMethodsInterface) { + $payment_gateway_plugin = $payment_gateway->getPlugin(); + if ($payment_gateway_plugin instanceof SupportsStoredPaymentMethodsInterface && !$payment_gateway_plugin instanceof OffsitePaymentGatewayInterface) { if (!empty($selected_option->getPaymentMethodTypeId())) { /** @var \Drupal\commerce\Plugin\Commerce\InlineForm\EntityInlineFormInterface $inline_form */ $inline_form = $pane_form['add_payment_method']['#inline_form']; diff --git a/modules/payment_example/src/Plugin/Commerce/PaymentGateway/StoredOffsiteRedirect.php b/modules/payment_example/src/Plugin/Commerce/PaymentGateway/StoredOffsiteRedirect.php index d20ea9bd..006ecacc 100644 --- a/modules/payment_example/src/Plugin/Commerce/PaymentGateway/StoredOffsiteRedirect.php +++ b/modules/payment_example/src/Plugin/Commerce/PaymentGateway/StoredOffsiteRedirect.php @@ -11,7 +11,6 @@ use Drupal\commerce_payment\PaymentMethodTypeManager; use Drupal\commerce_payment\PaymentTypeManager; use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsCreatingOffsitePaymentMethodsOnUserPageInterface; use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsCreatingPaymentInterface; -use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsDeletingPaymentMethodsInterface; use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsStoredPaymentMethodsInterface; use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsUpdatingStoredPaymentMethodsInterface; use Drupal\Component\Datetime\TimeInterface; @@ -31,14 +30,15 @@ use Symfony\Component\HttpFoundation\Request; * forms = { * "offsite-payment" = "Drupal\commerce_payment_example\PluginForm\OffsiteRedirect\PaymentOffsiteForm", * "add-payment-method" = "Drupal\commerce_payment_example\PluginForm\StoredOffsiteRedirect\PaymentMethodAddForm", - * "edit-payment-method" = "Drupal\commerce_payment\PluginForm\PaymentMethodEditForm", * }, + * "edit-payment-method" = "Drupal\commerce_payment\PluginForm\PaymentMethodEditForm", + * }, * payment_method_types = {"credit_card"}, * credit_card_types = { * "amex", "dinersclub", "discover", "jcb", "maestro", "mastercard", "visa", * }, * ) */ -class StoredOffsiteRedirect extends OffsiteRedirect implements SupportsStoredPaymentMethodsInterface, SupportsCreatingPaymentInterface, SupportsCreatingOffsitePaymentMethodsOnUserPageInterface, SupportsDeletingPaymentMethodsInterface, SupportsUpdatingStoredPaymentMethodsInterface { +class StoredOffsiteRedirect extends OffsiteRedirect implements SupportsStoredPaymentMethodsInterface, SupportsCreatingPaymentInterface, SupportsCreatingOffsitePaymentMethodsOnUserPageInterface, SupportsUpdatingStoredPaymentMethodsInterface { use StringTranslationTrait;