This will be mostly a Drupal question rather may not have any relation to Drupal commerce checkout.
I have an Offsite Checkout redirect payment method in which I have a buildRedirectFrom
as stated in https://docs.drupalcommerce.org/commerce2/developer-guide/payments/create-payment-gateway/off-site-gateways/off-site-redirect which will redirect to a vendor site for payment. I have the CompleteUrl
which will come back the call to the controller method after payment completion.
I need to show a custom error message after redirecting to the checkout page, when the payment fails
or canceled
the payment based on the status I receive from vendor API.
But somehow the message is not showing up after the redirection. I tried to show the message first and then redirect too. Is there any solution in Drupal or particularly in commerce for this?
My try
In controller method:
if( $statusFromAPI != 'PAYSUCCESS' ){
$redirect = new RedirectResponse('/checkout/' .$order_id . '/review');
$redirect->send();
if($statusFromAPI == 'ERROR'){
$this->messenger()->addError("Payment has been failed. Please check the payment details.", TRUE);
} else if($statusFromAPI == 'PAYSTART'){
$this->messenger()->addWarning("Please review the payment details again.");
} else{
$this->messenger()->addWarning("Please review the payment details.", TRUE);
}