I am trying to catch InvalidCreditCardException
and any other exception using Omnipay Bridge of PayumBundle.
I have tried:
try {
return $this->forward('PayumBundle:Capture:do', array(
'payum_token' => $captureToken,
));
} catch (\Exception $e) {
$exceptions = array();
do {
$exceptions[] = $e->getMessage();
} while ($e = $e->getPrevious());
$response = new Response(json_encode(array('status' => 'failed', 'Message' => $exceptions)));
return $response;
}
But before the code gets to my catch the Omnipay
throws its own Exception of creditcard number not being valid.
In comments it also says:
Generally if you want to validate the credit card yourself with custom error messages, you should use your framework's validation library, not this method.
This is exactly what I am trying to do, how can I validate card with custom error using Symfony PayumBundle exception?
Please do not answer this question by giving reference like the first answer below. I do appreciate his assistance but that does not help me on how to make use of that exception in my code.
Very Important
I am trying to understand PayumBundle better so I need to understand what I am doing wrong and steps (not in english but in real example code with explanation) I should take to catch hold of exception in my action and display user friendly message. Please understand, I am really new to symfony and I am trying learn, if you are going to ask me to create a service and do this or that then it will not help me, please see the example here, I really really appreciate the help but then I am really really lost.
Please note that if the correct credit number is entered the transaction goes through just fine, it is only the exception that I need to catch when wrong card number is entered, or card is expired or any other.
In case if it helps, this is how my config.yml looks like
contexts:
paypal:
paypal_express_checkout_nvp:
username: %paypal_username%
password: %paypal_password%
signature: %paypal_signature%
sandbox: %paypal_sandbox%
stripe_omnipay:
omnipay:
type: Stripe
options:
apiKey: xxxx
testMode: true
extensions:
PaymentExtension:
class: Payum\Core\Extension\PaymentExtention