In My Account when attempting to delete a Payment method by clicking Delete then confirming Delete, you get the message "The payment method Visa ending in xxxx has been deleted." However the Payment method has not deleted: it still appears in My Account->Payment methods and it can still be used at checkout.

Comments

jpdaut created an issue. See original summary.

bojanz’s picture

Which gateway are you using? The delete code is gateway specific.

jpdaut’s picture

Oops. Of course. I was using Authorize.net gateway.

mglaman’s picture

jpdaut, was it removed in Authorize.net?

The Authorize.net module has

  /**
   * {@inheritdoc}
   *
   * @todo Needs kernel test
   */
  public function deletePaymentMethod(PaymentMethodInterface $payment_method) {
    $owner = $payment_method->getOwner();
    $customer_id = $owner->commerce_remote_id->getByProvider('commerce_authnet_' . $this->getPluginId());
    $request = new DeleteCustomerPaymentProfileRequest($this->authnetConfiguration, $this->httpClient);
    $request->setCustomerProfileId($customer_id);
    $request->setCustomerPaymentProfileId($payment_method->getRemoteId());
  }

bojanz, I had no idea we needed to delete the payment method in our gateway.

Wouldn't it be best to modify

    try {
      $payment_gateway_plugin->deletePaymentMethod($payment_method);
    }
    catch (PaymentGatewayException $e) {
      drupal_set_message($e->getMessage(), 'error');
      return;
    }
</doe>

to run <code>$payment_method->delete();

after invoking the gateway plugin? I assumed the delete was just to process deletion of the remote profile. And if no exception is thrown the payment method deletes.

mglaman’s picture

Project: Commerce Core » Commerce Authorize.Net
Version: 8.x-2.x-dev » 8.x-1.x-dev
Component: Commerce » Code

Eh, I just read the docblock. Both the entity and the remote record are deleted.

And create method assumes it'll be saved. So I guess we can move this to Auth.net queue and fix there.

jpdaut’s picture

mglaman I just looked at my Authorize.net's Customer Profile CIM page and my profile created 11-27 is still there.
So it seems, when you click Delete your Payment method in the UI, neither the entity nor the remote record are deleted currently.

jpdaut’s picture

Whether the remote record is actually deleted or not is not important. It's not this module's responsibility.

But deleting the local entity is, so customer won't be presented with a payment method they don't want.

mglaman’s picture

Status: Active » Needs review
StatusFileSize
new819 bytes

Here is patch to fix delete payment method

mglaman’s picture

StatusFileSize
new988 bytes

Revised patch to handle record not found error.

  • mglaman committed ef493c7 on 8.x-1.x
    Issue #2830998 by mglaman: Cannot delete Payment method
    
mglaman’s picture

Status: Needs review » Fixed
jpdaut’s picture

I can confirm this works now.

As an aside, I checked and the CIM profile is still there in Authorize.net. But that's their property anyway, if they don't want to delete it it's their choice. The sync w/ Drupal is not mandatory I don't think and it has not impact on functionality.

Status: Fixed » Closed (fixed)

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