Repository: mdn/kuma

Issue:
T - Make subscription contribution amt dynamic
**Summary**
People in the previous MDN payment experiment could pick their contribution amount. The current email invoice assumes it's $5. The attached invoice PDF has the correct value. That's rather confusing.

**Actual behavior**
People who signed up to contribute $1 get message that they will be charged $5.


**Expected behavior**
Either we cancel the experimental subscriptions or we make the amount displayed dynamic.



Discussion:

Resolving patch:
diff --git a/kuma/users/views.py b/kuma/users/views.py
--- a/kuma/users/views.py
+++ b/kuma/users/views.py
@@ -856,10 +856,8 @@ def stripe_hooks(request):
     # to deal with here.
 
     if event.type == "invoice.payment_succeeded":
-        payment_intent = event.data.object
-        _send_payment_received_email(
-            payment_intent, request.LANGUAGE_CODE,
-        )
+        invoice = event.data.object
+        _send_payment_received_email(invoice, request.LANGUAGE_CODE)
         track_event(
             CATEGORY_MONTHLY_PAYMENTS,
             ACTION_SUBSCRIPTION_CREATED,
@@ -880,15 +878,15 @@ def stripe_hooks(request):
     return HttpResponse()
 
 
-def _send_payment_received_email(payment_intent, locale):
-    user = get_user_model().objects.get(stripe_customer_id=payment_intent.customer)
+def _send_payment_received_email(invoice, locale):
+    user = get_user_model().objects.get(stripe_customer_id=invoice.customer)
     subscription_info = retrieve_and_synchronize_subscription_info(user)
     locale = locale or settings.WIKI_DEFAULT_LANGUAGE
     context = {
-        "payment_date": datetime.fromtimestamp(payment_intent.created),
+        "payment_date": datetime.fromtimestamp(invoice.created),
         "next_payment_date": subscription_info["next_payment_at"],
-        "invoice_number": payment_intent.number,
-        "cost": settings.CONTRIBUTION_AMOUNT_USD,
+        "invoice_number": invoice.number,
+        "cost": invoice.total / 100,
         "credit_card_brand": subscription_info["brand"],
         "manage_subscription_url": absolutify(reverse("recurring_payment_management")),
         "faq_url": absolutify(reverse("payments_index")),
@@ -906,8 +904,8 @@ def _send_payment_received_email(payment_intent, locale):
             settings.DEFAULT_FROM_EMAIL,
             [user.email],
             attachment={
-                "name": os.path.basename(urlparse(payment_intent.invoice_pdf).path),
-                "bytes": _download_from_url(payment_intent.invoice_pdf),
+                "name": os.path.basename(urlparse(invoice.invoice_pdf).path),
+                "bytes": _download_from_url(invoice.invoice_pdf),
                 "mime": "application/pdf",
             },
         )


Test patch:
diff --git a/kuma/users/tests/test_stripe_subscription.py b/kuma/users/tests/test_stripe_subscription.py
--- a/kuma/users/tests/test_stripe_subscription.py
+++ b/kuma/users/tests/test_stripe_subscription.py
@@ -172,6 +172,7 @@ def test_stripe_payment_succeeded_sends_invoice_mail(
         data=SimpleNamespace(
             object=SimpleNamespace(
                 number="test_invoice_001",
+                total=700,
                 customer="cus_mock_testuser",
                 created=1583842724,
                 invoice_pdf="https://developer.mozilla.org/mock-invoice-pdf-url",
@@ -199,7 +200,7 @@ def test_stripe_payment_succeeded_sends_invoice_mail(
     assert payment_email.to == [testuser.email]
     assert "Receipt" in payment_email.subject
     assert "Invoice number: test_invoice_001" in payment_email.body
-    assert "You supported MDN with a $4.99 monthly subscription" in payment_email.body
+    assert "You supported MDN with a $7.00 monthly subscription" in payment_email.body
     assert "manage monthly subscriptions" in payment_email.body