Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: paddle transaction management for gifting #2648

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sshanzel
Copy link
Member

@sshanzel sshanzel commented Feb 8, 2025

One-time payments are not considered subscriptions in Paddle's dictionary, so we must handle the event for gifting within the TransactionCompleted. Events available are as below:

Screenshot 2025-02-08 at 12 38 33 PM

Test cases still check out.

Comment on lines -89 to -115
const { gifter_id: gifterId } = customData;
const duration = subscriptionGiftDuration;
const isGift = !!gifterId;
if (isGift) {
if (userId === gifterId) {
logger.error({ type: 'paddle', data }, 'User and gifter are the same');
return false;
}

const gifterUser = await con
.getRepository(User)
.findOneBy({ id: gifterId });
if (!gifterUser) {
logger.error({ type: 'paddle', data }, 'Gifter user not found');
return false;
}

const targetUser = await con.getRepository(User).findOne({
select: ['subscriptionFlags'],
where: { id: userId },
});
if (isPlusMember(targetUser?.subscriptionFlags?.cycle)) {
logger.error({ type: 'paddle', data }, 'User is already a Plus member');
return false;
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to its own function to lessen the noise here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant