Cannot Catch Errors in Stripe payment gateway in Codeigniter 3

心不动则不痛 提交于 2020-01-06 04:35:11

问题


I am very new to stripe payment gateway integration. I am facing a problem on catching errors. I saw their official documentation for catching errors, but nothing is working. My payment is working fine and when I enter the correct information stripe takes my payment and successfully redirect to the success page, but the problem happens when I tried with wrong information it doesn't give me any error just shows HTTP 500 error (In production environment). When I set error_reporting(E_ALL) then it shows me the actual errors but I can't catch those errors on Try Catch.

Here is my controller

    //check whether stripe token is not empty
    if (!empty($_POST['stripeToken'])) {
        $stripe = array(
            "secret_key" => "secret key",
            "publishable_key" => "public key"
        );

        \Stripe\Stripe::setApiKey($stripe['secret_key']);

        //add customer to stripe
        $customer = \Stripe\Customer::create(array(
                    'email' => $email,
                    'source' => $token
        ));


        try {
            $charge = \Stripe\Charge::create(array(
                        'customer' => $customer->id,
                        'amount' => $itemPrice * 100,
                        'currency' => $currency,
                        'description' => $itemNumber,
                        'metadata' => array(
                            'item_id' => $itemNumber
                        )
            ));
            $chargeJson = $charge->jsonSerialize();
        } catch (\Stripe\Error\Card $e) {
            // Since it's a decline, \Stripe\Error\Card will be caught
            $body = $e->getJsonBody();
            $err = $body['error'];

            print('Status is:' . $e->getHttpStatus() . "\n");
            print('Type is:' . $err['type'] . "\n");
            print('Code is:' . $err['code'] . "\n");
            // param is '' in this case
            print('Param is:' . $err['param'] . "\n");
            print('Message is:' . $err['message'] . "\n");
        } catch (\Stripe\Error\RateLimit $e) {
            // Too many requests made to the API too quickly
        } catch (\Stripe\Error\InvalidRequest $e) {

            echo "I am this error";
            $body = $e->getJsonBody();
            $err = $body['error'];

            print('Status is:' . $e->getHttpStatus() . "\n");
            print('Type is:' . $err['type'] . "\n");
            print('Code is:' . $err['code'] . "\n");
            // param is '' in this case
            print('Param is:' . $err['param'] . "\n");
            print('Message is:' . $err['message'] . "\n");
        } catch (\Stripe\Error\Authentication $e) {
            // Authentication with Stripe's API failed
            // (maybe you changed API keys recently)
        } catch (\Stripe\Error\ApiConnection $e) {
            // Network communication with Stripe failed
        } catch (\Stripe\Error\Base $e) {
            // Display a very generic error to the user, and maybe send
            // yourself an email
        } catch (Exception $e) {
            // Something else happened, completely unrelated to Stripe
        }

here is the error if I turn on error_reporting(E_ALL) PHP error. According to the Strip's documentation I should catch the errors in Try Catch block, but I am failing to catch the errors. It is in local server but in live server it is same.

来源:https://stackoverflow.com/questions/52695268/cannot-catch-errors-in-stripe-payment-gateway-in-codeigniter-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!