j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.29k stars 529 forks source link

[CdvPurchase] INFO: order(undefined) at the time of order place #1493

Open RintuMondal06 opened 6 months ago

RintuMondal06 commented 6 months ago

Project Info

// Consumable product register
   CdvPurchase.store.register({
    id: currentValue,
    type: CdvPurchase.ProductType.CONSUMABLE,
    platform:CdvPurchase.Platform.GOOGLE_PLAY,
    });

// event listeners
              CdvPurchase.store.when(my_product_code)
            .approved((transaction) =>transaction.verify())
            .verified((receipt) => receipt.finish())
            .finished((p) => {
             // custom function called here to update the server
        });

// order code block
      CdvPurchase.store.order(my_product_code)
    .then((p) => {
    console.log('order then block', p);
    })
    .catch((e) => {
    console.log('error order in catch', e);
    });

Output

Getting errors in order with error code 6777008 and the error message is "Adapter not found or not ready (undefined)"

undergroundcreative commented 6 months ago

Have you initialized the store?

CdvPurchase.store.initialize();

RintuMondal06 commented 6 months ago

Have you initialized the store?

CdvPurchase.store.initialize();

@undergroundcreative yes, i called CdvPurchase.store.initialize() before calling CdvPurchase.store.register()!

undergroundcreative commented 6 months ago

Ok you need to register products and set callbacks before calling CdvPurchase.store.initialize()

See here for an example: https://purchase.cordova.fovea.cc/discover/micro-example

RintuMondal06 commented 6 months ago

Ok you need to register products and set callbacks before calling CdvPurchase.store.initialize()

See here for an example: https://purchase.cordova.fovea.cc/discover/micro-example

@undergroundcreative thanks for your help! I'm following the example from the doc but in my case store.get() is returning undefined while fetching the product.

Below is my code:

     const product = CdvPurchase.store.get(
                PRODUCT_ID,
                CdvPurchase.Platform.GOOGLE_PLAY
            );

     product.getOffer()
        .order()
        .then((p) => {
            console.log('order then block', p);
        })
        .catch((e) => {
            console.log('error order in catch', e);
        });
undergroundcreative commented 6 months ago

That part of the code looks right to me. Maybe you should post your full code (obviously blank out sensitive info like product ids etc)

The second part, I use:

store.order(product.getOffer()).then(e => {...});

RintuMondal06 commented 5 months ago

This is the full code for the in-app-purchase.

// Consumable product register
   CdvPurchase.store.register({
    id: currentValue,
    type: CdvPurchase.ProductType.CONSUMABLE,
    platform:CdvPurchase.Platform.GOOGLE_PLAY,
    });

// event listeners
              CdvPurchase.store.when(my_product_code)
            .approved((transaction) =>transaction.verify())
            .verified((receipt) => receipt.finish())
            .finished((p) => {
             // custom function called here to update the server
        });

// order code block
           const product = CdvPurchase.store.get(
                PRODUCT_ID,
                CdvPurchase.Platform.GOOGLE_PLAY
            );

     product.getOffer()
        .order()
        .then((p) => {
            console.log('order then block', p);
        })
        .catch((e) => {
            console.log('error order in catch', e);
        });
undergroundcreative commented 5 months ago

There's no sign of CdvPurchase.store.initialize(); in that code :)

What is your output now?

RintuMondal06 commented 5 months ago
const product = CdvPurchase.store.get(
      'my_product_id',
      CdvPurchase.Platform.GOOGLE_PLAY
    );
    CdvPurchase.store
      .order(product.getOffer())
      .then((p: any) => {
        console.log('order then block', p);
      })
      .catch((e: any) => {
        console.log('error order in catch', e);
      });

product is undefined, that is my issue right now.

AlexandrDegteari commented 5 months ago

same problem I have, someone found solution?

RubioN commented 4 months ago

I have the same issues on my side. The function is returning undefined and some fields are missing in CdvPurchase.Product. product.canPurchase = true; product.title = ""; product.description = ""; product.offers[0].id = "$"; product.offers[0].productId = "qcm3ans";

But this is not the case for all products (one has all information)

shahdeep1989 commented 4 months ago

@j3k0 @RintuMondal06 I am facing same issue on iOS. Not tried for Android. Any solution for the same?

j3k0 commented 4 months ago

If the product is undefined it could mean it isn't available for purchase. Your code needs to check if store.get(...) returns undefined and warn the user that the product isn't available at the moment.

Notice also that if done properly, the user shouldn't be able to call order for that product, since you're supposed to display the price and title as returned by the plugin. So if a product is not available the "buy" button should be grayed out or replaced by a warning that "this offer isn't available at the moment".

This is a use case that needs to be handled gracefully, as some users have in-app purchases disabled on their device.

To understand the reason why the product isn't available, please share some logs.

shahdeep1989 commented 4 months ago

@j3k0 store.get(...) returns undefined on iOS. Also I checked again on App Store Connect and I can see status of Non-Renewing Subscriptions is "Approved". Why still I am not getting product details? Till date it was working. When I have updated last time at that time I am getting this error.

j3k0 commented 4 months ago

Why still I am not getting product details?

Can you share debug logs?

shahdeep1989 commented 4 months ago

@j3k0

For android my in app purchase is working well. Getting issue on iOS. Sending log soon. Is it due to below reason? Check screenshot.

Screenshot 2024-01-12 at 12 28 35 PM
j3k0 commented 4 months ago

Yes, any banking, tax and paid agreements warnings will results in in-app purchases being disabled for the developer account.

shahdeep1989 commented 4 months ago

@j3k0 All of the agreement and other setup has been done related to Tax, banking, etc. All set but still getting product details undefined on iOS, for Android it's working well.

Also follow the example but still getting undefined. Status of product on apple store is approved. And it was working previously. https://purchase.cordova.fovea.cc/discover/micro-example

Any one has any idea?

shahdeep1989 commented 4 months ago

@j3k0 It's working now.

j3k0 commented 4 months ago

So it was the missing tax form?

shahdeep1989 commented 4 months ago

No it was one mistake in my code to validate platform.

One more question: store.when().verified(receipt => {

When I am checking receipt of testflight build on real device, I am not getting "receipt.sourceReceipt.transactions[0].nativePurchase".

Format of testflight build receipt has been changed?

RintuMondal06 commented 4 months ago

@shahdeep1989 can you please help with Android implementation? I can't find any issues in my current code. If you share your code here for reference it would be a great help for me. Thanks!