Testing Android inapp subscription: You already own this subscription - android

I am testing Android inapp subscription with a test account, after I entered a real credit card to buy, the subscription is ok, but I cannot find the token in the json response.
So in the developer console, I cancelled the order, when I try to re-subscribe again, it now show me the alert "You already own this subscription".
When I click the "Detail" in the box, it opened the Play Store app, but showing "Item not found"
Anyone experienced this error before?
Thanks.

i guess you might have solved the problem but take a look at this question Subscription sample missing JSON parsing of purchaseToken it this might be the case for JSON.
The reason you cannot re-subscribe i think is because you are already subscribed for that period. Your subscription will end when the billing cycle ends.

Howard, the reason is that a subscription is active even after you cancel until the subscription period. It will continue to say that until the original subscription expires. I know, the Android implementation of subscriptions is really really kluegy. I've implemented in-app subs successfully on Android and have a lot of similar issues and one of them was you cannot re-purchase after cancelling if the item hasn't expired from it's original purchase date.

Related

How to handle subscription repurchase scenario in android in-app purchase?

I am maintaining and updating the subscription state through the real time developer notification.
When an user purchased a subscription in app, my server is called to link the purchase with the user.
Whenever user repurchases a subscription after expiry, I get a notification from Google pub-sub in my server as a "SUBSCRIPTION_PURCHASED" notification. I just don't know to which user I have to link this purchase? Since the repurchase is happening from the play store and it has no link with the app, I am unable to register the subscription to the user. Kindly please help me.
Just to clarify the different cases, even if I know that's not what you're asking for here :
whenever a subscription expires on the Play Store because of a payment issue, it enters in a grace period (if you havent deactivated this feature). If the payment method is not fixed, the subscription enters into an "account hold" period (30 days) where any payment method resolution or re-subscription will bring back the subscription. In this case, you'll receive a SUBSCRIPTION_RECOVERED S2S notification with the purchaseToken known by your server and everything should work just fine (more on this here: https://developer.android.com/google/play/billing/subscriptions#account-hold)
in your case, the user has re-purchased the subscription in another context than an "account hold", that's why you'll have an unknown purchaseToken and you won't be able to associate the subscription with any user. I'm afraid in this case, you can't do much.
The only solution for your user is to "restore" his subscription within your app. In another words, you should add a link in your Paywall which, when clicked, will retrieve the subscription from the Play Store and send them back to your server (like for a normal purchase). Your server will detect the new subscription and will linked the subscription to the correct user.
Here is an example of a Paywall with this restore link:
You could thought that it would be a good idea to always look in the Play Store for subscriptions when your app launch... and whenever your detect a subscription that isn't attached to your user, send the receipt to your server to attach the subscription to your user. It would be an error though since a same device can be used by 2 persons and one user would "steal" the subscription from the other.

How to handle pending purchases from Google Play

