code: public function onPreDelete(ResourceEventInterface $event)
      {
          if ($event->getHard()) {
              return;
          }
  
          if (null === $sale = $this->getSaleFromEvent($event)) {
              return;
          }
  
          // Stop if sale has valid payments
          foreach ($sale->getPayments() as $payment) {
              if (!PaymentStates::isDeletableState($payment->getState())) {
                  throw new Exception\IllegalOperationException(
                      'Sale has valid payments and therefore cannot be deleted.'
                  ); // TODO Translation
              }
          }
      }
docs: Pre delete event handler.
  
  @param ResourceEventInterface $event
  
  @throws Exception\IllegalOperationException