Trigger an event when gateway fails to process the payment.

@param GatewayInterface       $gateway
@param SubscriptionInterface  $subscription
@param FailedPaymentInterface $failed_payment
@param string|null            $note
517468
public function triggerSubscriptionPaymentFailed(GatewayInterface $gateway, SubscriptionInterface $subscription, FailedPaymentInterface $failed_payment, $note = null)
    {
        $this->trigger(self::ON_SUBSCRIPTION_PAYMENT_FAILED, $gateway, $subscription, $failed_payment, $note);
    }
1310046
public function fail(\Throwable $exception)
    {
        if (null === $this->observable) {
            return;
        }

        $this->observable = null;
        $this->failed = true;
        $this->delayed->reject($exception);
    }
232806
private function rejectDispatch($exception, Envelope $envelope, Queue $queue)
    {
        // Make sure the exception is not interfering.
        // Previously failing jobs handling have been moved to a middleware.
        //
        // Emit an event to let others log that exception
        $this->dispatcher->dispatch(BernardEvents::REJECT, new RejectEnvelopeEvent($envelope, $queue, $exception));

        if ($this->options['stop-on-error']) {
            throw $exception;
        }
    }
885481
function subscribeError(message, exceptionMessage, exceptionType) {
		reply(proto.writeSubscribeException(
			message.id, exceptionMessage, exceptionType));
		dequeueSubUnsubRequest(message.itemName);
		fireFirstSubUnsubEvent(message.itemName);
	}
824886
private function getFailure(MethodInvocation $invocation, FailureInterface $failure, \ReflectionMethod $onFailure = null)
    {
        if ($onFailure) {
            return $onFailure->invoke($invocation->getThis(), $failure);
        }

        return $this->failureException($invocation, $failure);
    }
753245
public static function _failure($objects, $echoResponse = TRUE, $format = 'json') {
        return self::_doResponse('failure', $objects, $echoResponse, $format);
    }
1104082
protected function failure(Circuit $circuit)
    {
        $circuit->incrementFailure();
        $circuit->setLastFailure(time());

        $this->dispatcher->dispatch(CircuitEvents::FAILURE, (new CircuitEvent($circuit)));
        $this->writeToStore($circuit);
    }
21936
public function triggerOrderCompleted(GatewayInterface $gateway, OrderInterface $order)
    {
        $this->trigger(self::ON_ORDER_COMPLETED, $gateway, $order);
    }
1228240
public function onPaymentPrepare(PaymentEvent $event)
    {
        $payment = $event->getPayment();
        if (!$payment instanceof OrderPayment) {
            return;
        }

        if (null === $order = $payment->getOrder()) {
            throw new LogicException('You must assign the payment to the order first.');
        }

        if ($order->isEmpty()) {
            throw new LogicException('Empty order.');
        }

        if ($order->getLocked()) {
            $event->addMessage(new ResourceMessage('ekyna_order.event.locked', ResourceMessage::TYPE_ERROR));
            return;
        }
        $order->setLocked(true);

        if (0 >= $payment->getAmount()) {
            $payment->setAmount(
                $this->calculator->calculateOrderRemainingTotal($order)
            );
        }

        $this->updateOrder($order, $event, true);
    }
779304
public function onPaymentNotify(PaymentEvent $event)
    {
        $payment = $event->getPayment();
        if (!$payment instanceof OrderPayment) {
            return;
        }

        $order = $payment->getOrder();

        if ($order->getLocked()) {
            $order->setLocked(false);
            $this->updateOrder($order, $event);
        }
    }
917617
public function addFailure(RequestInterface $request, Exception $exception): void
    {
        $this->lastRequest = $request;
        $this->lastException = $exception;
    }
582888
public function addFailedRecipient($failedRecipient, Exception $e = null)
    {
        $failedRecipients = (array) $failedRecipient;

        if (count($failedRecipients) > 1 && $e) {
            throw new InvalidArgumentException('If you pass an exception you can only pass one failed reciepient');
        }

        foreach ($failedRecipients as $recipient) {
            $this->failedRecipients[] = $recipient;
        }

        if ($e) {
            $this->errors[count($this->failedRecipients) - 1] = $e;
        }

        return $this;
    }
725697
protected function component_class_callback_failed(\Throwable $e, string $component, string $interface,
            string $methodname, array $params) {
        if ($this->observer) {
            call_user_func_array([$this->observer, 'handle_component_failure'], func_get_args());
        }
    }
468056
public function cancelSubscription($subscriptionId, \DateTime $cancellationDate = null, $cancellationNote = null)
    {
        $requestData = new Cancel\RequestData($subscriptionId);
        $requestData->setCancellationDate($cancellationDate);
        $requestData->setCancellationNote($cancellationNote);

        $request = new Cancel\Request($requestData);

        return $this->sendRequest($request, Cancel\ApiResponse::class);
    }
416574
protected function onFailure(RequestInterface $request)
    {
        return function ($reason) use ($request) {

            // Only log a rejected requests if it hasn't already been logged
            $this->log($request, null, $reason);

            return Promise\rejection_for($reason);
        };
    }
1234592
public function fail($exception)
    {
        Event::trigger('onFailure', array(
            'exception' => $exception,
            'job' => $this,
        ));

        $this->updateStatus(Status::STATUS_FAILED);
        Failure::create(
            $this->payload,
            $exception,
            $this->worker,
            $this->queue
        );

        Stat::incr('failed');
        Stat::incr('failed:' . $this->worker);
    }
1024134
public function send($message, &$failedRecipients = null)
    {
        if ($this->_log) {
            $this->filesystem->fileAppend($this->_log, json_encode($message, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . PHP_EOL);
        }

        $this->logger->debug(['From: ', $message->getFrom()]);
        $this->logger->debug(['To: ', $message->getTo()]);
        $this->logger->debug(['Cc:', $message->getCc()]);
        $this->logger->debug(['Bcc: ', $message->getBcc()]);
        $this->logger->debug(['Subject: ', $message->getSubject()]);

        $failedRecipients = [];

        $message->setMailer($this);
        $this->eventsManager->fireEvent('mailer:beforeSend', $this, ['message' => $message]);
        $r = $this->_send($message, $failedRecipients);
        $this->eventsManager->fireEvent('mailer:afterSend', $this, ['message' => $message, 'failedRecipients' => $failedRecipients]);

        return $r;
    }