/**
  * Cancel payment
  * Cancelaltion, is when the order can no longer be modified. While an order payment might be voided a new
  * invoice can always be generated. Cancellation of an order prevents any future change from being made to it.
  *
  * If REFUND is available do a refund, otherwise do a DEPOSITREVERSAL
  * Dont make APPROVEREVERSAL (decision by PM)
  *
  * @param \Magento\Framework\DataObject|InfoInterface|\Magento\Sales\Model\Order\Payment $payment
  *
  * @return $this
  * @throws \Exception
  * @api
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function cancel(\Magento\Payment\Model\InfoInterface $payment)
 {
     if (!$this->_dataHelper->isBackendAvailable()) {
         return $this;
     }
     $orderNumber = $payment->getAdditionalInformation('orderNumber');
     if (!strlen($orderNumber)) {
         /* dont throw an exception here, might be a pending payment */
         $this->_logger->debug(__METHOD__ . ':No order number found.');
         return $this;
     }
     $orderDetails = $this->getOrderDetails($orderNumber);
     $backendClient = $this->_dataHelper->getBackendClient();
     $log = sprintf("%s", $orderNumber);
     /* if refund op is available order already has been closed */
     /* otherwise revert each single payment */
     if (in_array('REFUND', $orderDetails->getOrder()->getOperationsAllowed())) {
         $log .= sprintf(" action:REFUND %s", $orderDetails->getOrder()->getAmount());
         $ret = $backendClient->refund($orderNumber, $orderDetails->getOrder()->getAmount(), $orderDetails->getOrder()->getCurrency());
         if ($ret->hasFailed()) {
             throw new \Exception($ret->getError()->getMessage());
         }
     } else {
         foreach ($orderDetails->getOrder()->getPayments() as $payment) {
             /** @var \WirecardCEE_QPay_Response_Toolkit_Order_Payment $payment */
             if (in_array('DEPOSITREVERSAL', $payment->getOperationsAllowed())) {
                 $log .= " action:DEPOSITREVERSAL APPROVEREVERSAL";
                 $ret = $backendClient->depositReversal($orderNumber, $payment->getPaymentNumber());
                 if ($ret->hasFailed()) {
                     throw new \Exception($ret->getError()->getMessage());
                 }
             }
         }
     }
     $this->_logger->debug(__METHOD__ . ":{$log}");
     return $this;
 }