【问题标题】:Stripe integration for subscriptions in Bootstrap website, API Key invalidBootstrap 网站中订阅的条带集成,API 密钥无效
【发布时间】:2016-03-27 15:14:00
【问题描述】:

我一直致力于将 Stripe 结帐表单集成到我的网站中,以便客户注册订阅。我已经通过 composer 下载了 Stripe 库,它是最新的,这是我的文件结构

出于显而易见的原因,我的 Stripe API 密钥已被星号替换。

这些文件与我测试中的文件相同。测试成功并将其发送到 Stripe,一切正常。在这个新站点中,表单甚至无法打开,我收到错误消息:

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

当我放入我的条带 TEST 键时,我会复制并粘贴它们,并确保键和引号之间没有空格。我的想法是某处的连接有问题,因为表单甚至无法打开。过去 3 天我一直在研究这个问题,并阅读了 Stripe 的所有文档。 我的问题是:如果我使用 Bootstrap,是否可以集成条带订阅按钮? SSL 和 HTTPS 只是为了测试它?我的代码中是否有错误会使 API 密钥无效?这是条带结帐表单的 index.php 和 charge.php。

索引.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());
}

【问题讨论】:

    标签: php twitter-bootstrap stripe-payments


    【解决方案1】:

    我敢打赌你在 index.html 中的require_once('./config.php') 没有正确指向。您收到的错误很可能是因为 data-key="&lt;?php echo $stripe['publishable_key']; ?&gt;" 无法回显 config.php 文件的变量。

    一个快速的解决方案是将&lt;?php echo $stripe['publishable_key']; ?&gt;" 替换为您的公钥。

    【讨论】:

    • Cheech 感谢您的回复,Stripe 的支持团队给我回了邮件……结果我的所有代码都是正确的,我的 PHP 没有运行的原因是因为我直接通过浏览器和我的 PHP 从未运行,因为它从未到达服务器……我忘记了这一点,因为 PHP 是一种服务器端语言,它只有在到达服务器后才由服务器执行!由于它没有到达服务器,浏览器只是将其作为文本读取!
    【解决方案2】:

    Stripe 的支持团队给我发了电子邮件……结果证明我的所有代码都是正确的,我的 PHP 没有运行的原因是我直接通过浏览器和我的 PHP 查看我的网站从未运行,因为它从未到达服务器...我忘记了,因为 PHP 是一种服务器端语言,它只有在到达服务器后才由服务器执行!由于它没有到达服务器,浏览器只是将它作为文本读取!我希望这可以帮助其他像我一样困惑的人!要在 Macbook 上设置本地 php 服务器(在 Windows 上可能不同),请打开终端,切换到项目所在的目录,然后在进入该目录后运行此代码

    php -S localhost:3000
    

    然后进入你的浏览器并转到url“localhost:3000”

    当我这样做时,代码到达服务器并被解释/执行!

    【讨论】:

      猜你喜欢
      • 2017-12-21
      • 2014-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-26
      • 2017-11-13
      相关资源
      最近更新 更多