Most of our purchases keep getting canceled after 3 days 30 minutes exactly, which I presume is the result of pending purchase state. However, there is so little documentation about how to handle pending purchases exactly. And, for some reason, even though I am a tester myself, I cannot test it because there is no "Slow card" option on purchase methods. Also, we do not have a backend server to well, back us up.
This is the explanation I've found from the official documentation:
void handlePurchase(Purchase purchase) {
if (purchase.getPurchaseState() == PurchaseState.PURCHASED) {
// Acknowledge purchase and grant the item to the user
} else if (purchase.getPurchaseState() == PurchaseState.PENDING) {
// Here you can confirm to the user that they've started the pending
// purchase, and to complete it, they should follow instructions that
// are given to them. You can also choose to remind the user in the
// future to complete the purchase if you detect that it is still
// pending.
}
}
Look at the explanation on the PENDING state. What does "To complete the purchase, they should follow instructions that are given to them" mean? What are these instructions exactly? Do we need to redirect the user to Google Play or what? It is not specific about what to do and is bugging me out because purchases are getting cancelled for no reason, or for this reason. How does one complete a pending purchase? There is nothing about it, or I cannot find it, hence I ended up here.
I hope you can help me figure this out. Thanks.
I agree the documentation is poor, especially since the one time you want to know exactly what's happening is when you're handling other people's money!
It looks like a 'slow card' transaction is actually a 'pending purchase', something Google have been rolling out in 2019. Here's the probable flow...
In your app the user taps 'Buy now'
They see the Google checkout overlay
They choose "Pay at Freddina's Grocery, Accra" (a local store that's signed up to deal with Google pending purchases)
Google checkout displays a code to show to Freddina
User pays Freddina in cash and Freddina processes the payment using that code
10 mins or so later, the purchase update will land in your app
As for handling unpredictably timed update events, we have an app with a handlePurchaseUpdated method listening out from the moment the app starts, and makes changes based on the Purchase object that comes with it. Here's an example flow:
We listen for purchase updates as soon as the app starts up
User makes a slow purchase
We get a purchase update
The passed Purchase object has purchase state PENDING
We tell the user that we'll notify them when the purchase is complete
At some point in the future (e.g. next day after an app restart) the purchase update comes in
If the purchase state is now PURCHASED we finalise the purchase and tell the user
Note: Ours is a ReactNative app, not native java, but the flow should be the same.
It's complicated to implement because you have to pick your time to make your purchase changes and display the purchase result at a time that makes sense, not necessarily when the purchase update arrives 5 secs after startup (or any other weird time). And it gets more complicated if there are errors during your grant-entitlement or acknowledgement steps, urgh.
Also, you might not be seeing the 'slow card' tester option because you didn't allow it?
Update for 2022: Personally I feel the documentation is still so poor, and the complexity so great, that I would recommend using a service like IAPHUB to manage iaps and subscriptions.
It sounds like you are not acknowledging the purchase. See below from the Google Play Billing documentation:
If you use the Google Play Billing Library version 2.0 or newer, you must acknowledge all purchases within three days. Failure to properly acknowledge purchases results in those purchases being refunded.
According to Google's documentation (https://developer.android.com/google/play/billing/integrate#pending), you need to call enablePendingPurchases() and then your PurchasesUpdatedListener will be notified when the state changes from PENDING to PURCHASED.

testing subscriptions - can't cancel

I have my in-app subscription working using a second test account. Now when I check inventory using queryInventoryAsync the subscription shows up as expected.
So now I want to do some more testing. I want to cancel the subscription and then when I know that works, I want to test again.
However, when I go to Google Play -> My Apps on the same phone as I used to buy the subscription, it shows no subscriptions! So I can't cancel it. What is wrong?
Also, how can I test expiration of subscription and make Google think time has passed.
Thanks,
Gary
Turns out that Google does not support testing of subscriptions. You have to use real charges.
To cancel the subscription have to go to the Google Wallet web. It's the only way, you can't do it in-app.
To testing process. You can use a subscription with trial time, in this way you haven't to pay until this trial time finish and you can test at least the purchase flow.
Also you "only" have to wait a week to see the subscription expired, and without make a refund if you had cancelled before.

Playstore subscriptions - testing strategy

Scenario:
I am on the verge of completing my google playstore in-app billing implementation. I am using a monthly or yearly subscription in order to charge my consumers.
Problem: I can't seem to find a way to remove a subscription from active state, since cancellation simply stops the billing from occurring. This doesn't allow QA to thoroughly test the purchase procedure without creating an account for each test, or waiting until the subscription period ends.
Question: Have I missed or am wrong about something? If so, what is it? If not, what should be done to allow QA to do proper testing?
According to what I have understood from your question,
you can not test subscription from the test account. Google play doesn't provide subscription testing using dummy product. you have to test on the real product.
Now question arises how can I test subscription
you can check subscription by purchasing real product and check product status or purchase cancellation using the purchase status api from your server.
you can also get more information from the given link below for the step by step cancellation purchase status:
1) link1
2) link2
you can simply query every day and check your subscription is valid or not and also get it's expiration date.
I also have one other option with out pay for any charges on your real product, you can set trial period in the Google console and before trial period ends up cancel subscription from the Google play store Menu -> MyApp -> Subsciption and cancel product and check above procedure given in the links.
EDIT:
Important: In all cases, you must continue to offer the content that
your subscribers have purchased through their subscriptions, for as
long any users are able to access it. That is, you must not remove any
subscriber’s content while any user still has an active subscription
to it, even if that subscription will terminate at the end of the
current billing cycle. Removing content that a subscriber is entitled
to access will result in penalties. Please see the policies document
for more information.
more information check below links:
1)
http://developer.android.com/google/play/billing/billing_subscriptions.html#cancellation
2) https://support.google.com/googleplay/answer/2476088?hl=en
3)
https://support.google.com/googleplay/android-developer/answer/140504?hl=en
You can not done this with out waiting until the subscription process cycle completes after cancellation of subs product, the only way remaining which is Free trial version it's only the way to provide us to test for the product cancellation in which product cancel immediately after you cancel subscription trial period, it will not continue until even trial periods ends.
more information check below link:
http://developer.android.com/google/play/billing/billing_subscriptions.html#administering
And I think it is better way because in the trial period you should go
with the actual credit card payment process but you doesn't need to
pay anything for it. Google play record the transaction as $0.00 for
the subscription process. And if you cancel the subscription the you
should not pay anything for testing, but yes I am not sure free trial version
is worked before you publish the app but it is only get by efforts only.
Conclusion:
In the current api it is not possible to test subcription product like
normal products and if user has been cancel the subscription product
then you have to wait to purchase the same product until the
subscription cycle has been expired, there is no another way if the
subscription cycle is going on and you can test for the same product
again before subscription cycle ends. And if you still want to test
for the same product then you have to choose another account for
testing it or another way is Free trials, you will not be any charged
until your Free trials period expired or cancel subscription in that
period and for the testing account before publish the app you will be refunded
automatically after 14 days of purchased product according to my
knowledge.
Hope it will solve your problem.
I have a horribly clunky workaround for this problem. Here is what I do every time I want to do a test of in-app subscriptions:
Create a new in-app subscription product in the google play developer console.
Point the android app at the new subscription product you just created.
In your code to check for active subscriptions, add a line to specifically ignore the order number of the previous subscription that you tested.
Export a release build of the app and transfer it directly to your testing device.
After testing, return to step #1 to test the next time.
Don't forget to fix your change from step #2 before deploying the app!
You might want to create many subscriptions in step #1 so you don't have to continually wait hours for them to propagate. Please comment if you know of a better way!
UPDATE: Google now has test subscriptions and is making it easier to use them! https://android-developers.googleblog.com/2018/01/faster-renewals-for-test-subscriptions.html
It seems that nowadays there is better solution:
Open your app page in Google Play Store application
Click "Manage subscriptions"
Click "Cancel subscription"
Go to "Settings", "Apps" in your phone.
Find Google Play Store and clear application data.
You should now be able to re-buy subscription.
Create a mock class that mocks out the Google Play methods that you are using.

IAB Error You already owned this item

I'm now developing a small game with Google's in-app billing service.
And I reference to Trivial Drive of Google's sample project.
Let's me ask you about connection interruption during Purchase Items from Google Play.
It's OK when launching purchase flow with normal internet connection.
I tested like this.
As soon as purchase flow is launched, disconnect the internet connection (by unplugging the routers' LAN).
After about 2-3 minutes, It shows Connection time out.
In merchant account, Money transfer is done.
But when I query All owned items, there is no owned item of this ID (purchased recently).
And when I try to purchase again this item, It shows "Error You already owned this item".
How can I solve this problem?
Anybody encountered like this problem?
Please Help. Appreciate to all comments and helps. Thanks.
The Google IAP flows requires you to call a consumePurchase() API after doing a purchase.
What you need to do is to call the getPurchases() API, this will return a list of purchases along with a purchaseToken. Then you need to iterate through them and call the consumePurchase() API for the purchased, unconsumed products.
For more reference, look at the API reference.

Categories

Resources