diff --git a/src/models/pnid.ts b/src/models/pnid.ts index bca37bb..e12a802 100644 --- a/src/models/pnid.ts +++ b/src/models/pnid.ts @@ -235,9 +235,35 @@ PNIDSchema.method('generateMiiImages', async function generateMiiImages(): Promi await uploadCDNAsset(config.s3.bucket, `${userMiiKey}/body.png`, miiStudioBodyImageData, 'public-read'); }); -PNIDSchema.method('markForDeletion', function markForDeletion() { +PNIDSchema.method('markForDeletion', async function markForDeletion() { this.marked_for_deletion = true; this.hard_delete_time = new Date(Date.now() + (7 * 24 * 3600 * 1000)); // * 7 day grace period + + if (this.connections?.stripe?.subscription_id) { + const subscriptionID = this.connections.stripe.subscription_id; + + try { + if (stripe) { + // * If a user has an active subscription when they mark themselves for deletion, then they + // * may get charged again in those 7 days while not having access to their account. To prevent + // * that, just update the subscription to cancel at the end of the period. That way the charge + // * doesn't happen, and the user likely won't be restoring their account anyway. If they do + // * restore the account and do want their subscription back then they can create a new one + // * after this one expires which is effectively the same as the old subscription renewing. + // * Pausing collection is another option however it requires much more effort on our end to + // * properly resume the paused charges and recitify any missed ones to prevent invoices + // * from being skipped. This method is just way easier for us to deal with right now, at the + // * expense of making the user do a tad more work on their end + await stripe.subscriptions.update(subscriptionID, { + cancel_at_period_end: true + }); + } else { + LOG_WARN(`UPDATING SUBSCRIPTION FOR USER ${this.username}. HAS STRIPE DATA UDER ID ${this.connections.stripe.customer_id}, BUT STRIPE CLIENT NOT ENABLED.`); + } + } catch (error) { + LOG_ERROR(`ERROR UPDATING SUBSCRIPTION FOR USER ${this.username} (${subscriptionID}). ${error}`); + } + } }); PNIDSchema.method('scrub', async function scrub() { diff --git a/src/services/grpc/account/v2/delete-account.ts b/src/services/grpc/account/v2/delete-account.ts index 631dbef..c4fa924 100644 --- a/src/services/grpc/account/v2/delete-account.ts +++ b/src/services/grpc/account/v2/delete-account.ts @@ -21,7 +21,7 @@ export async function deleteAccount(request: DeleteAccountRequest): Promise { + const deletionDate = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toLocaleString('en-US', { + timeZone: 'UTC', + weekday: 'long', + year: 'numeric', + month: 'long', + day: 'numeric' + }); const email = new CreateEmail() .addHeader('Dear {{pnid}},', { pnid: username }) - .addParagraph('your PNID has successfully been deleted.') - .addParagraph('If you had a tier subscription, a separate cancellation email will be sent. If you do not receive this cancellation email, or you are still being charged for your subscription, please contact @jonbarrow on our [Discord server](https://discord.pretendo.network/).'); + .addParagraph('your PNID has been scheduled for deletion.') + .addParagraph(`Your account and related data will be permanently deleted in 7 days (${deletionDate}). Note that this will not free the username associated with the account for use in future accounts. In case of accidental deletion, you may restore your account prior to the deletion date. To restore your account, send an email to \`support@pretendo.network\` from the email address used to register the deleted account, with the subject "Requesting account restore", making sure to include the username of the account being restored. Account restoration requests MUST be sent prior to the account deletion date, ideally more than 24 hours prior, or else account data may already be unrecoverable. For any additional support, please create a support thread on our [forum](https://forum.pretendo.network/). If you have an active tier subscription, or had one in the past, your Stripe account and all data/invoices/subscriptions/etc. will be deleted on the date of account deletion, and cannot be restored. If you have an active subscription which would normally renew on a day prior to the account deletion date, the subscription will be cancelled on the day it would normally rewnew and no new charges will be created. If your account is restored with an active subscription, a new subscription may need to be created after restoration due to the automatic cancelling. If you are still being charged for your subscription within the grace period, please contact @jonbarrow on our [Discord server](https://discord.pretendo.network/) prior to the account deletion date.`); const options = { to: emailAddress, - subject: '[Pretendo Network] PNID Deleted', + subject: '[Pretendo Network] PNID Deletion', email };