mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
ios: cancel invalid subscriptions without errors (#11035)
This commit is contained in:
@@ -239,6 +239,9 @@ api.cancelSubscribe = async function cancelSubscribe (user, headers) {
|
||||
|
||||
await iap.setup();
|
||||
|
||||
let dateTerminated;
|
||||
|
||||
try {
|
||||
let appleRes = await iap.validate(iap.APPLE, plan.additionalData);
|
||||
|
||||
let isValidated = iap.isValidated(appleRes);
|
||||
@@ -248,8 +251,14 @@ api.cancelSubscribe = async function cancelSubscribe (user, headers) {
|
||||
if (purchases.length === 0) throw new NotAuthorized(this.constants.RESPONSE_INVALID_RECEIPT);
|
||||
let subscriptionData = purchases[0];
|
||||
|
||||
let dateTerminated = new Date(Number(subscriptionData.expirationDate));
|
||||
dateTerminated = new Date(Number(subscriptionData.expirationDate));
|
||||
if (dateTerminated > new Date()) throw new NotAuthorized(this.constants.RESPONSE_STILL_VALID);
|
||||
} catch (err) {
|
||||
// If we have an invalid receipt, cancel anyway
|
||||
if (!err || !err.validatedData || err.validatedData.is_retryable === true || err.validatedData.status !== 21010) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
await payments.cancelSubscription({
|
||||
user,
|
||||
|
||||
Reference in New Issue
Block a user