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
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | provide_a_storage_me-3137107-3.patch | 4.5 KB | mglaman |
| #2 | provide_a_storage_me-3137107-2.patch | 4.5 KB | mglaman |
Comments
Comment #2
mglamanhere is the patch
Comment #3
mglamanFix phpcs
Comment #5
mglamanCommitted! This will help gateways create payment methods outside of the checkout process.