Skip to content

[PB-6910]: feat/send the account setup email when a new customer's payment is confirmed - #410

Closed
xabg2 wants to merge 3 commits into
masterfrom
feat/PB-6910-send-account-setup-email-on-payment
Closed

xabg2 wants to merge 3 commits into
masterfrom
feat/PB-6910-send-account-setup-email-on-payment

Conversation

@xabg2

@xabg2 xabg2 commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

What's new

  • When the payment of a customer without a Drive account is confirmed, they receive the email to finish setting up their account, with the name of the plan they bought.

@xabg2 xabg2 self-assigned this Sep 28, 2026
@xabg2 xabg2 added the enhancement New feature or request label Sep 28, 2026
@sonarqubecloud

Copy link
Copy Markdown

const userByCustomerId = await this.usersService.findUserByCustomerID(customerId);
if (userByCustomerId) {
return { uuid: userByCustomerId.uuid };
return { uuid: userByCustomerId.uuid, isRegisteredInDrive: false };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hardcoding isRegisteredInDrive: false here relies on the email lookup having failed, but that lookup swallows any error (see the catch above). If Drive fails transiently on findUserByEmail, a registered user is found by customer ID and gets the account setup email by mistake. Why not get this from a real source instead of inferring it from which lookup path succeeded?


const isPendingAccountSetup = !isRegisteredInDrive && !isBusinessPlan;
if (isPendingAccountSetup) {
await this.usersService.sendAccountSetupEmail(userUuid, productName ?? FALLBACK_PLAN_NAME);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If this call fails, the whole webhook fails after the plan was already applied, and every retry re-applies the tier and sends the email again (the redelivery test confirms it is sent twice). Any later failure in run() (e.g. handleUserCouponRelationship) also triggers a duplicate email. Is this intentional?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Nice catch, we have to prevent it. Should be sent just once.

});
});

describe('Payment confirmed for a customer who has not finished the account setup', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The initial block of code for this is... a bit weird and chaotic. Please refactor it a bit.

@xabg2

xabg2 commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

Closing due to new refactored and improved PR.

@xabg2 xabg2 closed this Oct 2, 2026

This branch was successfully deployed

1 active deployment
test — c68c1d85 Deployed Sep 28, 2026 by xabg2 via Run tests (24.11.0) #1125
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ready-for-preview

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants