相关疑难解决方法(0)

使用Try/Catch PHP方法捕获条带错误

在网站上测试STRIPE期间,我构建了这样的代码:

   try {
        $charge = Stripe_Charge::create(array(
          "amount" => $clientPriceStripe, // amount in cents
          "currency" => "usd",
          "customer" => $customer->id,
          "description" => $description));
          $success = 1;
          $paymentProcessor="Credit card (www.stripe.com)";
    } 
    catch (Stripe_InvalidRequestError $a) {
        // Since it's a decline, Stripe_CardError will be caught
        $error3 = $a->getMessage();
    }

    catch (Stripe_Error $e) {
        // Since it's a decline, Stripe_CardError will be caught
        $error2 = $e->getMessage();
        $error = 1;
    }
if ($success!=1)
{
    $_SESSION['error3'] = $error3;
    $_SESSION['error2'] = $error2;
    header('Location: checkout.php');
    exit();
}
Run Code Online (Sandbox Code Playgroud)

问题是卡有时会出错(没有被我在那里的"catch"参数捕获)并且"try"失败并且页面立即在屏幕上发布错误而不是进入"if"和重定向回checkout.php. …

php error-handling try-catch stripe-payments

41
推荐指数
5
解决办法
5万
查看次数

标签 统计

error-handling ×1

php ×1

stripe-payments ×1

try-catch ×1