Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the Sandbox opens repeatedly upon purchase even though it is displayed as Done. After Done appears, the store Listener is not called. #1571

Open
rodrigocsaraujo opened this issue Jun 16, 2024 · 7 comments

Comments

@rodrigocsaraujo
Copy link

rodrigocsaraujo commented Jun 16, 2024

Observed behavior

In Constructor

 this.plt.ready().then(async () => {
      // this.store.verbosity = LogLevel.INFO;
      this.store = CdvPurchase.store;
      this.registerProducts();
      this.setupListeners();
      this.store?.initialize();
  
    });

Calls in Sequences

private registerProducts() {
    const { ProductType, LogLevel, Platform } = CdvPurchase;
 
    this.store?.register([{
      id: SUBSCRIPTION_MONTHLY,
      type: ProductType.PAID_SUBSCRIPTION,
      platform: Platform.APPLE_APPSTORE,
    },
    {
      id: SUBSCRIPTION_MONTHLY,
      type: ProductType.PAID_SUBSCRIPTION,
      platform: Platform.GOOGLE_PLAY,
    }]);
    console.log(`INICIALZANDO ${CdvPurchase.store.getApplicationUsername()}`);
  }


private setupListeners() {
    const handleUpdate = () => {
      if (this.store?.owned(SUBSCRIPTION_MONTHLY)) {
        // this.gotoLoginPage();
        console.log("ENTROU PARA IR PARA O LOGIN");
        return;
      }
    
      if (this.receiptsVerified) {
        if (this.store?.get(SUBSCRIPTION_MONTHLY) && this.canPurchase) {
          // this.gotoSubscriptionPage();
          console.log("ENTROU PARA IR PARA A TELA DE PAGAMENTO");
        } else {
          console.log("ENTROU PARA IR PARA O ERRO");
        }
      }
    };

    this.store?.when()
    .unverified( cb => {
      console.log("PAYLOAD"+ cb.payload);
    })
    .productUpdated(() => {
      const product = this.store?.get(SUBSCRIPTION_MONTHLY);
      this.canPurchase = !!(product && product.canPurchase);
      console.log("RPU");
      handleUpdate();
    })
    .receiptUpdated(() => {
      console.log("RCU");
      handleUpdate();
    })
    .receiptsVerified(() => {
      this.receiptsVerified = true;
      console.log("RCV");
      handleUpdate();
    })
    .approved(async (transaction) => await transaction.verify())
    .verified(async (receipt) => await receipt.finish())
    .unverified((receipt) => {
      console.log(`Receipt cannot be verified: ${receipt && receipt.payload && receipt.payload.message}`);
    });
  }
  

  protected async purchase() {
    const { ProductType, Platform} = CdvPurchase;
    console.log(`COMPRAS  -->  ${this.store?. get(SUBSCRIPTION_MONTHLY, Platform.APPLE_APPSTORE)?.owned}`);    
   
    const { store } = CdvPurchase;
    const product = store.get(SUBSCRIPTION_MONTHLY);
    if (product && product.canPurchase) {

      console.log("PLANO => "+product.getOffer()?.productType);
      await product.getOffer()?.order().then( result =>{
        console.log(result?.message);
      }).catch(result =>{
        console.log(result?.message);
      });
       this.store?.restorePurchases();
    }

  }

Expected behavior

System Info

Ionic:

Ionic CLI : 7.2.0 (/opt/homebrew/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 8.2.2
@angular-devkit/build-angular : 17.3.8
@angular-devkit/schematics : 17.3.8
@angular/cli : 17.3.8
@ionic/angular-toolkit : 11.0.1

Capacitor:

Capacitor CLI : 6.0.0
@capacitor/android : 6.0.0
@capacitor/core : 6.0.0
@capacitor/ios : 6.0.0

Utility:

cordova-res : not installed globally
native-run : 2.0.1

System:

NodeJS : v20.14.0 (/opt/homebrew/Cellar/node@20/20.14.0/bin/node)
npm : 10.7.0
OS : macOS Unknown

@aussieEd
Copy link

aussieEd commented Jul 5, 2024

Hi, Did you manage to solve this issue? I think am experiencing the same problem.

@metinjakupi
Copy link

I have the same issue

@sfox-developer
Copy link

@rodrigocsaraujo did you solve this issue?

@xbaldiq
Copy link

xbaldiq commented Sep 4, 2024

i am experiencing looping when in ios simulator (sandbox), when using real device it's run fine

@sfox-developer
Copy link

@xbaldiq yes kind of same for me. Actually using a real device e.g. via xcode->iphone or a testflight worked for me.

There are some other issues like not being able to manage the sandbox subscriptions on a device, but that's a different problem. Also there are way more subscriptions created, because the events are fired somewhen more often (couldnt figure out yet why, but i think it's sandbox related).

@xbaldiq
Copy link

xbaldiq commented Sep 6, 2024

@xbaldiq yes kind of same for me. Actually using a real device e.g. via xcode->iphone or a testflight worked for me.

There are some other issues like not being able to manage the sandbox subscriptions on a device, but that's a different problem. Also there are way more subscriptions created, because the events are fired somewhen more often (couldnt figure out yet why, but i think it's sandbox related).

in my case i needed to logout apple account on my device to be able to buy subscription properly and maintain that subscription, otherwise store.when.verified() wouldn't fire at the first launch

@hcassar93
Copy link

Same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants