[@nativescript/payments] Not possible to use both subscriptions and IAPs in the same project

Offen
#39 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
typescript
Bereich
mobile, payments

Rechercherichtung

Start by tracing fetchSubscriptions and fetchItems, focusing on how _fetchedItems, _fetchedSubscriptions, and _fetchedProducts are populated and whether consecutive calls overwrite shared state. Confirm the behavior with a project that loads both subscription and in-app-purchase products; done means both product types remain available without polling or manually merging arrays.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

I have a situation where I offer two subscriptions and an additional "lifetime" subscription (which is really an in-app purchase, consumable). I may easily be mistaken, but the way the plugin implementation is designed, you can't really offer both subs and purchases because of an overwrite of _fetchedItems when calling both fetchSubscriptions and fetchItems consecutively?

My very hacky workaround is to:

  1. fetchSubscriptions where I normally would
  2. Call a separate method, like loadAll() after that:
  async loadAll() {
      await this.waitForSubscriptions();
      fetchItems(["com.nativescript.whatever.item]);
  }
  1. This will await subscriptions being loaded and waitForSubscriptions returns a promise when there is something in the array (yeah this isn't perfect):
  waitForSubscriptions(): Promise<void> {
      return new Promise<void>((resolve) => {
          const check = setInterval(() => {
              if (this._fetchedSubscriptions.length > 0) {
                  clearInterval(check);
                  resolve();        // now valid, since T is void
              }
          }, 500);
      });
  }
  1. After subscriptions are confirmed, then call fetchItems (see step 2).
  2. Finally merge the two arrays:
    if (this._fetchedSubscriptions.length > 0 && this._fetchedProducts.length > 0) {
        this._fetchedItems = [
            ...this._fetchedSubscriptions,
            ...this._fetchedProducts,
        ];
        console.log('Fetched subscription items:', this._fetchedItems);
    }

It's a little more complicated than this and I'd be happy to share my full code if anyone is curious.

Vorherrschende Sprache
TypeScript
Sterne
35
Forks
13
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus NativeScript/payments

Alle Issues in NativeScript/payments

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.