code: public function onPreDelete(ResourceEventInterface $event)
      {
          $payment = $this->getPaymentFromEvent($event);
  
          // Pre load sale's payments
          $payment->getSale()->getPayments()->toArray();
  
          if (!in_array($payment->getState(), PaymentStates::getDeletableStates())) {
              throw new IllegalOperationException(); // TODO reason message
          }
      }
docs: Pre delete event handler.
  
  @param ResourceEventInterface $event
  
  @throws IllegalOperationException