Skip to content

Commit

Permalink
Email successful referrals && Add Paypal to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
asennoussi committed Aug 26, 2023
1 parent c7b045f commit 202f964
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 3 deletions.
18 changes: 18 additions & 0 deletions accounts/migrations/0016_customuser_paypal_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.1 on 2023-08-26 19:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0015_linkedaccounts_check_spam'),
]

operations = [
migrations.AddField(
model_name='customuser',
name='paypal_email',
field=models.EmailField(max_length=254, null=True, verbose_name='Paypal email address'),
),
]
18 changes: 18 additions & 0 deletions accounts/migrations/0017_alter_customuser_paypal_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.1 on 2023-08-26 20:15

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0016_customuser_paypal_email'),
]

operations = [
migrations.AlterField(
model_name='customuser',
name='paypal_email',
field=models.EmailField(blank=True, max_length=254, null=True, verbose_name='Paypal email address'),
),
]
2 changes: 2 additions & 0 deletions accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class CustomUser(AbstractUser):
)
username = None
email = models.EmailField(_('email address'), unique=True)
paypal_email = models.EmailField(
_('Paypal email address'), null=True, blank=True)
count_contact = models.IntegerField(default=0)
subscription_status = models.CharField(
max_length=20, choices=SUBSCRIPTION_STATUS, default='trial')
Expand Down
2 changes: 1 addition & 1 deletion accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def form_valid(self, form):
user.is_verified = False # Turns the user email verification to False
user.save()

# form.send_activation_email(self.request, user)
form.send_activation_email(self.request, user)
# When the user signs up check if the referral is there.
if form.cleaned_data['referral_code']:
form.create_referral(form.cleaned_data['referral_code'], user)
Expand Down
2 changes: 2 additions & 0 deletions emailguru/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@

GTM_CONTAINER_ID = 'GTM-XXXXXXX'

REFERRAL_PAYOUT_VALUE = 2

try:
from .local_settings import *
except ImportError:
Expand Down
18 changes: 18 additions & 0 deletions referral/migrations/0004_referral_paid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.1 on 2023-08-26 20:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('referral', '0003_referral_created_at_referral_inviter_and_more'),
]

operations = [
migrations.AddField(
model_name='referral',
name='paid',
field=models.BooleanField(default=False),
),
]
1 change: 1 addition & 0 deletions referral/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Referral(models.Model):
# Additional fields to track referral information
created_at = models.DateTimeField(auto_now_add=True)
successful = models.BooleanField(default=False)
paid = models.BooleanField(default=False)

class Meta:
unique_together = ('inviter', 'referred_user')
Expand Down
28 changes: 26 additions & 2 deletions referral/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
from .models import Referral
from django.utils import timezone

from django.template.loader import render_to_string
import django_rq
from django.conf import settings


@receiver(post_save, sender=CustomUser)
def process_referral(sender, instance, **kwargs):
Expand All @@ -28,13 +32,33 @@ def process_referral(sender, instance, **kwargs):
# You might want to set it to some default datetime value or log an error.
inviter.expires_at = timezone.now() + timedelta(days=14)

# Extend the inviter's payment due date by 14 days
inviter.expires_at += timedelta(days=14)
inviter.save()

# Mark the referral as successful
referral.successful = True
referral.save()

# Send an Email to the inviter informing them of the successful referral
template_name = 'email-referral-success.html'
subject = 'Congratulations! You got a new successful referral on Emailgurus'

referral_count = Referral.objects.filter(
inviter=inviter, successful=True, paid=False).count() or 0

balance = referral_count * settings.REFERRAL_PAYOUT_VALUE

payload = {
'balance': balance,
'has_paypal_email': inviter.paypal_email
}
message = render_to_string(
'emails/' + template_name,
payload
)

django_rq.enqueue(user.email_user,
subject, message, html_message=message)

except Referral.DoesNotExist:
# No referral exists for this user, do nothing
pass
187 changes: 187 additions & 0 deletions referral/templates/emails/email-referral-success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html data-editor-version="2" class="sg-campaigns" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<!--[if !mso]><!-->
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<!--<![endif]-->
<!--[if (gte mso 9)|(IE)]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<!--[if (gte mso 9)|(IE)]>
<style type="text/css">
body {width: 600px;margin: 0 auto;}
table {border-collapse: collapse;}
table, td {mso-table-lspace: 0pt;mso-table-rspace: 0pt;}
img {-ms-interpolation-mode: bicubic;}
</style>
<![endif]-->
<style type="text/css">
body, p, div {
font-family: arial,helvetica,sans-serif;
font-size: 14px;
}
body {
color: #000000;
}
body a {
color: #1188E6;
text-decoration: none;
}
p { margin: 0; padding: 0; }
table.wrapper {
width:100% !important;
table-layout: fixed;
-webkit-font-smoothing: antialiased;
-webkit-text-size-adjust: 100%;
-moz-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
img.max-width {
max-width: 100% !important;
}
.column.of-2 {
width: 50%;
}
.column.of-3 {
width: 33.333%;
}
.column.of-4 {
width: 25%;
}
ul ul ul ul {
list-style-type: disc !important;
}
ol ol {
list-style-type: lower-roman !important;
}
ol ol ol {
list-style-type: lower-latin !important;
}
ol ol ol ol {
list-style-type: decimal !important;
}
@media screen and (max-width:480px) {
.preheader .rightColumnContent,
.footer .rightColumnContent {
text-align: left !important;
}
.preheader .rightColumnContent div,
.preheader .rightColumnContent span,
.footer .rightColumnContent div,
.footer .rightColumnContent span {
text-align: left !important;
}
.preheader .rightColumnContent,
.preheader .leftColumnContent {
font-size: 80% !important;
padding: 5px 0;
}
table.wrapper-mobile {
width: 100% !important;
table-layout: fixed;
}
img.max-width {
height: auto !important;
max-width: 100% !important;
}
a.bulletproof-button {
display: block !important;
width: auto !important;
font-size: 80%;
padding-left: 0 !important;
padding-right: 0 !important;
}
.columns {
width: 100% !important;
}
.column {
display: block !important;
width: 100% !important;
padding-left: 0 !important;
padding-right: 0 !important;
margin-left: 0 !important;
margin-right: 0 !important;
}
.social-icon-column {
display: inline-block !important;
}
}
</style>
<!--user entered Head Start--><!--End Head user entered-->
</head>
<body>
<center class="wrapper" data-link-color="#1188E6" data-body-style="font-size:14px; font-family:arial,helvetica,sans-serif; color:#000000; background-color:#FFFFFF;">
<div class="webkit">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="wrapper" bgcolor="#FFFFFF">
<tr>
<td valign="top" bgcolor="#FFFFFF" width="100%">
<table width="100%" role="content-container" class="outer" align="center" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="100%">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<!--[if mso]>
<center>
<table><tr><td width="600">
<![endif]-->
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="width:100%; max-width:600px;" align="center">
<tr>
<td role="modules-container" style="padding:0px 0px 0px 0px; color:#000000; text-align:left;" bgcolor="#FFFFFF" width="100%" align="left"><table class="module preheader preheader-hide" role="module" data-type="preheader" border="0" cellpadding="0" cellspacing="0" width="100%" style="display: none !important; mso-hide: all; visibility: hidden; opacity: 0; color: transparent; height: 0; width: 0;">
<tr>
<td role="module-content">
<p></p>
</td>
</tr>
</table><table class="wrapper" role="module" data-type="image" border="0" cellpadding="0" cellspacing="0" width="100%" style="table-layout: fixed;" data-muid="2f67fbc4-9b9a-424a-bbc3-bce416d4ecc6">
<tbody>
<tr>
<td style="font-size:6px; line-height:10px; padding:0px 0px 0px 0px;" valign="top" align="center">
<img class="max-width" border="0" style="display:block; color:#000000; text-decoration:none; font-family:Helvetica, arial, sans-serif; font-size:16px; max-width:21% !important; width:21%; height:auto !important;" width="126" alt="" data-proportionally-constrained="true" data-responsive="true" src="http://cdn.mcauto-images-production.sendgrid.net/4642ef324c7fce82/ec6ec129-f570-4f92-b3db-31e07d7d4f49/240x240.png">
</td>
</tr>
</tbody>
</table><table class="module" role="module" data-type="text" border="0" cellpadding="0" cellspacing="0" width="100%" style="table-layout: fixed;" data-muid="3e75c454-d892-435b-9e56-029c3f7c9cad" data-mc-module-version="2019-10-22">
<tbody>
<tr>
<td style="padding:18px 0px 18px 0px; line-height:22px; text-align:inherit;" height="100%" valign="top" bgcolor="" role="module-content"><div><div style="font-family: inherit; text-align: inherit">Hello,</div>
<div style="font-family: inherit; text-align: inherit">You have successfully referred a user to Emailgurus.&nbsp;</div>
<div style="font-family: inherit; text-align: inherit">Your total balance now is <strong>${{balance}}</strong></div>
<div style="font-family: inherit; text-align: inherit"><br></div>
{%if not has_paypal_email%}
<div style="font-family: inherit; text-align: inherit">Please update your Paypal details on your <a href="https://emailgurus.xyz/dashboard/settings"><u>profile</u></a> to wire the funds.&nbsp;</div>
{%endif%}
{%if balance < 10%}
<div style="font-family: inherit; text-align: inherit">Please note that the minimum threshold to payout is $10</div><div></div></div></td>
{%endif%}
</tr>
</tbody>
</table></td>
</tr>
</table>
<!--[if mso]>
</td>
</tr>
</table>
</center>
<![endif]-->
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</center>
</body>
</html>

0 comments on commit 202f964

Please sign in to comment.