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

Aberta
#39 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
typescript
Domínio
mobile, payments

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
TypeScript
Estrelas
35
Forks
13
Métricas de merge de PRs
Nenhum PR com merge em 30d

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de NativeScript/payments

Todas as issues de NativeScript/payments

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.