PeterStaev / nativescript-purchase

:moneybag: A NativeScript plugin for making in-app purchases!
Apache License 2.0
83 stars 28 forks source link

getProducts() returns empty array #88

Closed philicomus closed 4 years ago

philicomus commented 4 years ago

Hi,

I'm having the same issue a few others have had but still haven't been able to get this working after trying the other solutions which have been suggested.

I am using a global object to save the promise to:

(global as any).purchaseInitPromise = purchase.init(["myproduct]);

And then waiting for it to complete before calling getProducts:

(global as any).purchaseInitPromise.then(() => {
            purchase.getProducts().then((products: Array<Product>) => {
                console.log('back');
                if (products.length === 0) {
                    console.log('0');
                }
                console.log(JSON.stringify(products));
                products.forEach((product: Product) => {
                    console.log(product.productIdentifier);
                    console.log(product.localizedTitle);
                    console.log(product.priceFormatted);
                });
            });
        });

Still no luck. I've checked that:

Many thanks in advance

PeterStaev commented 4 years ago

Hey @philicomus , have you read the step by step guides and especially this note:

NB: You might NOT be able to see the registered products (consumable, non-consumable, etc.) if you do not have any contracts in effect regarding paid applications. To solve the problem, you can activate the contract for paid applications in App Store Connect > Contracts, Tax and Banking section.

philicomus commented 4 years ago

Hi Peter, yes I have read the guides and tried everything mentioned I think!

I know all is good on the payment side as my app is currently on the app store taking up-front payments...but I'm trying to move it to Freemium.

Any other help much appreciated! Cheers

PeterStaev commented 4 years ago

What do you mean it is taking upfront payments? You have In-app purchases working on production, but you made some changes and now you dont see the in-app products when you test the new version?

Sadly not much I can help with if there are no errors, this means that the native API is returning an empty list and there are no errors doing so. So it must be something with the whole set up.

philicomus commented 4 years ago

Ah no, I've never had in-app purchases working but it is being sold currently as an up-front payment product, so a payment contract is in place. Yes, no errors at all, so you're probably right. Perhaps I'll follow the tutorial step-by-step with a new app id and product ids and see if that works. Thanks anyway

philicomus commented 4 years ago

I'm still getting the same issue after following through the tutorial very carefully. However, I'm not using XCode as I don't have MAC - just the NS Playground on my device. Do I need to add a .entitlements file to the project with the in-app purchase entitlement (even though that's already configured on the explicit app id)? Also I've had to upgrade to NS6 due to the latest Playground app requiring it. Should it still work in NS6 even though I should be using the pro-plugins version? Many thanks

PeterStaev commented 4 years ago

@philicomus , dont think the plugin will work on the playground. All the security around purchases is based on certificates, and on files (the .entitlements one) that need to be built with your app. So you will have to find a Mac and build your app natively.

And android wont work 100% on the playground since it uses an aar file that you cannot use on the playground.

philicomus commented 4 years ago

Ah ok, makes sense. Thanks

alexisconsuegra commented 4 years ago

Hi Peter, I have two questions since I am also getting empty product array.

Are the products in the tutorial good? purchase.init([ "org.nativescript.purchasesample.product1", "org.nativescript.purchasesample.product2" ]);

Since PlayGround will not be a good tool to test. Will NativeScript Side Kit be used to build and deploy to a device? I am using it for a while but never with the purchase plugin before