【发布时间】: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