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

PurchaseUpdateListners not being called on production iOS build #1146

Closed
ashish3303 opened this issue Oct 9, 2020 · 28 comments
Closed

PurchaseUpdateListners not being called on production iOS build #1146

ashish3303 opened this issue Oct 9, 2020 · 28 comments
Labels
🙏 help wanted Extra attention is needed 📱 iOS Related to iOS Stale

Comments

@ashish3303
Copy link

Hello everyone,

I am not sure what actually happen with my code. I integrated the react-native-iap plugin into my iOS application. And it was working fine on local build or testflight build but when i release the mobile version of application and i made the subscription but nothing happened next. I assumed that purchaseUpdateListeners are not working on production build then i removed the listeners and write the code just after the requestSubscription send the response. And released the next version of application but still the same issue even getReceiptIOS not called. I am stuck into this. Help me to find out from this.

Here is my code : -

const purchases = await RNIap.requestSubscription(productId);
console.log(purchases, "purchase...")
this.validateTransactionReceipt(purchases);

validateTransactionReceipt method : -

validateTransactionReceipt = (purchase) => {
const receipt = purchase.transactionReceipt;
if (receipt) {
AppEventsLogger.logEvent("Subscription transaction receipt validated", { type: 'owner' });
const receiptBody = {
'receipt-data': purchase.transactionReceipt,
'password': subscriptionSecret
};

        RNIap.validateReceiptIos(receiptBody, true).then(receipts => {
            let lastReceipt = receipts.latest_receipt_info[receipts.latest_receipt_info.length - 1];
            console.log(lastReceipt, "lastReceipt...")
            let params = {
                productId: purchase.productId,
                transactionId: purchase.transactionId,
                autoRenew: purchase.hasOwnProperty("originalTransactionDateIOS") ? true : false,
                // autoRenew: true,
                transactionDate: purchase.transactionDate,
                status: "success",
                transactionReceipt: lastReceipt,
                paymentMode: receipts.environment,
                originalTransactionDateIOS: purchase.hasOwnProperty("originalTransactionDateIOS") ? purchase.originalTransactionDateIOS : purchase.transactionDate,
                originalTransactionIdentifierIOS: purchase.hasOwnProperty("originalTransactionIdentifierIOS") ? purchase.originalTransactionIdentifierIOS : purchase.transactionId
            }

            console.log(params, "params-1");
            this.subscriptionSaveHandler(params);
        });
        if (Platform.OS === 'ios') {
            RNIap.finishTransactionIOS(purchase.transactionId).then(response => {
                console.log(response, "finish");
            });
        }
    }
}

Thanks

@the-dut
Copy link

the-dut commented Oct 10, 2020

I think you need to initially call validateReceiptIos with a false parameter first, and then if that call returns a 21007 then you call it with true. That way it will work in both prod and sandbox. That's something I ran into.

@BStenfors9119
Copy link

I am having this same issue even with "isTest" set to "false" in calling RNIap.validateReceiptIos().

Testing on an actual device with "isTest" set to "true" seems to work but when pushed to production is does not work.
Some how Apple's testers approve my app which I am not sure how.

@the-dut
Copy link

the-dut commented Oct 15, 2020

Definitely when you validate the receipt validate in production (use false param), then if that returns with a status of 21007, validate in the sandbox (use true param).

Then after calling finishTransactionIOS(), also call finishTransaction().

Hope that helps!

@BStenfors9119
Copy link

@the-dut awesome! Going to give that configuration a try.

Will report back what happens :D.

I just wish Apple and Google had more solid abilities for devs to test before going through the process of release flows just to fined out our code doesn't work :/.

@BStenfors9119
Copy link

@the-dut ok now I am getting endless password / log in prompts after calling RNIap.requestSubscription([productId])

@the-dut
Copy link

the-dut commented Oct 15, 2020

It could be all the previous requests coming through that were never finalized. Could be hundreds or thousands based on how much you've tested. Maybe once you get through them you might be ok.

ALso, are you testing on a real device? Local or TestFlight? Are you using a Sandbox user or a production id? And if sandbox user, do you have that id set up in your phone as a Sandbox user?

I never saw that issue. But I can try to help.

@BStenfors9119
Copy link

ALso, are you testing on a real device?
Real Device via XCode :: iOS 13.6.1

Local or TestFlight?
Local

Are you using a Sandbox user or a production id?
Sandbox User Id

And if sandbox user, do you have that id set up in your phone as a Sandbox user?
They are set up

here is my code

purchaseUpdatedListener():


