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 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的