# 付款失敗時讓訂閱者保留存取權

> 讓 Agent 為你的 App 的訂閱開啟 Apple 的帳單寬限期，選擇它持續多久、涵蓋哪些續訂，並先在沙盒中試用。

Source: https://air.build/tw/docs/app-store/let-subscribers-keep-access-when-a-payment-fails/

當訂閱者的續訂因付款問題而失敗時，Apple 的帳單寬限期可以在 Apple 嘗試收款期間讓他們再多使用幾天。Apple 在 [Enable billing grace period for auto-renewable subscriptions](https://developer.apple.com/help/app-store-connect/manage-subscriptions/enable-billing-grace-period-for-auto-renewable-subscriptions) 中介紹了它。Agent 可以為你的 App 開啟它、選擇它持續多久，並先在沙盒中試用。

> [!NOTE]
> AirBuild 沒有這項設定的控制項：在 **App 內購買項目** 標籤頁上，**訂閱群組設定** 只能重新命名或刪除群組。你需要在專案的聊天中詢問 Agent。它用 `asc apps subscription-grace-period view` 讀取該設定（列在 [asc：App 與 App Store 頁面](https://air.build/tw/docs/cli/asc-apps/#apps) 的 `apps` 下），用 `asc subscriptions grace-periods update` 更改它（列在 [asc：App 內購買與訂閱](https://air.build/tw/docs/cli/asc-monetization/#subscriptions) 的 `subscriptions` 下）。與其他 App Store Connect 指令一樣，它們透過在 AirBuild 中連接的 Apple 開發者帳號執行。

## 整個 App 只有一項設定

`asc` 的說明稱它為「an app's subscription grace period」（App 的訂閱寬限期）：每個 App 只有一個，而不是每個方案或每個訂閱群組各一個。你的選擇會同時套用到該 App 的所有訂閱。

## 你可以選擇什麼

| 設定 | 選項 | 旗標 |
| --- | --- | --- |
| 多長時間 | 3 天、16 天或 28 天（`THREE_DAYS`、`SIXTEEN_DAYS`、`TWENTY_EIGHT_DAYS`） | `--duration` |
| 哪些續訂 | 所有續訂（`ALL_RENEWALS`），或僅從一個付費期間到下一個付費期間的續訂（`PAID_TO_PAID_ONLY`） | `--renewal-type` |
| 沙盒 | 開啟或關閉 | `--sandbox-opt-in` |
| 你的訂閱者 | 開啟或關閉 | `--opt-in` |

關於每個選項涵蓋哪些續訂，例如轉為付費訂閱的免費試用，請參閱 Apple 的[頁面](https://developer.apple.com/help/app-store-connect/manage-subscriptions/enable-billing-grace-period-for-auto-renewable-subscriptions)。

## 先在沙盒中試用

在專案的聊天中提出要求，例如：

```text
Turn on the billing grace period in Sandbox only: 16 days, for all renewals. Don't turn it on for real subscribers yet.
```

1. Agent 用 `asc apps subscription-grace-period view` 讀取你的 App 的寬限期，並告訴你目前的設定。
2. 它用 `asc subscriptions grace-periods update` 更改設定，這裡使用 `--sandbox-opt-in true`、`--duration SIXTEEN_DAYS` 和 `--renewal-type ALL_RENEWALS`。該指令只傳送你指定的設定，其他設定維持不變。
3. 它會向你顯示 Apple 傳回的設定。

然後在你的 iPhone 上用沙盒測試人員進行測試：請參閱[在發佈前測試 App 內購買項目](https://air.build/tw/docs/app-store/test-purchases-before-release/#buy-as-a-sandbox-tester)。Agent 可以讓測試人員的訂閱更快續訂，但 `asc sandbox` 沒有讓付款失敗的設定。關於在沙盒中測試帳單問題，請參閱 Apple 的 [Overview of testing in sandbox](https://developer.apple.com/help/app-store-connect/test-in-app-purchases/overview-of-testing-in-sandbox)。

### 檢查你的 App 的行為

寬限期是在 Apple 那邊設定的。你的 App 在寬限期內是否繼續開放付費功能，取決於你的 App 的程式碼。Apple 的[頁面](https://developer.apple.com/help/app-store-connect/manage-subscriptions/enable-billing-grace-period-for-auto-renewable-subscriptions)說明了 App 需要做什麼。詢問你的 Agent，例如：

```text
Check that the app keeps Premium open for a subscriber in Apple's billing grace period, and fix it if it doesn't.
```

## 為所有人開啟

在沙盒中運作正常後，提出要求：

```text
The grace period works in Sandbox. Turn it on for real subscribers too, with the same settings.
```

Agent 會使用 `--opt-in true` 執行 `asc subscriptions grace-periods update`，並向你顯示結果。

## 更改或關閉

說出你想要的，例如「把帳單寬限期改為 28 天。」或「關閉帳單寬限期。」Agent 只更改你指定的內容：時長、續訂，或者用 `--opt-in false` 和 `--sandbox-opt-in false` 將其關閉。關於你更改設定時已處於寬限期的訂閱者會如何，請參閱 Apple 的[頁面](https://developer.apple.com/help/app-store-connect/manage-subscriptions/enable-billing-grace-period-for-auto-renewable-subscriptions)。

要隨時查看該設定，請說「顯示 App 的帳單寬限期。」

## 常見問題

**每個方案可以有自己的寬限期嗎？**

不可以。`asc` 的說明稱它為 App 的訂閱寬限期：每個 App 一個。

**可以在 AirBuild 中查看寬限期嗎？**

不可以。**App 內購買項目** 標籤頁不顯示它。請詢問 Agent，或在網頁版 App Store Connect 中查看。

**Agent 說至少需要一個更新旗標。**

該指令需要有要更改的內容：時長、續訂、沙盒或你的訂閱者。說明你想更改什麼。

**Agent 說 --duration 必須是 THREE_DAYS、SIXTEEN_DAYS、TWENTY_EIGHT_DAYS 之一。**

只有這三種時長。請選擇 3 天、16 天或 28 天。

**Agent 說 --renewal-type 必須是 ALL_RENEWALS、PAID_TO_PAID_ONLY 之一。**

選擇所有續訂，或僅從一個付費期間到下一個付費期間的續訂。