await RNIap.clearTransactionIOS();
            let receipt = purchase.transactionReceipt;

            validatePurchase(receipt).then(async resp => {
                console.log('validated purchase');
                console.log(resp);
                // let iosTransactionFinished = await finishTransactionIOS(purchase.transactionId);
                let transactionFinished = await finishTransaction(purchase, false);
                let result = await successfullySubscribed(purchase);


                if (result.success && !fullFirstLaunchFlow) {
                    goTo('Home');
                }
            });

validatePurchase():

const receiptBody = {
                    'receipt-data': receipt,
                    'password': '<shared secret>'
                };

                console.log('validating purchase');

                let validReceipt = await RNIap.validateReceiptIos(receiptBody, false);
                console.log('valid receipt');
                console.log(validReceipt);
                if(validReceipt.status === 21007){
                    validReceipt = await RNIap.validateReceiptIos(receiptBody, true);
                    console.log('valid receipt was 21007');
                    console.log(validReceipt);
                }

@the-dut
Copy link

the-dut commented Oct 16, 2020

Is there a reason you have the finishTransactionIOS commented out? You should do both finishTransactionIOS() and then finishTransaction()

@BStenfors9119
Copy link

BStenfors9119 commented Oct 16, 2020

I could be confused but I thought this description in the README meant to only use "finishTransaction" if using v4.1.0 or later.

Or does it mean to use both of them as you suggest?

I am currently using v4.5.4.

iOS only
Finish a transaction. Use finishTransaction instead for both platforms since version 4.1.0 or later.

@the-dut
Copy link

the-dut commented Oct 16, 2020

Great point! I do both just in case.

@BStenfors9119
Copy link

well, either way it never gets to those lines yet, lol.

I will uncomment that line. Anymore I am willing to try anything to get this working :D

@BStenfors9119
Copy link

Just upgraded to v5.0.0 hoping something might of changed but no dice.

Still getting multiple pwd prompts.

I am getting 2 at a time and after second prompt it errors out with "E_UNKNOWN" cannot connect to iTunes.

@the-dut
Copy link

the-dut commented Oct 16, 2020

Does it all start happening right when you add your updatedpurchaselistener? If so, you may need to just get through all of the unfinished transactions first. Or.. use your real apple id instead of the test user.

@BStenfors9119
Copy link

it all happens right at "requestSubscription()". I never see another console log after that.

The only console log I see after requestSubscription executes is "Purchase Started !".

The next console log is "Purchase Failed!!" followed by the "E_UNKNOWN" errors inside of "puchaseErrorListener".

@the-dut
Copy link

the-dut commented Oct 16, 2020

Did you try with your real Apple ID?

@BStenfors9119
Copy link

I have not tried that yet. Do I need to add my real Apple ID as a tester?

@the-dut
Copy link

the-dut commented Oct 16, 2020

No. You can just use it I would think.

@BStenfors9119
Copy link

Using my Apple ID it only prompts me once and gives the "E_UNKOWN" error immediately.

@BStenfors9119
Copy link

just tried testing with a newly created Sandbox User but no dice.

2 pwd prompts and error.

@BStenfors9119
Copy link

what's really odd and I know it's not suppose to be this way now, is I use to have "finishTransaction()" before validating the receipt and it worked that way.

@BStenfors9119
Copy link

BStenfors9119 commented Oct 17, 2020

Quick update.

@the-dut I submitted a build with everything setup how you suggested (to TestFlight) and it worked!! So now I am throwing caution to the wind and submitted it for production.

@the-dut
Copy link

the-dut commented Oct 17, 2020

That's great news! Let us know how it goes!

@hyochan hyochan added 🙏 help wanted Extra attention is needed 📱 iOS Related to iOS labels Oct 26, 2020
@hyochan
Copy link
Member

hyochan commented Oct 26, 2020

Thanks to all having discussions and sharing benefits in the current thread ❤️

@BStenfors9119
Copy link

Sorry for the delayed report.

Forgot to add it works in production!!

Next up....accepting promotions so I can give my app for free to friends and family 😁

@rodrigopasc
Copy link

@BStenfors9119 what was the problem at all? Can you share exactly how you solve the problem? Thank you very much.

@stale
Copy link

stale bot commented Jun 4, 2021

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale label Jun 4, 2021
@stale
Copy link

stale bot commented Jul 8, 2021

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Jul 8, 2021
@c-info
Copy link

c-info commented Dec 15, 2022

let receipt = purchase.transactionReceipt;

does not return anything returns empty string

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 Stale
Projects
None yet
Development

No branches or pull requests

6 participants