Skip to content Skip to sidebar Skip to footer

Play It Again Sports Billings Mt

Testing in-app purchases on Android

An addendum to the official documentation

Overview

Monetization is one of the most important aspects of distributing your production to the rest of the world. It tin can make or break a small freelance developer or an established startup.

Android, being so widespread, provides ways for users to buy products from inside your app: this is referred to as In-app Billing. Through this prepare of APIs, developers tin offer two types of products:

  • Managed in-app products
    As the name suggests, these products are managed by the programmer, and they branch into consumable and non-consumable. A consumable production is unremarkably temporary and, in one case consumed, can be bought once again, whereas a non-consumable product is a one-off do good that the user will continue having in your app.
  • Subscriptions
    These products come with a validity flow (days, months, weeks, years) and are automatically renewed at the end of each billing wheel. When a subscription is not renewed, the production is no longer agile for the user.

The official documentation is very helpful when it comes to the beginning steps for adding in-app products to your application. In detail, the "Selling In-App Products" training is well structured and walks you through each required step:

  1. Adding the Play Billing Library to your app (also check out this article by Joe Birch)
  2. Configuring the products in the Google Play Console
  3. Testing the in-app products in your app

Allow's focus on the third point.

Testing, according to the documentation

According to the documentation for testing, we have two ways of testing purchases:

  • Static responses from Google Play
    By using a restricted fix of product IDs, you lot can trigger static responses from Google Play, then you can test that your app correctly handles all the possible states. You lot should use this when integrating the Play Billing Library into our app, or for instrumentation testing.
  • Exam purchases
    A Google account whitelisted as license-examination in the Play Console will be able to make purchases without being actually charged. Yous can apply this when the app goes to QA, or for general testing.

Static responses

Using static responses sounds easy enough, correct? Yous only employ one on the post-obit product IDs during a purchase operation:

  • android.test.purchased
  • android.examination.canceled
  • android.test.refunded
  • android.test.item_unavailable

and the Play Store will respond accordingly. The lawmaking looks roughly like this:

          mService.getBuyIntent(3, "com.example.myapp", "android.exam.purchased", PRODUCT_TYPE, developerPayload);        

However, if you are testing subscriptions, you're out of luck:

Note: If you're testing subscription purchases, you must employ the product ID of an bodily subscription, not a reserved product ID. [Reference]

This means that we cannot rely on static responses to test subscriptions; instead, we need to resort to exam purchases.

Examination purchases

Past using the so-called In-app Billing Sandbox, nosotros can enable admission to test purchases. These are the closest thing we have to actual purchases, with a few notable exceptions:

  • You are not being charged any corporeality for the product you purchase
  • If you're buying a subscription, the billing menstruation recurs on a daily basis, regardless of the duration configured in the Play Panel
  • You accept manual control over the response for each purchase

The last point is specially interesting, because we take 2 ways of customizing the test buy behavior.

The showtime method allows for fine control over the licensing behavior for all the testers: for instance, by leaving it to RESPOND_NORMALLY we have a beliefs like to the existent one.

The second method, on the other hand, allows for coarse control over the response of the fake credit carte: yous can decide whether the carte du jour volition always approve the purchase or always decline it. Intuitively enough, this 2nd method tin can be customized by each tester.

In order to exist eligible for test purchases, there are a few steps to go through:

  1. Your APK must be uploaded to the Play Panel (drafts are no longer supported)
  2. Add license testers in the Play Panel
  3. Have testers join the alpha/beta testing group (if bachelor)
  4. Wait 15 minutes, then start testing

Sounds easy enough, right? The documentation is also very encouraging

Information technology's easy to set test purchases [ane]

…Sure, let's see nearly that. 😒

Testing, according to real life

You religiously follow the documentation, wait 15 minutes (go far 30, only in example), you lot start testing and…an error occurs. What at present?

