Open booboothefool opened 5 years ago
Hello, i want to know if you found the best way to do this ? thanks u a lot !
Use cancellationDate & expirationDate that you get from this package.
const validatedData = await iap.validate(receipt);
if (!iap.isValidated(validatedData)) {
throw new Error('validation failed..');
}
const latestPurchaseDataItems = await iap.getPurchaseData(validatedData, {});
const latestPurchaseData = latestPurchaseDataItems[0]
const toStoreInDb = {
cancellationDateMs: latestPurchaseData.cancellationDate ? latestPurchaseData.cancellationDate : null,
expirationDateMs: parseInt(latestPurchaseData.expirationDate),
};
You will then need to implement cron job that runs every hour on server side that starts to refresh existing receipts in the database when it is close to expiring. Once every hour for day before and after.
const daysDelta = 1;
const d1 = getTodaysDateDaysSubtracted(daysDelta);
const d2 = getTodaysDateDaysAdded(daysDelta);
const purchaseReceipts = await mongoExecute(async (db) => {
return await db
.collection('PurchaseReceipt')
.find({
type: constants.PurchaseTypes.subscription,
source: 'purchase',
'data.cancellationDateMs': { $eq: null },
'data.expirationDateMs': {
$gte: d1.getTime(),
$lte: d2.getTime()
},
})
.hint('expirationDateMs')
.toArray();
});
I see the fields:
I noticed they all have a way of doing it. For
latest_receipt_info
seems like have to sort by date then use the expiration,pending_renewal_info => auto_renew_status
andpurchaseData => expirationDate
, etc.I am not sure what they specify exactly because they seem really similar. What is the difference between
latest_receipt_info
andpurchaseData
for example?What is the recommended approach to extend my user's subscription to a later date to store in my backend?