计划已经存在 - stripe / php

时间:2018-03-21 23:17:48

标签: php stripe-payments

我想结束自己创建的月度计划,并提供客户的身份证明,并完成固定金额的付款。

然而,在创建"订阅"在创建原始计划之后,"计划已经存在"是输出。

我无法真正理解上述错误。例如,如果我创建并运行"订阅"如果没有创建原始计划,代码将正常工作。

当时的日志如下。但是,由此,无法判断哪种计划内容适合客户。如何将您的计划与"订阅"?

相关联

实施订阅而不创建计划

// echo $customer->id;
// $my_original_plan =  \Stripe\Plan::create(array(
// "id"  => "basic-monthly",
// "interval"  =>  "month",
// "currency"  => "jpy",
// "product" => array("name" => "aaaaaa"),
// "amount"  => 9800
// ));
// echo $my_original_plan;

$subscription =  \Stripe\Subscription::create(array(
"customer" => "$customer->id",
"items" => array(
  array(
    "plan" => "basic-monthly",
  ),
)
));

echo $subscription;

以上日志

Stripe\Subscription JSON: {
    "id": "sub_CXKozer939U80A",
    "object": "subscription",
    "application_fee_percent": null,
    "billing": "charge_automatically",
    "billing_cycle_anchor": 1521674075,
    "cancel_at_period_end": false,
    "canceled_at": null,
    "created": 1521674075,
    "current_period_end": 1524352475,
    "current_period_start": 1521674075,
    "customer": "cus_CXKovj687dz1Po",
    "days_until_due": null,
    "discount": null,
    "ended_at": null,
    "items": {
        "object": "list",
        "data": [
            {
                "id": "si_CXKoBTbLbBICEL",
                "object": "subscription_item",
                "created": 1521674075,
                "metadata": [],
                "plan": {
...

计划已存在

// echo $customer->id;

$my_original_plan =  \Stripe\Plan::create(array(
"id"  => "basic-monthly",
"interval"  =>  "month",
"currency"  => "jpy",
"product" => array("name" => "aaaaaa"),
"amount"  => 9800
));

// echo $my_original_plan;


$subscription =  \Stripe\Subscription::create(array(
"customer" => "$customer->id",
"items" => array(
array(
"plan" => "basic-monthly",
),
)
));

echo $subscription;

所有源代码

<?php

header("Content-type: text/plain; charset=UTF-8");

if(isset($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
if (isset($_POST['request']))
{

//make token from ajax js 
$token_from_js = $_POST['request'];

//stripe from composer
require_once 'vendor/autoload.php';

//set api key
\Stripe\Stripe::setApiKey("sk_test_");

//make customer info 
$customer =  \Stripe\Customer::create(array(
"description" => "taylor@example.com",
"source" => "$token_from_js",
));

// echo $customer->id;

$my_original_plan =  \Stripe\Plan::create(array(
"id"  => "basic-monthly",
"interval"  =>  "month",
"currency"  => "jpy",
"product" => array("name" => "aaaaaa"),
"amount"  => 9800
));

// echo $my_original_plan;


$subscription =  \Stripe\Subscription::create(array(
"customer" => "$customer->id",
"items" => array(
array(
"plan" => "basic-monthly",
),
)
));

echo $subscription;
};
};

?>

1 个答案:

答案 0 :(得分:1)

<WixLocalization Culture="en-us" Codepage="1252" xmlns="http://schemas.microsoft.com/wix/2006/localization">
  <UI Dialog="SetupTypeDlg" Control="Title" >{\HeaderTitleFont}!(loc.SetupTypeDlgTitle)</UI>
</WixLocalization>

您应该尝试使用product_id而不是数组。