drasebt1835 2015-08-22 20:05
浏览 24

条带未定义索引(PHP)密钥

I am attempting to set up the Stripe checkout payment system, but am having trouble with the PHP. When I run the console log, everything executes, except the piece that actually posts the charge to my Stripe dashboard, which is crucial. Below I highlighted some of the potential areas that error my lie. Please let me know if you need more information, as I am glad to help.

Note: the line below "//charge card is where I think the problem is, but I may be mistaken.

`

    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>

`

  • 写回答

2条回答 默认 最新

  • douduikai0562 2015-08-22 20:14
    关注

    You are getting Undefined index notice as a result of accessing to unexisting array element. Just check all of your accesses to arrays - $_POST['stripeToken'] or $stripe['secret key'] does not exist.

    Also, it's a very common question, for example here you can get a realy clear explanation of how to overcome this notice.

    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致