# 付款失败时让订阅者保留访问权限

> 让智能体为你的 App 的订阅开启 Apple 的账单宽限期，选择它持续多久、涵盖哪些续订，并先在沙盒中试用。

Source: https://air.build/cn/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) 中介绍了它。智能体可以为你的 App 开启它、选择它持续多久，并先在沙盒中试用。

> [!NOTE]
> AirBuild 没有这项设置的控件：在 **App 内购买项目** 标签页上，**订阅群组设置** 只能重命名或删除群组。你需要在项目的聊天中询问智能体。它用 `asc apps subscription-grace-period view` 读取该设置（列在 [asc：App 与 App Store 页面](https://air.build/cn/docs/cli/asc-apps/#apps) 的 `apps` 下），用 `asc subscriptions grace-periods update` 更改它（列在 [asc：App 内购买项目与订阅](https://air.build/cn/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. 智能体用 `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/cn/docs/app-store/test-purchases-before-release/#buy-as-a-sandbox-tester)。智能体可以让测试员的订阅更快续订，但 `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 需要做什么。询问你的智能体，例如：

```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.
```

智能体会使用 `--opt-in true` 运行 `asc subscriptions grace-periods update`，并向你显示结果。

## 更改或关闭

说出你想要的，例如“把账单宽限期改为 28 天。”或“关闭账单宽限期。”智能体只更改你指定的内容：时长、续订，或者用 `--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 内购买项目** 标签页不显示它。请询问智能体，或者在网页版 App Store Connect 中查看。

**智能体说至少需要一个更新参数。**

该命令需要有要更改的内容：时长、续订、沙盒或你的订阅者。说明你想更改什么。

**智能体说 --duration 必须是 THREE_DAYS、SIXTEEN_DAYS、TWENTY_EIGHT_DAYS 之一。**

只有这三种时长。请选择 3 天、16 天或 28 天。

**智能体说 --renewal-type 必须是 ALL_RENEWALS、PAID_TO_PAID_ONLY 之一。**

选择所有续订，或仅从一个付费周期到下一个付费周期的续订。
