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

Issue 249: Payment confirmation email #688

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 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,9 @@ 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)