This commit is contained in:
Phillip Thelen
2022-11-11 13:58:45 +01:00
committed by Phillip Thelen
parent 87558a325e
commit 0f7001b609
2 changed files with 12 additions and 14 deletions

View File

@@ -9,7 +9,7 @@ import * as gems from '../../../../../website/server/libs/payments/gems';
const { i18n } = common;
describe.only('Apple Payments', () => {
describe('Apple Payments', () => {
const subKey = 'basic_3mo';
describe('verifyPurchase', () => {
@@ -459,7 +459,7 @@ describe.only('Apple Payments', () => {
user.purchased.plan.planId = common.content.subscriptionBlocks.basic_3mo.key;
user.purchased.plan.additionalData = receipt;
user.purchased.plan.dateTerminated = moment.utc().subtract({ day: 1 }).toDate();
await user.save()
await user.save();
iap.getPurchaseData.restore();
iapGetPurchaseDataStub = sinon.stub(iap, 'getPurchaseData')
@@ -467,7 +467,7 @@ describe.only('Apple Payments', () => {
expirationDate: moment.utc().add({ day: 3 }).toDate(),
purchaseDate: moment.utc().toDate(),
productId: sku,
transactionId: token + "new",
transactionId: `${token}new`,
originalTransactionId: token,
}]);
@@ -487,7 +487,6 @@ describe.only('Apple Payments', () => {
});
});
it('allows second user to subscribe if multiple initial subscription are cancelled', async () => {
user.profile.name = 'sender';
user.purchased.plan.paymentMethod = applePayments.constants.PAYMENT_METHOD_APPLE;
@@ -499,7 +498,7 @@ describe.only('Apple Payments', () => {
const secondUser = new User();
secondUser.purchased.plan = user.purchased.plan;
await secondUser.save()
await secondUser.save();
iap.getPurchaseData.restore();
iapGetPurchaseDataStub = sinon.stub(iap, 'getPurchaseData')
@@ -507,7 +506,7 @@ describe.only('Apple Payments', () => {
expirationDate: moment.utc().add({ day: 3 }).toDate(),
purchaseDate: moment.utc().toDate(),
productId: sku,
transactionId: token + "new",
transactionId: `${token}new`,
originalTransactionId: token,
}]);
@@ -602,7 +601,6 @@ describe.only('Apple Payments', () => {
});
});
it('errors when a multiple users exist using the subscription', async () => {
user = new User();
await user.save();
@@ -621,7 +619,7 @@ describe.only('Apple Payments', () => {
const secondUser = new User();
secondUser.purchased.plan = user.purchased.plan;
secondUser.purchased.plan.dateTerminate = new Date();
secondUser.save()
secondUser.save();
iap.getPurchaseData.restore();
iapGetPurchaseDataStub = sinon.stub(iap, 'getPurchaseData')
@@ -629,7 +627,7 @@ describe.only('Apple Payments', () => {
expirationDate: moment.utc().add({ day: 1 }).toDate(),
purchaseDate: moment.utc().toDate(),
productId: sku,
transactionId: token + "new",
transactionId: `${token}new`,
originalTransactionId: token,
}]);

View File

@@ -133,8 +133,7 @@ api.subscribe = async function subscribe (user, receipt, headers, nextPaymentPro
if (purchase.originalTransactionId === purchase.transactionId) {
throw new NotAuthorized(this.constants.RESPONSE_ALREADY_USED);
}
for (const index in existingUsers) {
const existingUser = existingUsers[index];
for (const existingUser of existingUsers) {
if (existingUser._id !== user._id && !existingUser.purchased.plan.dateTerminated) {
throw new NotAuthorized(this.constants.RESPONSE_ALREADY_USED);
}
@@ -262,7 +261,7 @@ api.cancelSubscribe = async function cancelSubscribe (user, headers) {
const purchases = iap.getPurchaseData(appleRes);
if (purchases.length === 0) throw new NotAuthorized(this.constants.RESPONSE_INVALID_RECEIPT);
let newestDate;
let newestPurchase
let newestPurchase;
for (const purchaseData of purchases) {
const datePurchased = new Date(Number(purchaseData.purchaseDate));
@@ -272,7 +271,9 @@ api.cancelSubscribe = async function cancelSubscribe (user, headers) {
}
}
if (!iap.isCanceled(newestPurchase) && !iap.isExpired(newestPurchase)) throw new NotAuthorized(this.constants.RESPONSE_STILL_VALID);
if (!iap.isCanceled(newestPurchase) && !iap.isExpired(newestPurchase)) {
throw new NotAuthorized(this.constants.RESPONSE_STILL_VALID);
}
await payments.cancelSubscription({
user,
@@ -289,7 +290,6 @@ api.cancelSubscribe = async function cancelSubscribe (user, headers) {
throw err;
}
}
};
export default api;