mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Prevent server from cancelling still active subs (#11795)
* Prevent server from cancelling still active subs * Allow subs to be cancelled before end date * fix test * fix test
This commit is contained in:
@@ -234,6 +234,9 @@ api.cancelSubscribe = async function cancelSubscribe (user, headers) {
|
||||
const purchases = iap.getPurchaseData(googleRes);
|
||||
if (purchases.length === 0) throw new NotAuthorized(this.constants.RESPONSE_INVALID_RECEIPT);
|
||||
const subscriptionData = purchases[0];
|
||||
// Check to make sure the sub isn't active anymore.
|
||||
if (subscriptionData.autoRenews) return;
|
||||
|
||||
dateTerminated = new Date(Number(subscriptionData.expirationDate));
|
||||
} catch (err) {
|
||||
// Status:410 means that the subsctiption isn't active anymore and we can safely delete it
|
||||
@@ -244,8 +247,6 @@ api.cancelSubscribe = async function cancelSubscribe (user, headers) {
|
||||
}
|
||||
}
|
||||
|
||||
if (dateTerminated > new Date()) throw new NotAuthorized(this.constants.RESPONSE_STILL_VALID);
|
||||
|
||||
await payments.cancelSubscription({
|
||||
user,
|
||||
nextBill: dateTerminated,
|
||||
|
||||
Reference in New Issue
Block a user