laravel 试用结束后更新订阅条带API

x6492ojm  于 2023-11-20  发布在  其他
关注(0)|答案(1)|浏览(118)

我有一个情况,我必须切换价格ID,一旦试用已在条带API结束。
到目前为止,我试图创建一个时间表,但它创建了一个新的订阅。这是我的代码如下。

$data = [
     'customer' => $stripeCustomer->id,
      'items' => [
       ['price' => $priceId],
     ],
     'collection_method' => 'charge_automatically',
      'cancel_at' => Carbon::now()->addYears(1)->timestamp,
     'description' => $description,
   ];
   $subscription = $this->stripe->subscriptions->create($data);
    $schedule = $this->stripe->subscriptionSchedules->create([
                        'from_subscription' => $subscription->id,
                        //'customer' => $stripeCustomer->id,
                        //'start_date' => Carbon::now()->addYears(1)->timestamp,
                        'start_date' => Carbon::now()->addSeconds(60)->timestamp,
                        'end_behavior' => 'release',
                        'phases' => [
                            [
                                'items' => [
                                    [
                                        'price' => $product['product']->metadata->schedule_price,
                                        'quantity' => 1,
                                    ],
                                ],
                                //'end_date' => Carbon::now()->addYears(20)->timestamp,
                            ],
                        ],
                    ]);c

字符串

aoyhnmkz

aoyhnmkz1#

在创建订阅计划时使用from_subscription参数时,您将无法使用大多数其他参数。
您需要将当前订阅计划创建请求拆分为两个单独的请求。第一个请求应仅使用from_subscription参数创建订阅计划。创建订阅计划后,您可以发出另一个请求以更新它并进行所需的更改。
来源:https://stripe.com/docs/api/subscription_schedules/create#create_subscription_schedule-from_subscription

相关问题