【问题标题】:Stripe Undefined Index (PHP) Secret Key条带未定义索引 (PHP) 密钥
【发布时间】:2015-08-22 20:05:49
【问题描述】:

我正在尝试设置 Stripe 结帐支付系统,但遇到了 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>

`

【问题讨论】:

  • **\Stripe\Stripe::setApiKey($stripe['secret key']) 中缺少下划线。

标签: php payment stripe-payments


【解决方案1】:

由于访问不存在的数组元素,您会收到Undefined index 通知。只需检查您对数组的所有访问 - $_POST['stripeToken']$stripe['secret key'] 不存在。

另外,这是一个非常常见的问题,例如here,您可以得到关于如何克服此通知的非常清晰的解释。

【讨论】:

    【解决方案2】:

    我不太懂php,但不会

    isset($_POST['stripeToken'])
    

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

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

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

    或任何最好的 PHP 方式。

    【讨论】:

      猜你喜欢
      • 2013-01-26
      • 1970-01-01
      • 2013-06-14
      • 1970-01-01
      • 2015-03-24
      • 2018-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多