Work from #2838380: [META] Allow offsite payment gateways to create and use payment methods.

The PaymentInformation pane contains the following lines of code to initialize a new payment method object for a customer based on the current payment gateway and order billing information:

    /** @var \Drupal\commerce_payment\PaymentMethodStorageInterface $payment_method_storage */
    $payment_method_storage = $this->entityTypeManager->getStorage('commerce_payment_method');
    $payment_method = $payment_method_storage->create([
      'type' => $payment_option->getPaymentMethodTypeId(),
      'payment_gateway' => $payment_option->getPaymentGatewayId(),
      'uid' => $this->order->getCustomerId(),
      'billing_profile' => $this->order->getBillingProfile(),
    ]);

While working on supporting stored payment methods for off-site payment gateways, this section of code was needed a few more times. Off-site payment gateways will have to be responsible for creating payment methods in their onReturn method. Or, gateways may need to create payment methods at any other time.

Instead of having to copy and paste these lines of code, we should add a method to the payment method storage for creating a new entity with this information.

I'm proposing: \Drupal\commerce_payment\PaymentMethodStorageInterface::createForCustomer

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Status: Active » Needs review
StatusFileSize
new4.5 KB

here is the patch

mglaman’s picture

StatusFileSize
new4.5 KB

Fix phpcs

  • mglaman committed b2588d6 on 8.x-2.x
    Issue #3137107 by mglaman: Provide a storage method to initialize a new...
mglaman’s picture

Status: Needs review » Fixed

Committed! This will help gateways create payment methods outside of the checkout process.

Status: Fixed » Closed (fixed)

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