How to gracefully handle "verification required" in in-app purchases - swift

Once in a while I see that the alert appears saying that verification is required to make a purchase.
When user taps "Continue" the AppStore opens the payment information view and after filling in the CVV it redirects user back to the app.
However at this point SKPaymentQueue reports an error saying "Cannot connect to iTunes store". The purchase automatically handles in background then.
This is a production environment and it's really hard to catch and test this kind of event and I am not able to reproduce this kind of scenario in sandbox.
Does anyone know how to gracefully handle this scenario so we don't show an error to the user?

Related

PayPal iOS sdk allow user to pay with old credentials even if user changes the password/pin using sandbox

Our iPad app has been processing payments successfully in sandbox mode using v1.0.5 of the iOS SDK. However, we found one defect while testing our application. Please find steps below.
Login into PayPal.
Use email or phone and type in your credentials.
click on send payment. You will see the payment complete screen. Click on done button.
Now open your sandbox account and change the password/pin (Profile->Update password).
Then go to the application and try to make payment again. PayPal sdk navigate you directly to the confirmation page.
Click on send Payment.
PayPal SDK allow user to pay with old credentials(password/pin).
Is this a known issue or I am missing anything?
Also is there any way to log out user after every payment. (Force user to login every time he tries to make the payment without manually clicking logout button).
moka, I think that the scenario you describe is okay as is.
Within your app, the user logs in to her PayPal account, pays you, and chooses to not log out from PayPal.
Later, within your app she remains logged in to her PayPal account, even though elsewhere she has changed her password. And therefore she can still pay you from this account.
That all seems fine to me.
Regarding your second question:
When you call [PayPalPaymentViewController initWithClientId:receiverEmail:payerId:payment:delegate:], the SDK uses the payerId to determine whether this is a new user or a returning user.
So if you change the payerId each time you call the SDK, then each time this will be interpreted as a new user, who will therefore require a fresh PayPal login. (For example, you could set payerId to something like [NSString stringWithFormat:#"%d",rand()].)
-- Dave Goldman (eBay/PayPal/card.io)
Set rememberUser property to NO for PayPalConfiguration instance like this
payPalConfiguration=[[PayPalConfiguration alloc] init];
payPalConfiguration.rememberUser=NO;
It will then ask each time to login.

Change Alert Title In In-app-purchase

I am integrating my iPhone app with PayPal. Now I am taking fixed amount of charge for doing this transection. If user clicks on Pay by PayPal i am asking user to first make an In-app purchase. When user is doing transection for the first there won't be any problem.
But when user has already did transection before, it will display message "You have purchased this. Tap OK to download it again for free" with "Cancel" and "OK" buttons.
I think this type of message doesn't make any sense as its not for downloading app, Can i change it to something like "You have done this transection before. Tap Ok to perform next transection" with "Cancel" and "OK" buttons.
Is there any way i can give custom title or do they have any other pre-define messages for this type of transections?
Thanks In advance.
No, there is no way (nor is there a reason for there to be). Furthermore Apple will reject your app if you attempt to use PayPal to purchase an In-App download.

Detect re-purchase of in-app purchase

How can I detect this situation in code:
User purchase a full version with in-app purchase.
User delete the application from iPhone.
User installed the application again
User purchases full version,
My problem is that in testing, I can see a message box saying "you already purchased...", but in the application updateTransactions not called.
In this situation I need to change to full version. How can I detect this event?
I.e., How can I know in my application that the user already purchased so I will "open" to full version?
Thanks.
Use [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]. It will force your app to receive transactions again.
See docs:
Restoring transactions
- restoreCompletedTransactions

In App Purchase user cancels tx while app in background: tx state stays on purchasing

I have some odd behavior with User canceling in App Purchase (Sandbox Environment) while the app is in background and the user is not yet logged in to the store:
The process is as follows:
User is not logged in/App Id is not set in Settings > Store
User clicks buy button. This calls [[SKPaymentQueue defaultQueue] addPayment:payment];
User immediatly preses home button (app goes to background)
Storekit popup appears asking to confirm purchase. User cancels
App is activated again and would expect to recieve - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions, but does not. The TX is still in state purchasing.
This process is different, if the testuser is logged in to the store already. In that case the above process works as expected.
Another remark: After the above steps, I actually buy another in-App item (inlcuding logging in to the appstore). After this I sent the app to backgrounding and reactivate it and it will process the fomerly missing cancel transaction.
Conclusion:
A user canceling a payment tx while the app is in background and not being logged in to the store results in late delivery of the storekit callback. Delivery is done after the user actually logged in to the appstore and the PaymentQueue process gets triggered by reactivating the app.
This behavior seems to be wrong and if it is actually like that in real environment, I might consider this a Storekit bug. Has someone experienced the same behavior or can indicate something to prevent a tx "hanging" in purchasing state?
Thanks,
Marcus
I don't believe you can count on ANYTHING when it comes to Store Kit. Rather than "waiting expectantly" for the transaction to be queued after the "Buy" button is pressed, just go on about your business. When you are notified that there are transactions (which could be tomorrow) process them. I believe there's a comment to this effect in the documentation -- that your app should register for SK notifications when it's launched and it should expect to get them at any time. So don't build any awareness of "state" into your app when it comes to Store Kit. Just process the transactions as they arrive.

Error Domain=SKErrorDomain Code=2 "Cannot connect to iTunes Store" UserInfo=0x6083900 {NSLocalizedDescription=Cannot connect to iTunes Store}

I am trying to test my in app purchases using a test account. The first time I try to purchase an in app auto renewable subscription, everything goes smooth, no errors and the transaction is complete as expected with the transaction state updated to "SKPaymentTransactionStatePurchased". But, when I test for the scenario of a user trying to purchase the subscription again, I keep getting the above error. Even though the store kit framework displays a dialog saying that the user is already subscribed, my observer sees the transaction as failed in the state(SKPaymentTransactionStateFailed).
The storekit documentation clearly says
"If the user attempts to purchase a nonconsumable product or a renewable subscription they have already purchased, your application receives a regular transaction for that item, not a restore transaction. However, the user is not charged again for that product. Your application should treat these transactions identically to those of the original transaction".
In my case here, I keep getting the transaction state as "failed" when I do the purchase again.
Any ideas? This is in the sandbox test environment.
This is the expected behavior. You still receive a transaction, it just marks it in a failed state because it does not represent a new, successful purchase. Repurchasing a subscription they already subscribe to (presumably to restore a purchase after a fresh install) is not a journey you should encourage your users to take, they should be directed towards the restore purchases function.
Arguably you might want to interrogate your failed purchases every time to see if this is what the user was trying to do, but then you'd have to do a fair amount of messing around to try and distinguish which ones were genuine failures and which one's were erroneous restores. but I'd say it's much easier to have a big 'restore' button and direct people towards that.
If you log out from the app store application, it seems to be working when you purchase again. But problem continues if your user try to purchase the same product twice.
I was getting this when the Sandbox servers were down and/or broken. Check on Apple's developer forum to see if anyone else is getting the same thing.
[Developer Login Required]
http://devforums.apple.com/community/ios/integration/storekit