簡體   English   中英

使用 PHP 在 Stripe 上降級/升級訂閱時遇到問題

[英]Trouble downgrading/upgrading subscription on Stripe with PHP

我正在使用 Stripe 為我的 SAAS 定期付款。

我今天面臨的問題是:我想讓我的客戶選擇升級或降級他們對我的服務的訂閱。

所以我實際上擁有的代碼如下(根據此處的文檔):

\Stripe\Subscription::update($subscriptionID, [
    'items' => [
        'id' => $itemID,
        'plan' => $planId
    ]
]);

$subscriptionID$itemID$planId返回我需要的正確值,但在 Stripe 端沒有更新。

我只有這個錯誤:

{
  "error": {
    "type": "invalid_request_error",
    "message": "Invalid array",
    "param": "items"
  }
}

請問他有什么幫助嗎?

謝謝。

您只需要在另一個數組級別覆蓋項目,如下所示:

\Stripe\Subscription::update($subscriptionID, [
    'items' => [
        [
          'id' => $itemID,
          'plan' => $planId
        ]
    ]
]);

它正在使用此代碼工作:

$customer = \Stripe\Customer::retrieve($CustomerId);
$subscription = $customer->subscriptions->retrieve($subscriptionID);
$customer->updateSubscription(['plan' => $planId]);
$customer->save();

奇怪的是,Stripe API 沒有談論這個解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM