I came across In-app Billing Library ( using BillingClient )and In-app Billing API (using IInAppBillingService ) both use to manage subscription, My question is which has to be used in what circumstance.
I am testing with In-app Billing API and checking the subscription status on Splash Screen of the app.My logic is simple, use getPurchases() method to obtain purchased status.If getPurchases() returns empty I considered "Not Purchased State" otherwise "Purchased State".Will this solve in the event of below criteria?
1.Deferred Billing
2.Purchase Expires
If a recurring payment fails (for example, because the customer’s credit card has become invalid), the subscription does not renew. The getPurchases() method does not return failed or expired subscriptions.
Does that mean
Bundle ownedSubscripedItems = mService.getPurchases(3, getPackageName(), "subs", null);
ArrayList<String> purchaseDataList =
ownedSubscripedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
Will the purchaseDataList array be empty for expired subscriptions?.
And what will be the response to Deferred billings?.How to check that this subscriber enjoys deferring billing.Will the response for them be same as normal subscribers?
Developer docs say
The library is a wrapper for the Android Interface Definition Language (AIDL) file that defines the interface to the In-app Billing service https://developer.android.com/google/play/billing/billing_library.html
Then both are basically the same thing. I personally use the AIDL directly
For Deferred Billing if the deferral period expires without payment then getPurchases will return not purchased, the same will happen for any not renewed subscription.
Don't forget to verify signature for any purchase returned by getPurchases() !, and better to verify with some library different to standard java.security or even better with a external signature verifying server.
UPDATE
The main difference between using the AIDL or the library is that the library uses asynchronous operations and a listener is called when completed.
Instead some of the AIDL methods works synchronous and will block the calling thread. That means if you use AIDL directly better to call it in a separated thread, that's what i do personally. Both ways do the same, but in a different way.
Advantage ? use the one you like more, if you are used to work with separate threads I recommend AIDL.
If your doubt is if getPurchases() will switch from to return item owned to item NOT owned when a subscription expires or referral time expires without payment the answer is yes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With