doumi1884 2016-03-27 15:14
浏览 31
已采纳

Bootstrap网站中订阅的条带集成,API密钥无效

I've been working on integrating a Stripe checkout form into my website for customers to sign up for a subscription. I've downloaded the Stripe library via composer and it is up to date, here is my file structure File Structure

My Stripe API Keys have been replaced with Asterisks for obvious reasons.

The files are the same as the one in my test. The test worked and sent it to Stripe and everything worked. In this new site the form won't even open and I get the error:

{"error":{"type":"invalid_request","message":"Invalidkeyparameter."}}

When I do put in my stripe TEST keys, I copy and paste them and make sure there are no spaces between the key and the quotes. My thought is that something is wrong with a connection somewhere because the form won't even open. I've been working on this the last 3 days and have read all of Stripe's Docs. My questions are: Can a stripe subscription button be integrated if i'm using Bootstrap?, If I have Stripe in test mode and i'm using the test keys do I still have to have it under an SSL and HTTPS just to test it?, and is there an error in my code that would make the API Key Invalid? Here is the index.php and charge.php for the stripe checkout form.

Index.php

<?php require_once('./config.php'); ?>

<form action="charge.php" method="post">

  <script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
        data-key="<?php echo $stripe['publishable_key']; ?>"

        data-image="https://pixel.nymag.com/imgs/daily/science/2014/11/13

        data-amount="1200"

        data-name="Remember My People"
        data-description="RMP Monthly subscription"
        data-label="Sign Me Up!" 
        data-billing-address="true"
        >

  </script>
</form>

Charge.php

<?php
  require_once('./config.php');

  $token  = $_POST['stripeToken'];

  try {

  $customer = \Stripe\Customer::create(array(
      'email' => $_POST['stripeEmail'],
      'source'  => $_POST['stripeToken'],
      'plan' => 'rmp_monthly'
  ));

   $charge = \Stripe\Charge::create(array(
      'customer' => $customer->id,
      'amount'   => 1200,
      'currency' => 'usd'
  ));

    header('Location: https://remembermypeople.com');
    exit;
  } 

  catch (Exception $e) {

      // header('Location:oops.html');
      error_log("unable to sign up customer" . $_POST['stripeEmail']. ", error" . $e->getMessage());
}
  • 写回答

2条回答 默认 最新

  • duanhe8280 2016-05-01 02:14
    关注

    Stripe's support team emailed me back... it turned out all of my code was correct and the reason my PHP was not running was because I was viewing my website directly through the browser and my PHP never ran because it never reached a server... I forgot that since PHP is a server side language that it's only executed by the server once it reaches the server! Since it didn't reach the server, the browser just read it as text! I hope this helps anyone else who was as confused as I was! To set up a local php server on your Macbook (may be different on windows) open up the terminal, change into the directory your project is in, then run this code once you're in the directory

    php -S localhost:3000
    

    Then go into your browser and go to the url "localhost:3000"

    When I did this, the code reached a server and was interpreted/executed!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下