Stripe 订阅成功但卡无效

Stripe Subscription Successful with Invalid Card

我正在使用 composer 实例化 stripe,并尝试使用卡号 4000 0000 0000 0341 在测试模式下为客户订阅订阅计划。文档说这将被接受,但在用于创建订阅。我的问题是,为什么使用此卡号创建订阅步骤总是 return 成功?

我的收费代码是

<form action="subscribe.php" method="post">
                            <input type="hidden" name="customer" value="<? echo $stripeID ?>">
                            <input type="hidden" name="plan" value="<? echo $thisPlan['id'] ?>">
                            <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
                                    data-key="<?php echo $stripe['publishable_key']; ?>"
                                    data-name="www.example.com"
                                    data-description="<? echo $thisPlan['name'] ?>"
                                    data-amount="<? echo $thisPlan['amount'] ?>"
                                    data-locale="auto"
                                    data-panel-label="Subscribe Now"
                                    data-label="Subscribe"
                                    data-allow-remember-me="false">
                          </script>
                        </form>

我的 subscribe.php 是

    try {
    $result = \Stripe\Subscription::create(array(
      "customer" => $_POST['customer'],
      "plan" => $_POST['plan']
    ));
  echo "Subscription successful";
}
catch (Stripe\Error\Base $e) {
  // Code to do something with the $e exception object when an error occurs
  echo($e->getMessage());
} catch (Exception $e) {
  // Catch any other non-Stripe exceptions
}

问题是为什么测试卡号没有生成错误响应。答案在评论中:客户已经分配了默认卡,即使以 javascript 形式提供新卡,stripe 始终使用默认卡。我的解决方案是使用令牌中返回的新卡号更新客户,然后应用订阅:

try {  
    $cu = \Stripe\Customer::retrieve($_POST['customer']);
    $cu->source = $_POST['stripeToken']; // obtained with Stripe.js
    $cu->save();
}

try {
$result = \Stripe\Subscription::create(array(
  "customer" => $_POST['customer'],
  "plan" => $_POST['plan']
));

echo "\n订阅成功"; }