I would like to uninstall this module but it requires me to delete all payment data first. I can't seem to delete the Purchase Order data, I've deleted the orders but the PO data stays behind. Any help would be greatly appreciated.

Thanks!

CommentFileSizeAuthor
#9 2972095-9.patch841 bytestonytheferg
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hommesreponse created an issue. See original summary.

FatherShawn’s picture

Assigned: Unassigned » FatherShawn

Is this in a dev site or a live site?

FatherShawn’s picture

Status: Active » Postponed (maintainer needs more info)
hommesreponse’s picture

My apologies for the delayed response, I didn't notice your reply to my message. I was working on a dev site but have since moved it into production. I've left the Purchase Order module installed for now. I played around with manually deleting Purchase Orders in the database but would rather do it via a form/UI of some kind obviously.

Let me know if you need any other info.

Thanks!

dwkitchen’s picture

Title: How I delete Purchase Orders? » Delete Purchase Orders
Version: 8.x-1.1 » 8.x-1.x-dev
Assigned: FatherShawn » Unassigned
Category: Support request » Feature request
Status: Postponed (maintainer needs more info) » Active
FatherShawn’s picture

Title: Delete Purchase Orders » Delete Payments
Project: Commerce Purchase Order » Commerce Core
Version: 8.x-1.x-dev » 8.x-2.x-dev
Component: User interface » Payment

Commerce Purchase Order uses the standard Commerce Payment entity and therefore its data is stored in the commerce_payment table. In my experience, payments are tied to orders, and are normally voided. There is a delete path defined in the Payment entity, /admin/commerce/orders/{commerce_order}/payments/{commerce_payment}/delete which also communicates that this is tied to the order.

You could delete all such payments via a query on that table for payments with type payment_purchase_order but I'm not sure what that would do to your orders.

I'm not sure what version of Commerce you are using, but I see a Delete operation added as an additional action in \Drupal\commerce_payment\PaymentListBuilder::getDefaultOperations which is also tied to orders by the route entity.commerce_payment.collection. I'm transferring this request upstream since it seems to be about Payments generally.

tkiehne’s picture

Although this might deviate somewhat from the OP report, I will pick up the thread from #6. As of this time, one cannot delete payments in Commerce 2 except in certain circumstances due to \Drupal\commerce_payment\PaymentAccessControlHandler, which does this check on the delete op:

    if ($operation == 'delete') {
      // @todo Add a payment gateway method for this check,
      // to allow a differently named test mode.
      $access = $access->andIf(AccessResult::allowedIf($entity->getPaymentGatewayMode() == 'test'));
    }

While this may make total sense where an external payment vendor is involved, our use case involves custom payments that represent offline transactions and that have legitimate need to be deleted on some occasions; Our custom gateways do not use the mode field, and wouldn't be set to "test" at any rate, so the access check fails. As indicated in the @todo, we should have the ability to decide when a payment can be deleted via our own gateway definitions.

Clearly this will require some work, not only to invoke the gateway when doing the access check, but to implement payment method cleanup on the payment delete event and possibly changing certain gateway & payment data on the order when these are removed (unless PaymentOrderUpdater handles that – regardless, making sure we don't end up with inconsistent data after deletion.)

tonytheferg’s picture

Changing this line to:
$access = $access->andIf(AccessResult::allowedIf($entity->getPaymentGatewayMode() != 'live'));

At least lets you delete manual payments.

tonytheferg’s picture

Status: Active » Needs review
FileSize
841 bytes

Here's an idea.

tonytheferg’s picture

Status: Needs review » Active

Opened a separate smaller issue specifically for manual payments.

#3379407: Allow deleting manual payments through the UI.