Skip to content

Commit

Permalink
Issue 249: add successful_payment_email function and test to check em…
Browse files Browse the repository at this point in the history
…ail sending
  • Loading branch information
Beloborodova-Anastasiia committed Aug 1, 2023
1 parent 7535891 commit 9bb1c4a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions memberships/payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def handle_stripe_payment(event):
update_last_payment(event, member)
add_user_membership_permission(member)
set_membership_renewal_date(member)
successful_payment_email(member)
return HttpResponse(200)

return HttpResponse(200)
Expand Down Expand Up @@ -103,3 +104,8 @@ def failed_payment_email(member):
subject = "Your payment failed!"
body = "Something seems to have gone wrong with your payment."
task_send_email(member.preferred_name, member.email, subject, body)

def successful_payment_email(member):
subject = "Your payment successful!"
body = "Thank you for your payment."
task_send_email(member.preferred_name, member.email, subject, body)
19 changes: 19 additions & 0 deletions memberships/tests/test_stripe_webhooks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.urls import reverse
from django.contrib.auth.models import User, Permission
from django.core import mail

from .utils import StripeTestCase
from memberships.models import Member, Membership, FailedPayment, Payment
Expand Down Expand Up @@ -184,3 +185,21 @@ def test_new_member_is_given_user_permission_on_payment(self):
user = User.objects.get(id=self.member.user_id)

self.assertEqual(True, user.has_perm("memberships.has_membership"))

def test_a_successful_payment_send_email(self):
response = self.client.post(
reverse("stripe_webhook"),
{
"type": "invoice.paid",
"data": {
"object": {
"customer_email": "test@example.com",
"subscription": "sub_12345",
}
},
"created": 1611620481,
},
content_type="application/json",
)

self.assertEqual(len(mail.outbox), 1)

0 comments on commit 9bb1c4a

Please sign in to comment.