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

[Android] v13 with Capacitor - can't initialize IAPs - DEVELOPER_ERROR: SKU name can't be empty #1440

Closed AEiosApp closed 1 month ago

AEiosApp commented 10 months ago

Observed behavior

CdvPurchase.store.initialize() never finished on Android with Capacitor, but same code works perfect on:

On the Logcat I've:

Here's my code:

// --- initIAPs ---
// iaps: IAP ids (Array of String)
async function initIAPs(iapIDs, appID, paidToFree) {
  return new Promise(async (resolve) => {
    // register all IAPs in purchase plugin
    var iapsToRegister = []
    console.log('window:')
    console.log(window)
    var platform = window.CdvPurchase.Platform.GOOGLE_PLAY

    const gs = useGlobalsStore()
    if (gs.platform === 'ios') {
      platform = window.CdvPurchase.Platform.APPLE_APPSTORE
    }

    iapIDs.forEach((id) => {
      const iapToRegister = {
        id: id,
        type: window.CdvPurchase.ProductType.NON_CONSUMABLE,
        platform: platform,
      }
      iapsToRegister.push(iapToRegister)
    })

    console.log('#iaptest iapsToRegister: ' + JSON.stringify(iapsToRegister))
    window.CdvPurchase.store.register(iapsToRegister)

    window.CdvPurchase.store.when().productUpdated((product) => {
      console.log(
        '#iaptest initial product update ' +
          product.id +
          ' (owned: ' +
          product.owned +
          '):\n' +
          JSON.stringify(product)
      )
      // resolve(true)
    })

    window.CdvPurchase.store.initialize().then(() => {
      console.log('#iaptest iaps initialised!')
      resolve(true)
    })
  })
}

So console.log('#iaptest iaps initialised!') never fired on Android.

IAPs configured in Google Play correctly - all of them works fine with production version in Play Store. IAPs array to register looks correct:

Screenshot 2023-07-13 at 11 53 16 PM

Expected behavior

In my another, cordova app with the same plugin version v13.6.0 queryAllProductDetails() works fine and return product details:

Screenshot 2023-07-14 at 8 20 21 AM

System Info

cordova-plugin-purchase v13.6.0 capacitor v3.4.3

Output of cordova info.

AEiosApp commented 10 months ago

@j3k0 check please, and let me know if any debug tests or log can help you to investigate this issue 🙏

dferenc-netwizzy commented 9 months ago

Not sure if revelant to Your issue, but i had to specify the group explicitly to get v13 working on android (ie. contrary to what the documentation states of "group" having a default value if not set, see commit )

store.register({
  id: "PRODUCT_SKU",
  type: CdvPurchase.ProductType.CONSUMABLE,
  platform: CdvPurchase.Platform.GOOGLE_PLAY,
  group: 'default'
})

EDIT: Not sure if it's the same behaviour for NON_CONSUMABLE type products as well, but You could give it a try.

AEiosApp commented 9 months ago

@dferenc-netwizzy thanks for the comment, but I've started getting more bug reports from users, seems like v13 is not yet ready, I'll roll back to the stable v11.

AEiosApp commented 1 month ago

Issue has gone on v13.10.1