如何同时创建客户和收费订阅?

时间:2017-09-02 05:24:55

标签: php stripe-payments checkout stripe.js

我使用条带并且之前所有订阅都正常工作。 就在最近,我正在尝试将相同的代码移动到不同的条带帐户,并且在尝试收取订阅时收到错误。

<?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.

2 个答案:

答案 0 :(得分:1)

Plan objects同时拥有idname属性。 id是计划的唯一标识符,而name是其显示名称。

creating a customera subscription时,plan参数的值必须设置为有效的计划ID,而不是计划的名称。

在您的情况下,错误消息明确告诉您计划"basic_monthly"name,但计划的id504102373103330,因此,您需要传递plan参数以创建对该计划的订阅。

答案 1 :(得分:-2)

你必须改变秘密并测试api密钥

相关问题