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

Can't manage to get it working on IOS Capacitor #1524

Closed yannickBona closed 2 months ago

yannickBona commented 2 months ago

Observed behavior

hey there, I've been struggling with making this work on my React Ionic application.

I installed the package "cordova-plugin-purchase": "^13.10.1" and it keeps fetching an empty array /undefined if I log store.products or use store.get("id")

I have created my products in the App Store Connect: Screenshot 2024-02-08 alle 20 18 12

For each product I filled all the info except for the App Promotion and Review Information.

I also have set up all the identifiers ID, merchantIds and requested the signed certificates.

I tried many versions and this is the code right now:

useEffect(() => {
    document.addEventListener("deviceready", initStore);

    function initStore() {
      const { store, LogLevel, Platform, ProductType } = CdvPurchase;
      console.log("Init store");
      store.verbosity = LogLevel.DEBUG;
      store.register([{
        id: "notarifypersonal",
        type: ProductType.CONSUMABLE,
        platform: Platform.APPLE_APPSTORE,
      }]);
      store.initialize().then((e) => {
        const product = store.get("notarifypersonal"); // product
        console.log("PRODUCT", product);
      });

  }, []);

The useEffect is inside a React Context that wraps the entire App

I import the package in the App.tsx file:

import "cordova-plugin-purchase";

These are the two scripts I'm running to test on the native device(live server/static):

"debug-ios": "ionic cap run ios -l --external --open",
"build-ios": "ionic cap build ios",

Here's the logs i get when I start the app:

2024-02-08 20:08:10.929208+0100 App[19206:1345032] [CdvPurchase.AppleAppStore.objc] processPendingTransactionUpdates
⚡️  TO JS {"mode":"native"}
⚡️  [log] - [CdvPurchase.AppleAppStore] DEBUG: loading appstore receipt...
To Native Cordova ->  InAppPurchase appStoreReceipt InAppPurchase1967461962 ["options": []]
⚡️  [log] - [CdvPurchase.AppleAppStore.Bridge] DEBUG: loading appStoreReceipt
2024-02-08 20:08:11.185603+0100 App[19206:1345032] [CdvPurchase.AppleAppStore.objc] appStoreReceipt:
⚡️  [log] - [CdvPurchase.AppleAppStore.Bridge] DEBUG: infoPlist: io.notarify.app,1.0,1081344,null
⚡️  [log] - [CdvPurchase.AppleAppStore] DEBUG: appstore receipt loaded
⚡️  [log] - [CdvPurchase.AdapterListener] DEBUG: receiptsReady: ios-appstore (1/0)
⚡️  [warn] - [CdvPurchase.AppleAppStore] WARNING: no appStoreReceipt
⚡️  [log] - [CdvPurchase.Adapters] INFO: AppStore products loaded: [{"isError":true,"code":6777012,"message":"Product not found in AppStore. #400","platform":"ios-appstore","productId":"notarifypersonal"}]
⚡️  [log] - [CdvPurchase.Adapters] INFO: AppStore receipts loaded: [{"className":"Receipt","transactions":[],"platform":"ios-appstore"}]
⚡️  [log] - [CdvPurchase.AdapterListener] DEBUG: setSupportedPlatforms: ios-appstore (1 have their receipts ready)
⚡️  [log] - [CdvPurchase.AdapterListener] DEBUG: triggering receiptsReady()
⚡️  [log] - PRODUCT undefined // This is my log
⚡️  [log] - [CdvPurchase] DEBUG: Calling callback: type=receiptsReady() name=receiptsMonitor_setup reason=adapterListener_setSupportedPlatforms
⚡️  [log] - [CdvPurchase.ReceiptsMonitor] DEBUG: receiptsReady...
⚡️  [log] - [CdvPurchase.ReceiptsMonitor] DEBUG: check(0/0)
⚡️  [log] - [CdvPurchase.ReceiptsMonitor] INFO: receiptsVerified()
⚡️  [log] - [CdvPurchase.AppleAppStore] DEBUG: receipt updated.
⚡️  [log] - [CdvPurchase.AdapterListener] DEBUG: receiptsUpdated: [{"className":"Receipt","transactions":[],"platform":"ios-appstore"}]

What am I doing wrong? I'll appreciate any help, thanks

Expected behavior

Fetch products and handle IAP

System Info

XCode Version 14.3.1 Capacitor 4.7.0 Ionic/react 7.0.11 MacOS Ventura 13.2.1

yannickBona commented 2 months ago

Got it working by filling out the banking & Tax info in this section App Store Connect - Agreements and waited for the approval.

I switched the state of my products from "Missing Metadata" to "Ready for submit" by completing also the App Promotion information, IDK if this last step is actually needed though.

Hope this helps someone else too! This is poor documented and I was stuck for days due to this.

natestone commented 2 months ago

Got it working by filling out the banking & Tax info in this section App Store Connect - Agreements and waited for the approval.

This was the solution for me as well. As soon as I filled out the agreements and entered tax info, I could see the products and test. I did not have to wait for approval as it is still "pending" and I did not have to fix the "Missing Metadata" problem.

Thanks for the heads up! Stuck for a single day here (instead of many) thanks to your help.