-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
STRIPE_PUBLIC_KEY= | ||
STRIPE_PRIVATE_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from djstripe.models import PaymentMethod | ||
from rest_framework import viewsets | ||
from rest_framework.permissions import IsAuthenticated | ||
|
||
from ckc.serializers import PaymentMethodSerializer | ||
|
||
|
||
class PaymentMethodViewSet(viewsets.ModelViewSet): | ||
queryset = PaymentMethod.objects.all() | ||
serializer_class = PaymentMethodSerializer | ||
permission_classes = [IsAuthenticated] | ||
|
||
def get_queryset(self): | ||
qs = PaymentMethod.objects.filter(customer__subscriber=self.request.user) | ||
return qs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ pytest-django==4.5.2 | |
flake8==6.0.0 | ||
|
||
# payment processing | ||
djstripe==2.8.3 | ||
dj-stripe==2.8.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from django.urls import reverse | ||
from djstripe.models import PaymentMethod, Customer | ||
from rest_framework.test import APITestCase | ||
|
||
from django.contrib.auth import get_user_model | ||
|
||
User = get_user_model() | ||
|
||
|
||
class TestExceptions(APITestCase): | ||
def setUp(self): | ||
self.user = User.objects.create_user(username="test", password="test") | ||
self.client.force_authenticate(user=self.user) | ||
return super().setUp() | ||
|
||
def test_payment_method(self): | ||
# simulate card being created on the frontend | ||
url = reverse('payment-methods-list') | ||
payload = {"token": "pm_card_visa"} | ||
resp = self.client.post(url, data=payload, format='json') | ||
|
||
# assert payment method and customer creation | ||
assert resp.status_code == 201 | ||
assert PaymentMethod.objects.count() == 1 | ||
assert Customer.objects.count() == 1 |