How to test In-app purchase in Sandbox mode iOS? - ios

Am new to In-app purchase integration in iOS application. I have done the coding in the project level and I have created a Sandbox user in iTunes Connect. I read many tutorials and Apple Document to test the In-App purchase in DEV mode.
As per the document I have removed the APPLE ID from iPad Settings and launched the app from Xcode. But, I didn't received the Account Alert from the app. Also, my products are returning empty in SKProductRequest delegate method didReceiveResponse. I have posted my code for your reference. Can you please help me on this? Am working since last two days. Please help me. Thanks in advance.
- (void) getAvailProducts
{
NSLog(#"Fetching Available Products");
NSSet *productIdentifiers = [NSSet setWithObjects:#"com.test.testios.monthly", #"com.test.testios.yearly" ,nil];
self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
self.productsRequest.delegate = self;
[self.productsRequest start];
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
//SKProduct *validProduct = nil;
DebugLog(#"\n Products: %#", response.products);
NSUInteger count = [response.products count];
NSLog(#"Request Count: %lu", (unsigned long)count);
if (count > 0)
{
self.validatedProducts = response.products;
DebugLog(#“\n Products: %#", response.products);
self.validationCheck = TRUE;
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
// Check subscription
}
else
{
// No products found….
}
}
Also, I tried with "monthly and yearly" instead of "com.test.testios.monthly and com.test.testios.yearly". But, no results.
Edit: Am getting the mentioned ProductIds are invalid in the following code,
for (NSString *invalidProductId in response.invalidProductIdentifiers)
{
NSLog(#"Invalid product id: %#" , invalidProductId);
}

Thank you all.
Fixed the issue and tested the In-App purchase in Sandbox environment. Following items fixed my issue,
1. iTunes Agreement was not accepted.
2. Tax and Payment details was not added.
3. Added correct Product Identifier in project.

Related

Empty Auto-Renewing iOS In-App purchases from SKProductsRequest initWithProductIdentifiers

I've made an iOS in-app Auto-Renewable Subscription, now I'm trying to allow users to purchase it in a React-Native app.
I've found react-native-in-app-utils, but can't seem to even load my products. I have 3 "products" (auto-renewable subscriptions) in iTunes connect, but trying to load them with:
var products = [
'com.xxxx.app.monthly',
'com.xxxx.app.6months',
'com.xxxx.app.year',
];
InAppUtils.loadProducts(products, (error, products) => {
console.log('products:', products);
});
just logs "products: []".
Digging a little deeper, I've added some additional logging to the objective-c code doing the querying, and it looks like:
NSLog(#"loading products %#", productIdentifiers);
if([SKPaymentQueue canMakePayments]){
SKProductsRequest *productsRequest = [[SKProductsRequest alloc]
initWithProductIdentifiers:[NSSet setWithArray:productIdentifiers]];
productsRequest.delegate = self;
_callbacks[RCTKeyForInstance(productsRequest)] = callback;
[productsRequest start];
} else {
callback(#[#"not_available"]);
}
Then in the callback:
NSLog(#"products response %#", response.products);
products = [NSMutableArray arrayWithArray:response.products];
NSMutableArray *productsArrayForJS = [NSMutableArray array];
for(SKProduct *item in response.products) {
NSDictionary *product = #{
...
This will log "loading products" with my product ids, as expected. But then "products response ()"... empty response.
Those products are listed in iTunes connect as "Ready to Submit". And they've been added to the app info under In-App Purchases. What gives? Why aren't the products showing up?
Looks like it was an administrative issue, not a technical one. Project Manager hadn't put through the paid app agreement.

Issue with InApp purchase in Sandbox mode: SKProductsRequest delegate returns inconsistent response

When requesting for in-app auto renewable subscription products from apple, I sometimes get valid products but most of the times I get invalidProductIdentifiers in SKProductsResponse object. I wrote a small piece of code to verify this inconsistency in response:
-(void)viewDidAppear:(BOOL)animated{
[self getProductsFromApple];
}
-(void)getProductsFromApple{
SKProductsRequest *_productRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:#"2"]];
[_productRequest setDelegate:self];
[_productRequest start];
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
NSLog(#"Invalid %#", response.invalidProductIdentifiers);
NSLog(#"Valid %#", response.products);
if (response.invalidProductIdentifiers && [response.invalidProductIdentifiers isKindOfClass:[NSArray class]] && response.invalidProductIdentifiers.count) {
[self getProductsFromApple];
}
}
This sometimes succeeds after n calls to apple server.Our team has escalated the issue to apple, we are waiting for there response.
Has anyone faced this issue, kindly suggest how you were able to test in-apps payment ?

In-App Purchase Product Request Method Needs Two Calls

I currently have created a series of methods that call and return In-App Purchase products that I have created. I can call the SKProductRequest without issue, I can even purchase the item and receive a successful purchase notification (SKPaymentTransactionStatePurchased).
The issue is that for whatever reason, when I initially run the app, I have to call the following methods 2 times in order to receive a non-null response from Apple:
/// In app purchases
- (IBAction)BuyProduct:(id)sender {
if ([SKPaymentQueue canMakePayments]) {
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:_productID]];
request.delegate = self;
[request start];
} else {
NSLog(#"Please enable In App Purchasing in your settings");
}
}
#pragma mark _
#pragma mark SKProductsRequestDelegate
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
NSArray *products = response.products;
if (products.count != 0) {
NSLog(#"Products available: %#", _product.localizedTitle);
_product = products[0];
} else {
NSLog(#"Products not found.");
}
products = response.invalidProductIdentifiers;
for (SKProduct *product in products) {
NSLog(#"Product not found: %#", product);
}
}
Every time, the first time I call the BuyProduct IBAction i receive this:
(excuse the dashes - simply clearing my personal info!)
---------- --.07.55.823 -------[2474:827710] Products available: (null)
Then the second time and onwards that I call the same IBAction button, I receive the IAP name correctly,
---------- --.08.03.142 -------[2474:827710] Products available: TEST IAP
---------- --.08.04.455 -------[2474:827710] Products available: TEST IAP
SO, I am just trying to figure out why I need to call these methods 2 times in order for Apple (or my code) to successfully return my IAP product name. If anyone could help me out I would greatly appreciate it!

IOS in-app purchases stopped working suddenly, fetching null identifiers

My in-app purchases were working until yesterday and today I am submitting my app for review. The only change that I made is that in the app page in the iTunes, I connected my app (by checking) with the in-app purchases.
From that time, every time I try in my debug app to buy something with my test account, I am getting this error:
NSInvalidArgumentException', reason: 'Invalid product identifier: (null)'
I have already:
re-installed my app
logged out from my store and used again my test account
but today nothing seems to work. The exact same code was working perfect yesterday, with the same test account.
May it be because I did this change in itunes? I am worrying what would happen when my app gets approved and goes online.
Any help is greatly appreciated.
EDIT:
The problem is that the array _products stays nil.
- (void)reload {
_products = nil;
NSLog(#"reload is called");
[[VimaIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
if (success) {
_products = products;
NSLog(#"Success from AppStore");
}
}];
for (SKProduct* product in _products) {
NSLog(#"In-app item:%#",product.localizedTitle);
}
}
The Success log message is never called. Yesterday I had no problem, with the same code.
EDIT:
after a lot of tries, it works. Without changing anything. It seems that the server takes a lot of time to respond back. However, I cannot buy the product since I get an "cannot connect to itunes". Why that might happen?
EDIT2:
In other tries, the problem seems to be in this code:
pragma mark - SKProductsRequestDelegate
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
NSLog(#"Loaded list of products...");
_productsRequest = nil;
NSArray * skProducts = response.products;
for (SKProduct * skProduct in skProducts) {
NSLog(#"Found product: %# %# %0.2f",
skProduct.productIdentifier,
skProduct.localizedTitle,
skProduct.price.floatValue);
}
_completionHandler(YES, skProducts);
_completionHandler = nil;
}
after the for loop. Especially, I get a BAD_ACCESS in line: _completionHandler(YES, skProducts);
A problem with the Xcode 5 simulator has been reported but not fixed. See this post describing the situation.
Actually the problem was that during these days the whole Apple Dev Center was down, so the above code is working for anyone else who is looking for an example.

Still getting invalid product identifiers... iOS

I keep getting invalid product identifiers as a return from in app purchase product requests.
I've checked the following:
Checked provisioning profiles, deleted and re-made several times...
Checked product identifiers against products in itunesconnect (uk.co.companyname.appname.product_name).
Deleted app and provisions from phone and re installed.
Logged out of app store on phone.
Checked my code signing (signed as iPhone Developer (with uk.co.companyname.appname as identifier)
Made sure app identifier is in info.plist correctly.
Submitted and rejected app binary.
Running on phone, not simulator.
This is my code for fetching products:
- (void)loadProducts
{
NSSet *productIdentifiers = [NSSet setWithObjects:uk.co.companyname.appname.product_name, uk.co.companyname.appname.product_name2, uk.co.companyname.appname.product_name3, nil];
for(NSString *pk in productIdentifiers) NSLog(#"%#", pk);
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
productsRequest.delegate = self;
[productsRequest start];
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSLog(#"products: %d", [response.products count]);
NSLog(#"invalidProductIdentifiers: %d", [response.invalidProductIdentifiers count]);
}
and I get:
products: 0
invalidProductIdentifiers: 9

Resources