我有条纹工作很棒 . 在客户捐赠后,会创建一个新的订阅,并且效果很好 - 除非Stripe识别出该电子邮件并说“输入验证码” .
如果客户这样做,由于某种原因,不会创建新订阅并且不向客户收费 .
这是我的charge-monthly.php
<?php
require_once('init.php');
// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("sk_test_**************");
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
$email = $_POST['stripeEmail'];
$amount = $_POST['amount'];
$finalamount = $amount * 100;
$dollars = ".00";
$plan = "/month";
$dash = " - ";
$monthlyplan = $amount .$dollars .$plan .$dash .$email;
//Create monthly plan
$plan = \Stripe\Plan::create(array(
"name" => $monthlyplan,
"id" => $monthlyplan,
"interval" => "month",
"currency" => "usd",
"amount" => $finalamount,
));
// Create a Customer
$customer = \Stripe\Customer::create(array(
"source" => $token,
"description" => "MONTHLY DONATION",
"plan" => $monthlyplan,
"email" => $email, )
);
?>
任何想法为什么当Stripe识别用户并且他“登录”时它不允许我创建订阅?
在条带日志中,我收到此400错误:
{
"error": {
"type": "invalid_request_error",
"message": "Plan already exists."
}
}
但肯定没有创建计划......啊!
1 回答
您的请求失败的原因是,如果用户返回相同的电子邮件地址并想要注册相同的计划,您已经拥有了具有该名称的现有计划,
$monthlyplan = $amount .$dollars .$plan .$dash .$email;
因此,您对
\Stripe\Plan::create
的调用将返回错误,并导致其余调用在此处失败 .您可以在计划ID中添加类似唯一ID或时间的内容 .
http://php.net/manual/en/function.time.php http://php.net/manual/en/function.uniqid.php
人们通常会处理其他一些方法:
为$ 1创建单个计划,然后在创建订阅时调整数量 . 因此,每月计划1美元,数量为100,将收取100美元的月 .
存储客户在您的应用程序中支付的金额 . 订阅您的客户每月0美元的计划 . 使用webhooks监听
invoice.created
事件 . 让您的webhook处理程序每月为余额添加一个发票项目 .