Wizcorp/node-iap

Checking if auto renewable subscription is valid..

Opened this issue · 1 comments

Thank you for this library, but i would like to ask something since it's my first time implementing auto renewable subscription..

So now after the user purchase the subscription i should send the receipt to my backend and validate it, and then if it's valid i should store the receipt and the expiration date in my db, and since i have a corn job that runs daily i can check if the subscription is expired, and if it's i can send the receipt again to check if it's renewed or not, is that right? and if it returns an error meaning that it's not valid anymore?

app.post('/receipt-validation' , (request , response) => {

  const platform = request.body.platform;
  const userId = request.body.userId;
  const receipt = request.body.platform;

  const payment = {
    receipt: receipt, // always required
    productId: 'com.shamhandev.snaplearn',
    packageName: 'com.shamhandev.snaplearn',
    excludeOldTransactions: true, // ios
    secret: 'password',      
    subscription: true,	// optional, if google play subscription
    keyObject: {}, // required, if google
  };


  iap.verifyPayment(platform, payment)
  .then(
    res => {	
       //Updating subscription status in db
    },
    err => {
        /* your code */ 
    }
)



});

@Abdullah-Shamhan You have the right idea. Our service followed much of what you proposed.

The only improvement I would suggest is to look into real-time notifications from app stores that offer it. Cancellations, renewals, or even upgrades/downgrades, are all events you'll want to capture in real-time. The reason for this is keeping your service up-to-date with the app store.

Let me know if you have any questions since in-app purchases is a world in itself.