/**
  * @param Payment $payment
  *
  * @return void
  *
  * @throws SavePaymentFailedException
  */
 public function markAsPaid(Payment $payment)
 {
     $connection = $this->getConnection();
     $table = $this->getTableName();
     try {
         $connection->update($table, ['paid' => true, 'gateway_id' => $payment->getGatewayId()], ['id' => $payment->id()]);
     } catch (\Exception $exception) {
         throw SavePaymentFailedException::createWithPayment($payment, sprintf('Unable to mark payment #%s as paid', $payment->id()), 0, $exception);
     }
 }
 /**
  * Processes the associated command
  *
  * @param CommandInterface|TakePaymentCommand $command
  *
  * @throws PaymentFailedException     if unable to create new payment record, or the gateway authorisation failed
  *                                    form any reason
  * @throws SavePaymentFailedException if the payment succeeds, but something goes wrong when updating the payment
  *                                    record
  */
 protected function _handle(CommandInterface $command)
 {
     $this->paymentId = null;
     $payment = $this->convertCommandToPayment($command);
     try {
         // We clone the payment object here, so PHPSpec can test it, until the following issue is resolved…
         // https://github.com/phpspec/phpspec/issues/789
         $payment = $this->repository->savePaymentBeforeProcessing($payment);
         $this->paymentId = $payment->id();
         $purchaseRequest = $this->gateway->purchase($payment->getGatewayPurchaseArray());
         $purchaseResponse = $purchaseRequest->send();
         if (!$purchaseResponse->isSuccessful()) {
             // @todo Add saving of failed details to payment record
             throw PaymentNotAuthorisedException::createWithPayment($payment, $purchaseResponse->getMessage());
         }
     } catch (PaymentFailedException $exception) {
         // These exceptions will be publicly safe, so just throw themhttps:/https://github.com/phpspec/phpspec/issues/789https://github.com/phpspec/phpspec/issues/789https://github.com/phpspec/phpspec/issues/789https://github.com/phpspec/phpspec/issues/789/github.com/phpspec/phpspec/issues/789
         throw $exception;
     } catch (\Exception $exception) {
         throw PaymentFailedException::createWithPayment($payment, sprintf('An unrecognised exception (%s) has been thrown', get_class($exception)), 0, $exception);
     }
     try {
         $this->updatePaymentWithStripeCharge($payment, $purchaseResponse);
     } catch (\Exception $exception) {
         // Wrap in SavePaymentFailedException if need be to provide public exception
         if ($exception instanceof SavePaymentFailedException) {
             throw $exception;
         }
         throw SavePaymentFailedException::createWithPayment($payment, sprintf('An unrecognised exception (%s) has been thrown', get_class($exception)), 0, $exception);
     }
 }