Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: This in-app purchase has already been bought. #257

Closed
siderakis opened this issue Sep 12, 2018 · 16 comments
Closed

iOS: This in-app purchase has already been bought. #257

siderakis opened this issue Sep 12, 2018 · 16 comments
Labels
🙏 help wanted Extra attention is needed 📱 iOS Related to iOS

Comments

@siderakis
Copy link

siderakis commented Sep 12, 2018

Version of react-native-iap

"react-native-iap": "^2.0.3",

Platforms you faced the error (IOS or Android or both?)

iOS

Expected behavior

Makes a purchase

const purchase = await RNIap.buyProductWithoutFinishTransaction(productId)
const { transactionReceipt, purchaseToken } = purchase
sendToServer(transactionReceipt, {
onSuccess: () => {
RNIap.finishTransaction()
RNIap.consumeAllItems()
}})

Actual behavior

Dialog: “This in-app purchase has already been bought”. This is only happening for one SKU, others are working fine. I think the app got in a bad state and I don't see a way to fix it. I tired to call finishTransaction and consumeAllItems on initialization but that didn't fix it. Other SKUs I can purchase multiple times without issue. Nothing is returned for getPurchaseHistory.

Tested environment (Emulator? Real Device?)

Device (sandbox)

Steps to reproduce the behavior

I'm not sure.

@hyochan hyochan added 📱 iOS Related to iOS 🙏 help wanted Extra attention is needed labels Sep 13, 2018
@hyochan
Copy link
Member

hyochan commented Sep 13, 2018

@siderakis Yeah strange. I've already patched this problem like told in stackoverflow but still occurring in some devices. I am willing to fix this too. Which device are you using?

@hyochan
Copy link
Member

hyochan commented Sep 13, 2018

@siderakis This might solve your app in bad state I guess. Could you try?

@siderakis
Copy link
Author

I tried it and it didn't work. I also reinstalled the app and that didn't help. It's running on an iPad.

@siderakis
Copy link
Author

I set a breakpoint and it looks like currentQueue.transactions is empty

@siderakis
Copy link
Author

From SKPaymentQueue.h

// Array of unfinished SKPaymentTransactions.  Only valid while the queue has observers.  Updated asynchronously.
@property(nonatomic, readonly) NSArray<SKPaymentTransaction *> *transactions NS_AVAILABLE_IOS(3_0);

@end

Maybe I called it too soon

@siderakis
Copy link
Author

I called the code later in the programs execution and it fixed the issue.

@JJMoon
Copy link
Contributor

JJMoon commented Sep 14, 2018

@siderakis Sorry for bothering. But, what code did you call ?
The transactions array is a property, not method, which is not in our code.
Did you mean finishTransaction ?

@siderakis
Copy link
Author

I was calling this native code.

When I called it in didFinishLaunchingWithOptions currentQueue.transactions was empty, but calling it in applicationDidBecomeActive worked.

This worked:

- (void)applicationDidBecomeActive:(UIApplication *)application
{
  // take current payment queue
  SKPaymentQueue* currentQueue = [SKPaymentQueue defaultQueue];
  [currentQueue restoreCompletedTransactions];
  // finish ALL transactions in queue
  //  [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
  [currentQueue.transactions enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    [currentQueue finishTransaction:(SKPaymentTransaction *)obj];
  }]; 
}

I'm not sure how but maybe we can expose this functionality in the library?

@JJMoon
Copy link
Contributor

JJMoon commented Sep 14, 2018

@siderakis Yes. That's what I meant in issue #259 .
I think that action can be anywhere after applicationDidBecomeActive.
So, I will expose that method to JS side, that user can call it any time.
Thank you for your advice.

@sivrihuseyin
Copy link

@JJMoon, I have the same issue, When can we expect a resolution for exposing a method as you mentioned above. Thanks.

@hyochan
Copy link
Member

hyochan commented Sep 14, 2018

@sivrihuseyin Problem is well known now. We will make the patch this weekend. Thank you to all issuers.

@hyochan
Copy link
Member

hyochan commented Sep 16, 2018

We've released the expected solution in 2.2.0. Could you follow readme and try this line of codes?

@sivrihuseyin
Copy link

sivrihuseyin commented Sep 16, 2018 via email

@sivrihuseyin
Copy link

sivrihuseyin commented Sep 16, 2018 via email

@sivrihuseyin
Copy link

It is fixed with the version 2.2.0 by applying clearTransaction function. Thank you
@JJMoon

@leotm
Copy link

leotm commented Dec 10, 2020

For future Googlers upgrading from v2 to v3-5, I found this helpful

https://github.com/dooboolab/react-native-iap/blob/de0fc084966fc4d36a9c45f4e27cb166243d4319/README_DEPRECATED.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙏 help wanted Extra attention is needed 📱 iOS Related to iOS
Projects
None yet
Development

No branches or pull requests

5 participants