CheckoutPage_Controller::PaymentErrorMessage PHP Method

PaymentErrorMessage() public method

This can originate e.g. from an earlier offsite gateway API response.
public PaymentErrorMessage ( ) : string
return string
    public function PaymentErrorMessage()
    {
        $order = $this->Cart();
        if (!$order) {
            return false;
        }
        $lastPayment = $order->Payments()->sort('Created', 'DESC')->first();
        if (!$lastPayment) {
            return false;
        }
        $errorMessages = $lastPayment->Messages()->exclude('Message', '')->sort('Created', 'DESC');
        $lastErrorMessage = null;
        foreach ($errorMessages as $errorMessage) {
            if ($errorMessage instanceof GatewayErrorMessage) {
                $lastErrorMessage = $errorMessage;
                break;
            }
        }
        if (!$lastErrorMessage) {
            return false;
        }
        return $lastErrorMessage->Message;
    }