【问题标题】:how to create customer and charge subscription at same time?如何同时创建客户和收费订阅?
【发布时间】:2018-02-11 03:20:28
【问题描述】:

我使用的是 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.

【问题讨论】:

  • 正如您所说,您正在尝试对不同的 Stripe 帐户使用相同的代码。那个 Stripe 帐户是否有定义 ID basic_annually 的计划??
  • 是的,如果 ID504102373103330 你需要在 plan 中传递它

标签: php stripe-payments checkout stripe.js


【解决方案1】:

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

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

在您的情况下,错误消息明确告诉您有计划以"basic_monthly" 作为其name,但计划的id504102373103330,所以这是您需要传递的值plan 参数来创建对该计划的订阅。

【讨论】:

    【解决方案2】:

    您必须更改密钥并测试 api 密钥

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-21
      • 2020-04-07
      • 2021-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-26
      • 2018-10-15
      相关资源
      最近更新 更多