iOS auto-renewable subscription purchase issue - ios

Here is the reproduce steps of issue:
I tap the "purchase" button in my app.
I enter the password of Apple ID.
Apple show a dialog to confirm purchase or not. And I tap "Yes."
Apple show a dialog to say that I have no payment information, need to complete it.
(This moment I got a transaction with state SKPaymentTransactionStateFailed in updatedTransactions: function)
I tap continue then jump to iTunes app and start to complete my credit card information.
After complete the payment information , apple ask me to confirm purchase again.
I tap "confirm" then the purchase is done.
(Notice that it didn't come back to my app automatically.)
Here is my questions:
Why this flow didn't invoke the callback function I wrote when transaction with state SKPaymentTransactionStatePurchased is coming?
The last one, do I need to finish transaction when I receive transaction with state SKPaymentTransactionStateFailed?

In my experience, if you're in the sandbox and are asked for credit card info, something is wrong. Could you try to log out of your App Store account before you build/run the app? That usually solves it for me. If that doesn't work, you might try deleting the app as well as logging out before running the app again. Are you making sandbox purchases with a test user created through iTunesConnect?
According to SKPaymentTransactionObserver Protocol Reference, yes, you should call -finishTransaction: even for SKPaymentTransactionStateFailed. I do this in my own projects with no ill effects.

Related

In-App-Purchase subscribed state in Swift?

So I have a question about doing an in-app purchase with a subscription in swift. I read at this link: https://www.revenuecat.com/blog/the-ultimate-guide-to-subscription-testing-on-ios#sandbox that you need your app to enter subscribed state. Is this some kind of delegate method or something I call, or does it simply mean that I enable the features? I haven't been able to find much detail on that part. Any guidance would be much appreciated. I do have the in-app purchase dialog appearing and the sandbox account working. I also get the alert saying the purchase was a successful. But even 2 seconds later if I try again it just allows me to purchase again.
By subscribed state they mean that a user still should have access to the content he unlocked with the subscription.
But even 2 seconds later if I try again it just allows me to purchase again.
Unfortunately, it is your responsibility to hide already bought in-app purchases from your users. Although, Apple prevents buying the same subscription again. So, when your first purchases succeeded, the second one should lead to an alert from Apple, that the purchases weren't executed. Otherwise, I assume your purchase logic is faulty.
How do you check the eligibility of your users? Do you validate the receipt locally, or are you using RevenueCat for that?

How is "restore purchase" actually implemented in most apps?

According to Apple doc, calling restoreCompletedTransactions() prompts user for App Store password:
Don't automatically restore purchases, especially when your app is launched. Restoring purchases prompts for the user’s App Store credentials, which interrupts the flow of your app.
I tried quite a few apps but never observed this behavior. One example is bear, a freemium note taking app. When I pressed its "restore purchase" button, it just went ahead to query and then showed an alert saying that there was no purchase information for me.
I wonder how is this implemented? I guess it stores users purchase information on its own server so it queries its own server, instead of App store. But the question is how it identifies me? (Note Bear app doesn't require user to create an account to use the app. I just downloaded the app and didn't do anything in it yet.). I know iOS has DeviceCheck API, but I think that only identifies a device, instead of an user, right?
Thanks for any help.
Note: Bear app's "restore purchase" button can be found by going to its side menu, pressing setting button at the bottom, pressing "get Pro!" button.
You need to be signed in with Apple ID in order to download apps and make purchases, that's how they match it.

When are In-App Purchases activated after app has been approved for sale

I just made my first IOS app which has an IAP option and today it has been approved by iTunes Store. After I got the email, I had to wait another 4 hours before the app actually has been added to the App Store.
After I search for it and download it on my phone I decided to test the IAP option, but it doesn't seem to work. I am using my original Apple ID email and not the one I used for testing.
My question is, if the app has been added to the store, does the IAP has to work ? Or you have to wait awhile ? Just like waiting for the app to be added to the store after it has been approved.
PS: both the app and IAP has been approved by Apple and the status of my app is Ready For Sale.
edit:
If I run my app now from Xcode I get the following output from my code:
About to fetch product
Fetching products
Got response from Apple
Black Edition Theme
Black theme
0.99
Sending the payment request to Apple
Received payment transaction from Apple
Received payment transaction from Apple
Restored
Received payment transaction from Apple
It works how it should, but it keeps asking me for my Apple ID password continually and at some point said Cannot connect to App Store even if everything was successful, and after I click Retry I get the Confirm Your In-App Purchase screen but it also says Environment: Sandbox
I'm really confused why the sandbox screen is appearing.
Apple's servers often lag behind directly after updating an app with a new IAP (the product will not be found by the API). Waiting a few hours usually resolves the problem. We've had this with every new IAP we added.
You say the IAP "doesn't seem to work" ... what do you mean by that? You are charged for it, but you don't get the new content / feature / whatever it is? Or you select Purchase in your app but nothing happens?
It's been a while since I worked with IAP, but back when I did you had to submit at least one IAP component at the time you submitted your app for review. So both were reviewed at the same time.
If that's what you did, the IAP should be available immediately - if it's not, yeah... something's wrong.

In app purchase prompts sign in on app startup

I am using StoreKit for in app purchases in my iPhone game. The purchases all work correctly, however I am constantly being prompted when the app is opened to sign into an account which does not exist anymore.
I had one sandbox account that I used until I was getting an error in which pressing 'restore purchases' was restoring the purchase even if the user pressed 'Cancel' on the modal popup. Because of this I created a new sandbox account to try and restore purchases from an account which had not made any purchases. Unfortunately restore purchases still worked in this situation which is of course a problem. I thought it could be an issue with the old sandbox account still being on the device somewhere so I deleted it. For some reason, every time the app starts, I am still prompted to sign into this test account that has been deleted.
Research has lead me to believe that maybe somewhere a transaction was not finished and so it is trying to complete it every time the app starts? Does this sound plausible?
If you would like to see my code, let me know and I will update.
Edit: I have of course tried deleting the app and reinstalling and also signing out of all accounts along with a reboot of the device.
Research has lead me to believe that maybe somewhere a transaction was not finished and so it is trying to complete it every time the app starts? Does this sound plausible?
Not just plausible, but likely. Hack your app to call finish on all transactions regardless of actual completion state, then un-hack it.
To solve this I finally signed into the account it was prompting me to sign in to and then went through and purchased all of my IAPs again manually, this reset whatever hung action there was and fixed the issue.

Non-Renewing Subscription Already purchased alert track

I am implementing Non-renewing subscription IAP in my app where I am making server implementation to expire a subscription. I am stuck when I click on a subscription I already have bought, It shows a dialog, "This In-App purchase has already been bought. It will be restored for free." with OK button. I have two questions here:
Sometime it shows the above dialog but sometimes it shows "Tap buy to renew or extend it." dialog. Can anyone tell me whats reason behind this? Or it is just a Sandbox issue. (This screenshot from another thread.)
When I get "This In-App purchase has already been bought. It will be restored for free." alert, how i can stop activity indicator? Is there a delegate method to track this?
I could not found but is there anything new came in iOS 8?
Thank you
For a non-renewable subscription, the correct dialog is "Tap buy to renew or extend it.". The reason for this is that once a non-consumable product is owned, it is owned permanently; hence the "renew or extend" language.
You are getting this dialog because you are attempting to purchase the same product again before completing the transaction on the app's side. The App Store has approved the transaction and sent you a transaction ID, but you have not confirmed that you have delivered the promised content/access. Thus, the transaction is left in the approved state. The transaction remains tied to the app until you finish it.
See "Finishing the Transaction" in Apple's (confusing, convoluted) documentation.
I met this problem in consumable IAP, and I have called the function [[SKPaymentQueue defaultQueue] finishTransaction:transaction]. Then I found that there is a exception occurred in a function before the call, then I exchange the position of two function, the problem is solved now.

Resources