Stripe Undefined Index (PHP) Secret Key


Stripe Undefined Index (PHP) Secret Key

我正试图设置条纹结帐支付系统,但我有麻烦的PHP。当我运行控制台日志时,所有内容都在执行,除了实际将收费发布到我的Stripe仪表板的那一部分,这是至关重要的。下面我强调了一些可能使我的谎言出错的地方。如果你需要更多的信息,请告诉我,我很乐意帮忙。

注意:下面的行"//收费卡是我认为问题所在,但我可能是错的。

'

    require_once('Stripe.php'); 
    $stripe = array(
        **'secret_key' => 'secret key',**
        'publishable_key' => 'publishable key'
        );
        **'Stripe'Stripe::setApiKey($stripe['secret key']);**

    if($_POST) {
        $error = NULL;
        try{
            if (isset($_POST['stripeToken'])) 
                throw new Exception("The Stripe Token was not generated correctly");

        //charge the card
        **$charge = 'Stripe'Charge::create(array(**
            'card' => $_POST['stripeToken'],
            'amount' => 2000,
            'currency' => 'usd'
            ));
            }
            catch(Exception $e) {
                $error = $e->getMessage(); 
            }
        $quotes= array(
            "A",
             "B",
             "C" 
            );
            echo "<h1>Here is your quote!</h1>";
            echo "<h2>" . $quotes[array_rand($quotes)]. "</h2>";

    } else{ 
        //show the welcome screen
        ?>
    <form action="index.php" method="POST">
      <script
        src="https://checkout.stripe.com/checkout.js" class="stripe-button"
        data-key="publishable key"
        data-amount="2000"
        data-name="BB Traders"
        data-description="Wiping Rags Order"
        data-image="/128x128.png">
      </script>
    </form>

"

由于访问不存在的数组元素,您正在获得Undefined index通知。请检查您对数组的所有访问- $_POST['stripeToken']$stripe['secret key']不存在。

同时,这也是一个非常常见的问题,例如在这里你可以得到一个关于如何克服这个通知的非常清晰的解释

我真的不懂php,但不会

isset($_POST['stripeToken'])

返回true如果令牌是正确生成的?看起来您可能会为您想要的相反情况抛出异常。

尝试暂时删除该检查或使用

isset($_POST['stripeToken'])==FALSE

或者其他最好的PHP方式