From bd100bb5b95fd988ed0bcbacdfb29452cdc4888a Mon Sep 17 00:00:00 2001 From: Lee Hansel Solevilla Date: Fri, 2 May 2025 14:51:46 +0800 Subject: [PATCH 1/3] fix: deleting an account with gifted subscription --- src/common/user.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/common/user.ts b/src/common/user.ts index 36244770b2..00f6511024 100644 --- a/src/common/user.ts +++ b/src/common/user.ts @@ -47,16 +47,20 @@ export const deleteUser = async ( } if (subscriptionFlags?.provider === SubscriptionProvider.Paddle) { - await cancelSubscription({ - subscriptionId: subscriptionFlags.subscriptionId, - }); + const isGifted = !!subscriptionFlags.giftExpirationDate; + // gifted subscription is a one-time payment hence not considered subscription in Paddle's terms + if (!isGifted) { + await cancelSubscription({ + subscriptionId: subscriptionFlags.subscriptionId, + }); + } logger.info( { provider: SubscriptionProvider.Paddle, userId, subscriptionId: subscriptionFlags.subscriptionId, }, - 'Subscription cancelled user deletion', + `Subscription${isGifted ? ' (gifted)' : ''} cancelled user deletion`, ); } } From 8f755f0afffb18ace87186f0ced877784e6dcaef Mon Sep 17 00:00:00 2001 From: Lee Hansel Solevilla Date: Fri, 2 May 2025 20:03:29 +0800 Subject: [PATCH 2/3] refactor: error logging --- src/common/user.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/user.ts b/src/common/user.ts index 00f6511024..ad07b63b24 100644 --- a/src/common/user.ts +++ b/src/common/user.ts @@ -58,9 +58,10 @@ export const deleteUser = async ( { provider: SubscriptionProvider.Paddle, userId, + isGifted, subscriptionId: subscriptionFlags.subscriptionId, }, - `Subscription${isGifted ? ' (gifted)' : ''} cancelled user deletion`, + 'Subscription cancelled user deletion', ); } } From e038f9101dc33a867a8674dc83180fe4358f1111 Mon Sep 17 00:00:00 2001 From: Lee Hansel Solevilla Date: Fri, 2 May 2025 20:11:08 +0800 Subject: [PATCH 3/3] test: gifted user cancellation --- __tests__/users.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/__tests__/users.ts b/__tests__/users.ts index 0275e004a2..5301f03ffa 100644 --- a/__tests__/users.ts +++ b/__tests__/users.ts @@ -4059,6 +4059,27 @@ describe('mutation deleteUser', () => { expect(userOne).toEqual(null); }); + it('should not call cancel subscription for gifted subscription', async () => { + loggedUser = '1'; + + await con.getRepository(User).update( + { id: '1' }, + { + subscriptionFlags: updateSubscriptionFlags({ + subscriptionId: '123', + provider: SubscriptionProvider.Paddle, + giftExpirationDate: new Date(Date.now() + 86400000), // 1 day from now + }), + }, + ); + + await client.mutate(MUTATION); + + expect(cancelSubscription).not.toHaveBeenCalled(); + const userOne = await con.getRepository(User).findOneBy({ id: '1' }); + expect(userOne).toEqual(null); + }); + describe('when user has a storekit subscription', () => { beforeEach(async () => { await saveFixtures(con, User, [