class BuyArticleOperation {
/** @var PaymentsGateway */
private $paymentsGateway;
/** @var DelayedPaymentsGateway */
private $delayedPaymentsGateway;
public function process(string $orderId)
{
// doing stuff with my order and then...
try {
$this->paymentsGateway->attempt($orderId);
} catch (PaymentsGatewayException $e) {
// something went wrong, let's switch the payment
// to the "delayed" queue system
$this->delayedPaymentsGateway->queue($orderId);
}
}
}
use CircuitBreaker;
use My\Namespace\PaymentsGateway;
use My\Namespace\DelayedPaymentsGateway;
class BuyArticleOperation {
/** @var PaymentsGateway */
private $paymentsGateway;
/** @var DelayedPaymentsGateway */
private $delayedPaymentsGateway;
public function process(string $orderId)
{
if(CircuitBreaker::isAvailable(PaymentsGateway::class)) {
try {
$this->paymentsGateway->attempt($orderId);
} catch (PaymentsGatewayException $e) {
// something went wrong, let's switch the payment
// to the "delayed" queue system and report that
// the default gateway is not working!
$this->delayedPaymentsGateway->queue($orderId);
CircuitBreaker::reportFailure(PaymentsGateway::class);
}
// there's nothing we can do here anymore
return;
}
// we already know that the service is disabled, so we
// can queue the payment process on the delayed queue
// directly, without letting our users wait more
$this->delayedPaymentsGateway->queue($orderId);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.