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.
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
La bibliothèque Play Billing renvoie une réponse BillingResult pour vous indiquer le résultat d'une action déclenchée. Pour en savoir plus, consultez la section Gérer les codes de réponse BillingResult. Avant de déployer votre application dans l'environnement de production, vous pouvez tester ses différents flux de réponse à l'aide du simulateur de réponse.
Simulateur de réponse
Lorsque vous intégrez votre application à la bibliothèque Play Billing, il peut être difficile de tester tous les flux BillingResponseCode, car vous n'avez pas beaucoup de contrôle sur la communication entre le Play Store et le backend de Play.
Le simulateur de réponse de l'application Play Billing Lab vous permet
configurer les réponses de code d'erreur de la bibliothèque Play Billing afin de tester divers
et d'erreurs.
Activer les tests des remplacements de facturation pour la bibliothèque Play Billing
Pour activer la communication entre le simulateur de réponse et votre application, vous devez activer les tests de forçage de facturation pour la bibliothèque Play Billing depuis votre application. Pour ce faire, ajoutez les balises de métadonnées suivantes au fichier AndroidManifest.xml de votre application.
Lorsque vous déployez votre application dans l'environnement de production, vous devez utiliser un fichier AndroidManifest.xml distinct qui n'inclut pas ces balises de métadonnées ou vous assurer d'avoir supprimé ces balises du fichier AndroidManifest.xml.
Simuler les erreurs de la bibliothèque Play Billing
Pour simuler des erreurs de la bibliothèque Play Billing, commencez par configurer les codes de réponse
dans l'application Play Billing Lab, puis testez votre application.
Configurer un code de réponse
Dans l'application Play Billing Lab, connectez-vous à votre application avec un compte de testeur de licence.
Le tableau de bord Play Billing Lab s'affiche, avec
la fiche Simulateur de réponse.
<ph type="x-smartling-placeholder"></ph>
Figure 1. Fiche du simulateur de réponse.
Cliquez sur Gérer sur la fiche "Simulateur de réponse".
L'écran du simulateur de réponse s'affiche.
Lorsque vous y êtes invité, autorisez les notifications de Play Billing Lab pour voir l'état de la connexion de votre application.
Activez l'option Simuler les réponses de la Bibliothèque Play Billing, si ce n'est pas déjà fait.
Figure 2 Simulez le bouton de commutation des réponses de la Bibliothèque Play Billing.
Sélectionnez un code de réponse pour les API de la bibliothèque Play Billing de votre choix
à tester.
Vos sélections sont automatiquement enregistrées, et le simulateur de réponse est prêt à envoyer les codes de réponse sélectionnés à votre application.
Tester la gestion des erreurs dans votre application
Ouvrez votre application.
Si vous avez autorisé les notifications de Play Billing Lab, l'icône de notification de Play Billing Lab s'affiche dans la barre d'état de votre appareil, ce qui indique que vous êtes bien connecté au simulateur de réponse.
Figure 3 Icône Play Billing Lab indiquant une connexion réussie.
Déclenchez la méthode de l'API Play Billing Library que vous souhaitez tester. Par exemple, si vous souhaitez tester launchBillingFlow, lancez un parcours d'achat intégré.
Le contenu et les exemples de code de cette page sont soumis aux licences décrites dans la Licence de contenu. Java et OpenJDK sont des marques ou des marques déposées d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/27 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/07/27 (UTC)."],[],[],null,["# Test BillingResult response codes\n\nThe Play Billing Library returns a [`BillingResult`](/reference/com/android/billingclient/api/BillingResult) response to let you\nknow the outcome of an action that was triggered. For more\ninformation, see [handling `BillingResult` response codes](/google/play/billing/errors). Before you\ndeploy your app to the production environment, you can test your app's various\nresponse flows by using the Response Simulator.\n\nResponse Simulator\n------------------\n\nWhen you integrate your app with the Play Billing Library, it can be difficult\nto test all of the [`BillingResponseCode`](/reference/com/android/billingclient/api/BillingClient.BillingResponseCode) flows, because you don't have much\ncontrol over the communication between the Play Store and Play's backend.\nThe Response Simulator feature in the [Play Billing Lab](https://play.google.com/store/apps/details?id=com.google.android.apps.play.billingtestcompanion) app lets you\nconfigure error code responses for the Play Billing Library to test various complex\nerror scenarios.\n\n### Enable billing overrides testing for the Play Billing Library\n\n| **Note:** Before testing, ensure that your app is using [Play Billing Library](/google/play/billing/integrate#dependency) version 7.1.1 or later.\n\nTo enable communication between the Response Simulator and your app,\nyou must enable billing overrides testing for the Play Billing Library\nfrom within your app. To do this, add the following metadata tags to your app's\n`AndroidManifest.xml` file. \n\n```scdoc\n\u003cmanifest ... \u003e\n \u003capplication ... \u003e\n ...\n \u003cmeta-data\n android:name=\"com.google.android.play.largest_release_audience.NONPRODUCTION\"\n android:value=\"\" /\u003e\n \u003cmeta-data\n android:name=\"com.google.android.play.billingclient.enableBillingOverridesTesting\"\n android:value=\"true\" /\u003e\n \u003c/application\u003e\n\u003c/manifest\u003e\n```\n| **Note:** Even though adding only the `enableBillingOverridesTesting` tag and setting it to `true` is sufficient to enable billing overrides testing for your app, it's recommended that you also add the `NONPRODUCTION` tag. The `NONPRODUCTION` tag prevents accidental deployment of your app to the production environment with billing overrides testing enabled.\n\nWhen you deploy your app to the production environment, you should either\nuse a separate `AndroidManifest.xml` file that doesn't include these\nmetadata tags or ensure that you've removed these tags from the\n`AndroidManifest.xml` file.\n\n### Simulate Play Billing Library errors\n\nTo simulate Play Billing Library errors, first, configure the response codes\nin the [Play Billing Lab](https://play.google.com/store/apps/details?id=com.google.android.apps.play.billingtestcompanion) app, and then test your app.\n\n#### Configure a response code\n\n1. In the Play Billing Lab app, sign in with a [license tester](/google/play/billing/test#license-testers) account for your app.\n This displays the Play Billing Lab **Dashboard** including\n the **Response Simulator** card.\n\n **Figure 1.** Response Simulator card.\n2. Click **Manage** on the Response Simulator card.\n This shows the **Response Simulator** screen.\n\n3. When prompted, allow notifications from Play Billing Lab to see the connection status of your app.\n\n4. Enable the **Simulate Play Billing Library responses** switch, if it isn't\n already enabled.\n\n **Figure 2.** Simulate Play Billing Library responses switch.\n5. Select a response code for the Play Billing Library APIs that you want\n to test.\n Your selections are automatically saved, and the Response Simulator\n is ready to send the selected response codes to your app.\n\n#### Test your app's error handling\n\n| **Note:** When testing using the Response Simulator, ensure that you first open Play Billing Lab, and then open your app. Opening your app before opening Play Billing Lab may result in issues connecting to the Response Simulator.\n\n1. Open your app.\n\n - If you have allowed notifications from Play Billing Lab, you will see the Play Billing Lab notification icon in your device's status bar which indicates a successful connection to the Response Simulator.\n\n **Figure 3.** Play Billing Lab icon indicating successful connection.\n2. Trigger the Play Billing Library API method you want to test. For example,\n if you want to test the `launchBillingFlow`, initiate an in-app purchase\n flow."]]