hyochan / react-native-iap

In App Purchase module for React Native!
https://react-native-iap.hyo.dev
MIT License
2.84k stars 647 forks source link

Hi. Is there a way to get the list of subscribed plans for the user. #17

Closed ankurToko closed 6 years ago

ankurToko commented 6 years ago

Hi. Is there a way to get the list of subscribed plans for the user so that we do not display the subscription UI if the user is already on a paid plan.

hyochan commented 6 years ago

@ankurToko sure you can in Android but ios, I think it is not fully supported at the moment. @JJMoon will answer your question soon.

ankurToko commented 6 years ago

@dooboolab @JJMoon Yeah, I had the ios usecase. Any work around or solution?

JJMoon commented 6 years ago

Please refer the Apple document : https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/Subscriptions.html

I will implement regarding this in the near future.

hyochan commented 6 years ago

@ankurToko @JJMoon getPurchaseItemsAndroid(inapp : string) We are missing above method currently for IOS. Also looking for the contributor!

ankurToko commented 6 years ago

Hi @JJMoon @dooboolab

Is there some breaking change in the RNIapIos.m file? The code that was working earlier now shows exception here

NSDictionary *dic = @{ @"productId" : theProd.productIdentifier, @"price" : theProd.price, @"currency" : theProd.priceLocale.currencyCode, @"title" : theProd.localizedTitle, @"description" : theProd.localizedDescription, @"localizedPrice" : localizedPrice };

This is the exception

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[3]' *** First throw call stack: (0x1924befe0 0x190f20538 0x1923a59b4 0x1923a5824 0x10070ca98 0x10070b578 0x19f58d320 0x10106da50 0x10106da10 0x101072b78 0x19246d0c8 0x19246ace4 0x19239ada4 0x193e05074 0x19864ec9c 0x100021054 0x1913a959c) libc++abi.dylib: terminating with uncaught exception of type NSException

hyochan commented 6 years ago

@ankurToko It would be better if you paste your js codes here too so we can tell what is going wrong.

ankurToko commented 6 years ago

@dooboolab There you go. Just the simple buy stuff.

RNIap.getItems(itemSkus).then(items=> { console.log("get items called: ", items); RNIap.buyItem('xyz').then(receipt=> { console.log("bought items: ", receipt); }).catch(errorCode=>{ console.log("ErrorCode: ", errorCode) })} ).catch(error=>{ console.log("Error: ", error) })

hyochan commented 6 years ago

@ankurToko Is item called? I mean can you see the logs? If you do, in which line does the crash occurs? If you got crashed in RNIap.getItems(itemSkus) then I suspect your item has not been set properly in itunesconnect. Could you check that?

Also to be sure we need to see what you put in itemSkus as long as your in app product status in itunesconnect.

ankurToko commented 6 years ago

@dooboolab I get the correct valid product count and the product ids get listed correctly. Also earlier it was working fine, but then recently i tried upgrading the library, but that didnt work out. After that when I tried rolling back to the older version that I was using, it showed this error to me. Earlier I was using 0.1.10

hyochan commented 6 years ago

@ankurToko If you see the Readme, you can see what has been changed critically. How is your import statement done? Just said, we need more information to guide you. Please review my previous comment too.

Also if you read the error message in xcode, you are attempting to put nil in it. Therefore you should look in to variables you put into as parameter something like itemSkus.

ankurToko commented 6 years ago

@dooboolab

Import statement is import * as RNIap from 'react-native-iap';

The code stops here NSDictionary *dic = @{ @"productId" : theProd.productIdentifier, in RNIapIos.m

My itemSkus is

const itemSkus = {
  ios: [
    'xyz',
    'abc',
    'pqr',
  ],
};

My in-app products in the iTunes are correctly configured as i get them in the valid Product count in the logs and also it used to work until i tried upgrading.

Currently I am on 0.2.0

hyochan commented 6 years ago

@ankurToko Looks you've updated to 0.2.* correctly. Can you tell where it exactly is crashing? Is it when you buyItem or when you getItems?

Feels you've used wrong parameter during buying item. Also there was critical bug in 0.1.15 in ios module, and please avoid using it if you've tried that too.

JJMoon commented 6 years ago

Are 'xyz', 'abc' product IDs? You should not use Identification Infomation. And usually the ID use same notation with bundle id, like prod.second.mysite.com etc

ankurToko commented 6 years ago

@JJMoon I have just masked those values. And as mentioned earlier, it was working earlier and I was able to buy the product in my sandbox environement.

@dooboolab it is crashing in the getItems. The logs start coming

===============LOGS================ 2018-01-30

12:51:48.196 [info][tid:com.facebook.react.RNIapIosQueue][RNIapIos.m:46]

Obj c >> InAppPurchase :: fetchProducts

. 2018-01-30 12:51:48.196370+0530 APP NAME[772:191753]

Obj c >> InAppPurchase :: fetchProducts

. 2018-01-30 12:51:48.198672+0530 APP NAME[772:191753] Obj c >> InAppPurchase :: fetchProducts >> arrProd parsed as follows ... ( "abc", "pqr", "xyz" ) 2018-01-30 12:51:49.267226+0530 APP NAME [772:191710]

Obj c >> InAppPurchase ### didReceiveResponse :: Valid Product Count :: 3 2018-01-30 12:51:49.270598+0530 APP NAME[772:191710] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[3]' *** First throw call stack: (0x1924befe0 0x190f20538 0x1923a59b4 0x1923a5824 0x1007b8a98 0x1007b7578 0x19f58d320 0x101209a50 0x101209a10 0x10120eb78 0x19246d0c8 0x19246ace4 0x19239ada4 0x193e05074 0x19864ec9c 0x1000cd054 0x1913a959c) libc++abi.dylib: terminating with uncaught exception of type NSException

hyochan commented 6 years ago

@ankurToko It is quite inefficient to solve your issue here because there hasn't been chages from 0.1.* to 0.2.* for getting items in ios. So we need to try some tests and trials to find out your problem. Could you please getItems one by one for your ios products?

const itemSkus = {
  ios: [
    'xyz',
//    'abc',
//    'pqr',
  ],
};

one by one. It might not be the issue but need to do some test yourself because we are not in your environment..

Also you might want to upgrade to 0.2.6 and test again because many users are in this version.

ankurToko commented 6 years ago

@dooboolab Alright. Will be on it.

hyochan commented 6 years ago

@ankurToko Please tell us again if you are still in trouble or any experience!

ankurToko commented 6 years ago

@dooboolab I still haven't been able to resolve it. Trying upgrading. The single item thing didn't work out.

hyochan commented 6 years ago

@ankurToko Could you try example code in here?

I will invite you to this itunesconnect test project if you share your apple id. If you feel private with this one you can send me an email(dooboolab@gmail.com).

Maybe you can compare with your configuration in itunesconnect and sample codes through working example.

ankurToko commented 6 years ago

@dooboolab @JJMoon I rectified the issue that I had. It was because of 0.1.15 As in the package.json there was a '^' it was taking the latest version of 0.1.15, but when i removed the '^' then it remained on 0.1.10 and worked just like before.

I suppose this has something to do with any of your latest updates.

hyochan commented 6 years ago

@ankurToko Glad that it is solved. I've told you previously that there is critical bug in 0.1.15 that @JJMoon born. Good that you found out. Also, I've created another issue for previous question here. Because there are mixed personalities in this issue thread which are getting the list of subscribed plans for the user and other problems.

Thank you. I will close this.

ankurToko commented 6 years ago

Yeah, but then I didnt know that it was referring to 0.1.15 and not the latest one i.e. 0.2.6

Anyways, thanks for your help and the library itself.