[FIX] Student membership creation (#2144)

[FIX] Student membership creation (#2144)

diff --git a/ankihub/memberships/services.py b/ankihub/memberships/services.py
index c309971..eb1aa91 100644
--- a/ankihub/memberships/services.py
+++ b/ankihub/memberships/services.py
@@ -171,7 +171,7 @@ class MembershipHandler:
             issuer=issuer,
         )
 
-        if not user.customer_id:
+        if customer and not user.customer_id:
             user.customer_id = customer.get("id")
             user.save(update_fields=["customer_id"])
 
diff --git a/ankihub/memberships/tests/test_services.py b/ankihub/memberships/tests/test_services.py
index eb6867f..b894b4a 100644
--- a/ankihub/memberships/tests/test_services.py
+++ b/ankihub/memberships/tests/test_services.py
@@ -244,6 +244,20 @@ def test_get_or_create_membership_for_organization(
     assert organization.membership == membership
 
 
+def test_get_or_create_membership_no_stripe(mocker: MockerFixture, user: User) -> None:
+    mock_stripe = mocker.patch.object(
+        MembershipHandler, "get_or_create_stripe_customer"
+    )
+    sh = MembershipHandler()
+    membership = sh.get_or_create_membership(user=user, payment_method="paypal")
+
+    mock_stripe.assert_not_called()
+    assert membership.user == user
+    assert membership.revenue == Decimal(0)
+    assert membership.status == MembershipStatusChoices.INACTIVE
+    assert membership.metadata == {}
+
+
 def test_get_customer_by_id(mocker: MockerFixture, user: User) -> None:
     excepted_value = {"customer": {"id": "1"}}
     mocker.patch.object(stripe.Customer, "retrieve", return_value=excepted_value)

GitHub
sha: cca9b37c64b68a5a362eb070f8f1381c33ba8b8d