Reminder: By Aug 31, 2025, all new apps and updates to existing apps must use Billing Library version 7 or newer. If you need more time to update your app, you can request an extension until Nov 1, 2025. Learn about
Play Billing Library version deprecation.
從 Google Play 帳款服務程式庫第 5 版或第 6 版改用第 7 版
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本文說明如何從 Google Play 帳款服務程式庫第 5 或 6 版改用第 7 版,以及如何整合新的選用訂閱功能。
如需第 7.0.0 版的完整異動清單,請參閱「版本資訊」。
總覽
Google Play 帳款服務程式庫第 7 版改善了現有訂閱功能的付款處理方式。這些選用改善功能可讓您支援分期付款,以及支援預付訂閱方案的待處理交易。
回溯相容的 Play 帳款服務程式庫升級
所有新版 Google Play 帳款服務程式庫 7 API 皆為選用,開發人員無須實作任何 API 變更即可更新。
如要遷移,您必須更新 API 參照,並從應用程式中移除特定 API,如發布說明和本遷移指南稍後所述。
從 PBL 5 升級至 PBL 7
以下各節將說明如何從 PBL 5 升級至 PBL 7。
更新 Google Play 帳款服務程式庫
更新應用程式 build.gradle
檔案中的 Play 帳款服務程式庫依附元件版本。
dependencies {
def billingVersion = 7.0.0
implementation "com.android.billingclient:billing:$billingVersion"
}
接著,請按照下列各節所述更新 API 參照。
變更使用者的訂閱購買交易
Play 帳款服務程式庫 5 以下版本會使用 ProrationMode
對使用者的訂閱購買交易套用變更,例如升級或降級。這個 API 已遭移除,並由 ReplacementMode
取代。
處理訂閱價格異動
先前淘汰的 launchPriceConfirmationFlow
API 已移除。如需替代方案,請參閱價格異動指南。
處理訂閱相關 API 異動
先前已淘汰的 API setOldSkuPurchaseToken
、setReplaceProrationMode
、setReplaceSkusProrationMode
已遭到移除。
處理 Play 帳款服務程式庫錯誤
新的 NETWORK_ERROR
代碼可指出使用者裝置與 Google Play 系統之間的網路連線問題。
SERVICE_TIMEOUT
和 SERVICE_UNAVAILABLE
代碼也已更新。
詳情請參閱「處理 BillingResult 回應代碼」。
處理未完成的交易
Play 帳款服務程式庫不會再為未完成的購買交易建立訂單 ID。必須等到購買交易移至 PURCHASED
狀態後,系統才會為這類購買交易填入訂單 ID。請確保您的整合功能只預期在交易完成後取得訂單 ID。您仍然可以將購買憑證用於記錄。
如要進一步瞭解如何處理未完成的購買交易,請參閱 Play 帳款服務程式庫整合指南和購買交易生命週期管理指南。
處理已移除的其他結帳系統 API
已移除 BillingClient.Builder.enableAlternativeBilling
、AlternativeBillingListener
和 AlternativeChoiceDetails
。開發人員應改為在事件監聽器回呼中使用 BillingClient.Builder.enableUserChoiceBilling()
搭配 UserChoiceBillingListener
和 UserChoiceDetails
。
這項更新只是將已淘汰的 API 重新命名,行為並未變更。
選用變更
PBL 7 包含兩個新的選用 API。
支援預付方案的待處理購買交易
請參閱處理訂閱項目和待處理交易指南。
虛擬分期付款訂閱
請參閱分期付款訂閱項目整合指南。
從 PBL 6 升級至 PBL 7
以下各節說明如何從 PBL 6 升級至 PBL 7。
更新 Google Play 帳款服務程式庫
更新應用程式 build.gradle
檔案中的 Play 帳款服務程式庫依附元件版本。
dependencies {
def billingVersion = 7.0.0
implementation "com.android.billingclient:billing:$billingVersion"
}
接著,請按照下列各節所述更新 API 參照。
處理訂閱相關 API 異動
先前已淘汰的 API setOldSkuPurchaseToken
、setReplaceProrationMode
、setReplaceSkusProrationMode
已遭到移除。
處理已移除的其他結帳系統 API
已移除 BillingClient.Builder.enableAlternativeBilling
、AlternativeBillingListener
和 AlternativeChoiceDetails
。開發人員應改為在事件監聽器回呼中使用 BillingClient.Builder.enableUserChoiceBilling()
搭配 UserChoiceBillingListener
和 UserChoiceDetails
。
選用變更
PBL 7 包含兩個新的選用 API。
支援預付方案的待處理購買交易
請參閱處理訂閱項目和待處理交易指南。
虛擬分期付款訂閱
如要瞭解如何將這些變更整合至應用程式,請參閱「分期付款訂閱項目整合」指南。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Migrate to Google Play Billing Library 7 from versions 5 or 6\n\nThis document describes how to migrate from Google Play Billing Library 5 or 6\nto Google Play Billing Library 7 and how to integrate with the new optional\nsubscription capabilities.\n\nFor a full list of the changes in version 7.0.0, refer to the [release\nnotes](/google/play/billing/release-notes).\n\nOverview\n--------\n\nGoogle Play Billing Library 7 improves payment handling for\nexisting subscription features. These optional improvements\nadd support for paying with installment plans as well as\nsupport for pending purchases for prepaid subscriptions.\n\nBackward-compatible Play Billing Library upgrade\n------------------------------------------------\n\nAll new Google Play Billing Library 7 APIs are optional, and\ndevelopers don't need to implement any API changes to update.\n\nTo migrate, you need to update API references and remove\ncertain APIs from your app as described in the release notes and later in this\nmigration guide.\n\nUpgrade from PBL 5 to PBL 7\n---------------------------\n\nThe following sections describe how to upgrade from PBL 5 to PBL 7.\n\n### Update Google Play Billing Library\n\nUpdate the Play Billing Library dependency version in\nyour app's `build.gradle` file. \n\n dependencies {\n def billingVersion = 7.0.0\n\n implementation \"com.android.billingclient:billing:$billingVersion\"\n }\n\nNext, update your API references as described in the following sections.\n\n### Change a user's subscription purchases\n\nPlay Billing Library 5 and earlier used [`ProrationMode`](/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode)\nto apply changes to a user's subscription purchases, such as upgrades\nor downgrades. This API has been removed and replaced with\n[`ReplacementMode`](/reference/com/android/billingclient/api/BillingFlowParams.SubscriptionUpdateParams.ReplacementMode).\n\n### Handle subscription price changes\n\nThe previously deprecated `launchPriceConfirmationFlow` API has been removed.\nFor alternatives, see the [price changes\nguide](/google/play/billing/price-changes).\n\n### Handle subscription related API changes\n\nThe previously deprecated APIs `setOldSkuPurchaseToken`,\n`setReplaceProrationMode`, `setReplaceSkusProrationMode` have been removed.\n\n- Update `setOldSkuPurchaseToken` to [`setOldPurchaseToken`](/reference/com/android/billingclient/api/BillingFlowParams.SubscriptionUpdateParams.Builder#setOldPurchaseToken).\n- Update `setReplaceProrationMode` to [`setSubscriptionReplacementMode`](/reference/com/android/billingclient/api/BillingFlowParams.SubscriptionUpdateParams.Builder#setSubscriptionReplacementMode).\n- Update `setReplaceSkusProrationMode` to [`setSubscriptionReplacementMode`](/reference/com/android/billingclient/api/BillingFlowParams.SubscriptionUpdateParams.Builder#setSubscriptionReplacementMode).\n\n### Handle Play Billing Library errors\n\nA new `NETWORK_ERROR` code indicates problems with the network connection\nbetween the user's device and the Google Play system.\n\nThe `SERVICE_TIMEOUT` and `SERVICE_UNAVAILABLE` codes were also updated.\n\nFor more information, see\n[Handle BillingResult response codes](/google/play/billing/errors).\n\n### Handle pending transactions\n\nThe Play Billing Library no longer creates an order ID for pending purchases.\nFor these purchases, the order ID is populated after the purchase is moved\nto the [`PURCHASED`](/reference/com/android/billingclient/api/Purchase.PurchaseState#PURCHASED) state. Make sure that your integration expects\nan order ID only after a transaction has fully completed. You can still use\nthe purchase token for your records.\n\nFor more information about handling pending purchases, see the\nPlay Billing Library [integration guide](/google/play/billing/integrate) and the\n[purchase lifecycle management guide](/google/play/billing/lifecycle).\n\n### Handle removed alternative billing APIs\n\nRemoved [`BillingClient.Builder.enableAlternativeBilling`](/reference/com/android/billingclient/api/BillingClient.Builder#enableAlternativeBilling(com.android.billingclient.api.AlternativeBillingListener)),\n[`AlternativeBillingListener`](/reference/com/android/billingclient/api/AlternativeBillingListener),\nand [`AlternativeChoiceDetails`](/reference/com/android/billingclient/api/AlternativeChoiceDetails).\nDevelopers should use [`BillingClient.Builder.enableUserChoiceBilling()`](/reference/com/android/billingclient/api/BillingClient.Builder#enableUserChoiceBilling(com.android.billingclient.api.UserChoiceBillingListener)) with [`UserChoiceBillingListener`](/reference/com/android/billingclient/api/UserChoiceBillingListener)\nand [`UserChoiceDetails`](/reference/com/android/billingclient/api/UserChoiceDetails)\nin the listener callback instead.\n\nThis update is a renaming of the deprecated APIs with no behavior changes.\n\n### Optional Changes\n\nPBL 7 includes two new optional APIs.\n\n#### Support Pending Purchases for Prepaid Plans\n\nSee the [Handle Subscriptions and Pending Transactions](/google/play/billing/subscriptions#pending) guide.\n\n#### Virtual Installment Subscriptions\n\nSee the [Installment Subscriptions Integration](/google/play/billing/subscriptions#installments) guide.\n\nUpgrade from PBL 6 to PBL 7\n---------------------------\n\nThe following sections describe how to upgrade from PBL 6 to PBL 7.\n\n### Update Google Play Billing Library\n\nUpdate the Play Billing Library dependency version in\nyour app's `build.gradle` file. \n\n dependencies {\n def billingVersion = 7.0.0\n\n implementation \"com.android.billingclient:billing:$billingVersion\"\n }\n\nNext, update your API references as described in the following sections.\n\n### Handle subscription related API changes\n\nThe previously deprecated APIs `setOldSkuPurchaseToken`,\n`setReplaceProrationMode`, `setReplaceSkusProrationMode` have been removed.\n\n- Update `setOldSkuPurchaseToken` to [`setOldPurchaseToken`](/reference/com/android/billingclient/api/BillingFlowParams.SubscriptionUpdateParams.Builder#setOldPurchaseToken).\n- Update `setReplaceProrationMode` to [`setSubscriptionReplacementMode`](/reference/com/android/billingclient/api/BillingFlowParams.SubscriptionUpdateParams.Builder#setSubscriptionReplacementMode).\n- Update `setReplaceSkusProrationMode` to [`setSubscriptionReplacementMode`](/reference/com/android/billingclient/api/BillingFlowParams.SubscriptionUpdateParams.Builder#setSubscriptionReplacementMode).\n\n### Handle removed alternative billing APIs\n\nRemoved [`BillingClient.Builder.enableAlternativeBilling`](/reference/com/android/billingclient/api/BillingClient.Builder#enableAlternativeBilling(com.android.billingclient.api.AlternativeBillingListener)),\n[`AlternativeBillingListener`](/reference/com/android/billingclient/api/AlternativeBillingListener)\nand [`AlternativeChoiceDetails`](/reference/com/android/billingclient/api/AlternativeChoiceDetails).\nDevelopers should use [`BillingClient.Builder.enableUserChoiceBilling()`](/reference/com/android/billingclient/api/BillingClient.Builder#enableUserChoiceBilling(com.android.billingclient.api.UserChoiceBillingListener)) with [`UserChoiceBillingListener`](/reference/com/android/billingclient/api/UserChoiceBillingListener)\nand [`UserChoiceDetails`](/reference/com/android/billingclient/api/UserChoiceDetails)\nin the listener callback instead.\n\n### Optional Changes\n\nPBL 7 includes two new optional APIs.\n\n#### Support Pending Purchases for Prepaid Plans\n\nSee the [Handle Subscriptions and Pending Transactions](/google/play/billing/subscriptions#pending) guide.\n\n#### Virtual Installment Subscriptions\n\nSee the [Installment Subscriptions Integration](/google/play/billing/subscriptions#installments) guide for\ninformation on how to integrate these changes into your app."]]