mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Better handling for cancellation when user had multiple subs
This commit is contained in:
committed by
Phillip Thelen
parent
967717a010
commit
ddf1b4060d
@@ -97,8 +97,8 @@ api.subscribe = async function subscribe (user, receipt, headers, nextPaymentPro
|
||||
if ((!newestDate || datePurchased > newestDate) && dateTerminated > new Date()) {
|
||||
originalTransactionId = purchaseData.originalTransactionId;
|
||||
newTransactionId = purchaseData.transactionId;
|
||||
newestDate = datePurchased
|
||||
sku = purchaseData.productId
|
||||
newestDate = datePurchased;
|
||||
sku = purchaseData.productId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,9 +255,16 @@ api.cancelSubscribe = async function cancelSubscribe (user, headers) {
|
||||
|
||||
const purchases = iap.getPurchaseData(appleRes);
|
||||
if (purchases.length === 0) throw new NotAuthorized(this.constants.RESPONSE_INVALID_RECEIPT);
|
||||
const subscriptionData = purchases[0];
|
||||
let newestDate;
|
||||
|
||||
for (const purchaseData of purchases) {
|
||||
const datePurchased = new Date(Number(purchaseData.purchaseDate));
|
||||
if (!newestDate || datePurchased > newestDate) {
|
||||
dateTerminated = new Date(Number(purchaseData.expirationDate));
|
||||
newestDate = datePurchased;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user