如何同时创建客户和收费订阅?
how to create customer and charge subscription at same time?
我使用的是 stripe,之前我的所有订阅都正常工作。
就在最近,我试图将相同的代码移动到不同的条带帐户,但在尝试收取订阅费用时收到错误消息。
<?php
require_once('../stripe-php-master/init.php');
// (switch to the live key later)
\Stripe\Stripe::setApiKey("sk_test_hlQNSE1fy1cGmsqDSbR9LfDF");
try
{
$customer = \Stripe\Customer::create(array(
'email' => $_POST['stripeEmail'],
'source' => $_POST['stripeToken'],
'plan' => 'basic_annually'
));
header('Location: ../../subscription-success.html');
exit;
}
catch(Exception $e)
{
header('Location:oops.html');
error_log("unable to sign up customer:" . $_POST['stripeEmail'].
", error:" . $e->getMessage());
}
这将返回以下错误
unable to sign up customer: 'test@example.com', error:No such plan: basic_monthly; one exists with a name of basic_monthly, but its ID is 504102373103330.
您必须更改密钥并测试 api 个密钥
Plan objects have both an id
and a name
属性。 id
是计划的唯一标识符,而 name
是其显示名称。
当 creating a customer or a subscription, the value of the plan
参数必须设置为有效的计划 ID,而不是计划名称时。
在您的情况下,错误消息明确告诉您有计划 "basic_monthly"
作为其 name
,但计划的 id
是 504102373103330
,所以这是您需要在 plan
参数中传递以创建该计划的订阅的值。
我使用的是 stripe,之前我的所有订阅都正常工作。 就在最近,我试图将相同的代码移动到不同的条带帐户,但在尝试收取订阅费用时收到错误消息。
<?php
require_once('../stripe-php-master/init.php');
// (switch to the live key later)
\Stripe\Stripe::setApiKey("sk_test_hlQNSE1fy1cGmsqDSbR9LfDF");
try
{
$customer = \Stripe\Customer::create(array(
'email' => $_POST['stripeEmail'],
'source' => $_POST['stripeToken'],
'plan' => 'basic_annually'
));
header('Location: ../../subscription-success.html');
exit;
}
catch(Exception $e)
{
header('Location:oops.html');
error_log("unable to sign up customer:" . $_POST['stripeEmail'].
", error:" . $e->getMessage());
}
这将返回以下错误
unable to sign up customer: 'test@example.com', error:No such plan: basic_monthly; one exists with a name of basic_monthly, but its ID is 504102373103330.
您必须更改密钥并测试 api 个密钥
Plan objects have both an id
and a name
属性。 id
是计划的唯一标识符,而 name
是其显示名称。
当 creating a customer or a subscription, the value of the plan
参数必须设置为有效的计划 ID,而不是计划名称时。
在您的情况下,错误消息明确告诉您有计划 "basic_monthly"
作为其 name
,但计划的 id
是 504102373103330
,所以这是您需要在 plan
参数中传递以创建该计划的订阅的值。