Save InAppPurchase subscription to Firebase and check on Appstart

I have a more or less complex question:

I have an InAppPurchase subscription in my app, therefor iam using the ionic native InAppPurchase Plugin:

The subscription is auto renewal and have a test time of 7 days.

The purchase itself works very well:

buyProduct(productName: string): void {
    console.log(productName);
    InAppPurchase
        .getProducts([productName])
        .then((products) => {
            InAppPurchase
                .buy(productName)
                .then((data)=> {
                    // do something here: maybe store somethign to firebase? But what?
                })
                .catch((err)=> {
                    console.log("error buy");
                    console.log(JSON.stringify(err));
                });
        })
        .catch((err) => {
            console.log("error getProducts");
            console.log(JSON.stringify(err));
        });
}

I have a 2 qustions:

1: How do i check if the subscription is still active?

On App start i want to know, if the subscription is active.

I thinks its easy on Android: there is the function “restorePurchases()”, where you will get a state with “0 - ACTIVE, 1 - CANCELLED, 2 - REFUNDED”.

On IOS i have to save the reciepe somehow, but how? Does someone you have any code examples here?

2: I want to save the current subscription status to firebase.

Whats the best way to do this? Which data should i save?

1 Like

I’m wanting to do the same thing. Ever figure it out?

You can create a simple rest api with nodejs/java + mongo and store the receipt.
You need a :
POST receipt
With json content of the receipt / email
GET receipt with email

It is how I will do it. Even for Android. To have cross platform subscription. In fact i don’t do it with email because I have a user registered.

Imagine your guy buy your subscription on android and at a moment he want to go to ios. He does not have to pay for it because he already did it.
Or if he subscribe on your website

Have a nice day

Thanks @speedflyer for confirming that. I think we’re going to do the same thing. I have users that have both devices, so this makes sense. Here’s a starter I found (haven’t tried it yet).

1 Like

Store the receipt permanently so you have a paper trail. But for your internal bookkeeping I’d recommend creating a data structure that is platform-independent. A subscription for each package you offer, with an enum specifying each possible status of that subscription. Update the data structure for a user in a way that conforms to what the user purchased. Then you have one thing you can read, regardless of which app store the purchase was made on, and regardless of whatever changes to receipt format the app store owners might introduce in the future.

I think google best practices could help:

https://developer.android.com/google/play/developer-api.html#practices

1 Like