Craig-Ronald / capacitor-subscriptions

MIT License
12 stars 5 forks source link

Issue with Retrieving Active Subscriptions Using `getCurrentEntitlements()` Method #14

Open sinanverve7 opened 4 months ago

sinanverve7 commented 4 months ago

Hi @CraigRonald555

I hope this message finds you well. I am currently implementing the "capacitor-subscriptions" plugin in our iOS application to manage subscription services. However, I am encountering a recurring issue where the getCurrentEntitlements() method does not return active subscriptions, even though they exist.

implementation Details

Every time a user logs into our app, I call the getCurrentEntitlements() method to check for any active subscriptions. Below is the relevant segment of our implementation:

if (this._subService.firstOpen) {
  this._subService.firstOpen = false;
  setTimeout(async () => {
    const response: CurrentEntitlementsResponse = await Subscriptions.getCurrentEntitlements();
    console.log('new IAP RES ', response);
    const receipt = await this._inAppPurchase.getReceipt().catch((err) => {
      console.log('get receipt error==>', err);
    });
    console.log('GET RECEIPT RES==>', receipt);

    if (response.responseCode == 0) {
      return response.data;
    } else {
      return [];
    }
  }, 0);
}

Issue observed

Despite having active subscriptions, the getCurrentEntitlements() method consistently returns the following response:

[Log] new IAP RES – {responseCode: 1, responseMessage: "No entitlements were found"} (vendor.js, line 60364)

Verification and Additional Context

To verify the presence of an active subscription, I used another plugin ("cordova-plugin-inapppurchase") to fetch the receipt, which indeed shows a lengthy encrypted response indicating an active subscription.

Screenshot Attached:

I am also attaching a screenshot that clearly shows an active subscription for our app, which should normally be detected by this plugin. subscriptions-screenshot

Request

Could you please investigate why getCurrentEntitlements() might not be detecting active subscriptions as expected?

Thank you for your assistance. I look forward to your prompt response and am hopeful for a resolution.

Best regards, Sinan

NOTE : I haven't setup storekit configuration file

TomDoesb commented 4 months ago

I think you are misunderstanding how getCurrentEntitlements works.. It retrieves the subscriptions/purchases of the current app and only the ones in the correct environment. So the in dev/testflight environment it will not retrieve actual production purchases.

This has nothing to do with the library but with how apples storekit works.

sinanverve7 commented 4 months ago

Hi @TomDoesb i have few doubts regarding your solution.

  1. will it retrieve active subscriptions only once ?
  2. cannot we test the implementation in dev/testflight environment?
CraigRonald555 commented 4 months ago

Hi @TomDoesb

i have few doubts regarding your solution.

  1. will it retrieve active subscriptions only once ?

  2. cannot we test the implementation in dev/testflight environment?

It will receive any subscriptions which are active, every time.

You can, but it requires setting up a sandbox account which is separate from your actual iOS account.

This needs to be set up in TestFlight within AppStoreConnect, you can then log in and manage sandbox subscriptions from your phone by going to Settings > App Store > Sandbox Account as shown below

image

image