It turns out that the documentation is fairly optimistic when explaining the required steps for testing in-app purchases. According to this StackOverflow answer, which in plough is a drove of various trial-and-errors by other users, plus my personal experience, there are actually ten+ conditions that you need to meet or business relationship for before being able to properly apply examination products!

Let'south epitomize them here:

  1. Your app is published (i.e., not in draft).
  2. The APK must be published (either production, blastoff or beta channels).
  3. The APK you uploaded matches the one you lot're testing with when it comes to version code, version proper name, and keystore signature (this point, in my experience, is non needed).
  4. When testing on the device, you're using a different business relationship than the one tied to the Play Panel (i.e., non your developer business relationship).
  5. The instructions to await xv minutes are a scrap too optimistic, as it can take up to ii hours for changes to propagate from the Play Console.
  6. Double bank check that the SKU you're using in the app matches the 1 for the product that was configured in the Play Panel.
  7. Double check that you're not trying to purchase an already owned product or an already active subscription.
  8. Double check that you have activated your products in the Play Panel: by default, products in the console are deactivated and y'all demand to manually activate them.
  9. If you're using the alpha/beta channels, brand certain that the account you're testing with is part of the testing grouping (i.e., has clicked on "Become a tester" after following the opt-in URL).
  10. If you use ABI flavors, similar arm-v7, arm-v8, etc., make sure the APK y'all're using for testing contains all the ABI libraries.
  11. Make sure that, when retrieving the Intent using getBuyIntent, yous're passing the correct product type, i.e., inapp if you're purchasing managed in-app products or subs if y'all're purchasing subscriptions.
  12. If you're using the public key for enhanced security, brand sure it matches the i on the Play Console because information technology might alter over time (see here).
  13. Bank check that Google Play Services are updated on the test device by going to the Google Play Services page on the Play Store.

Every bit you can see, the sandbox is far from straightforward when it comes to existent usage, but at least now nosotros have a few extra hints to start looking for a solution!

Bonus tip: faster testing for exam subscriptions

We mentioned before that test subscriptions have a one-day expiration period, regardless of their original duration. This means that, fifty-fifty if we cancel the subscription, information technology will nevertheless be considered active for that day. In turn, when the app retrieves the list of purchased products, it will receive the cancelled subscription and present it as an active subscription (because information technology technically however is). Your UI will then react accordingly and display premium features, instead of the purchase button: again, technically right, but very inconvenient for us to exercise quick testing.

However, there's a nice way of checking whether a subscription'due south auto-renewal has been cancelled: the autoRenewing field inside the INAPP_PURCHASE_DATA JSON payload that comes from the billing service (see documentation). When checking the validity of a subscription in a debug surround, yous tin assume that when autoRenewing is false the subscription is cancelled and you tin buy another ane.

⚠️ Exist careful though! This cheque should just be done in debug/staging environments and not in production, and then brand certain you limit this "strict" check to debug/staging builds only. ⚠️

Update! 17/01/2018

While this mail service was still being drafted, Google announced that test subscriptions volition no longer be renewed daily. Instead, the renewal period will vary from 5 to thirty minutes, depending on the original billing period.

In addition to this, they are limiting the amount of times a test subscription can be renewed to vi (it is currently unlimited).

All these modifications will be applied starting February 20th 2018.

Conclusion

While far from perfect, the in-app billing support is critical for the Android ecosystem to grow and to beingness able to generate revenue.

When implementing purchases in your app, it's worth paying attention to the checklist we reported before to avoid headaches, every bit well equally provide a reliable sandbox environment for you to develop with and for your testers to test the app.

It's likewise overnice to run into that Google is committed for the long run, as they just released the all new Play Billing Library (compared to the old 2013 version!).

A final shout out to the Android community, for existence as open and as supportive as ever!

hunterlapp1972.blogspot.com

Source: https://medium.com/bleeding-edge/testing-in-app-purchases-on-android-a6de74f78878

Post a Comment for "Play It Again Sports Billings Mt"