full passing test suite w. new stripe integration across multiple project nodes; new gameboard django app; stripe in test mode on staging
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
import stripe
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db.models import Max, Q
|
||||
from django.http import HttpResponse, HttpResponseForbidden
|
||||
from django.http import HttpResponse, HttpResponseForbidden, JsonResponse
|
||||
from django.shortcuts import redirect, render
|
||||
from django.views.decorators.csrf import ensure_csrf_cookie
|
||||
|
||||
from apps.dashboard.forms import ExistingListItemForm, ItemForm
|
||||
from apps.dashboard.models import Applet, Item, List, UserApplet
|
||||
from apps.lyric.models import Token, User, Wallet
|
||||
from apps.lyric.models import PaymentMethod, Token, User, Wallet
|
||||
|
||||
|
||||
APPLET_ORDER = ["wallet", "new-list", "my-lists", "username", "palette"]
|
||||
@@ -146,6 +150,7 @@ def toggle_applets(request):
|
||||
return redirect("home")
|
||||
|
||||
@login_required(login_url="/")
|
||||
@ensure_csrf_cookie
|
||||
def wallet(request):
|
||||
wallet = request.user.wallet
|
||||
coin = request.user.tokens.filter(token_type=Token.COIN).first()
|
||||
@@ -155,3 +160,31 @@ def wallet(request):
|
||||
"coin": coin,
|
||||
"free_tokens": free_tokens,
|
||||
})
|
||||
|
||||
@login_required(login_url="/")
|
||||
def setup_intent(request):
|
||||
stripe.api_key = settings.STRIPE_SECRET_KEY
|
||||
user = request.user
|
||||
if not user.stripe_customer_id:
|
||||
customer = stripe.Customer.create(email=user.email)
|
||||
user.stripe_customer_id = customer.id
|
||||
user.save(update_fields=["stripe_customer_id"])
|
||||
intent = stripe.SetupIntent.create(customer=user.stripe_customer_id)
|
||||
return JsonResponse({
|
||||
"client_secret": intent.client_secret,
|
||||
"publishable_key": settings.STRIPE_PUBLISHABLE_KEY,
|
||||
})
|
||||
|
||||
@login_required(login_url="/")
|
||||
def save_payment_method(request):
|
||||
stripe.api_key = settings.STRIPE_SECRET_KEY
|
||||
pm_id = request.POST.get("payment_method_id")
|
||||
pm = stripe.PaymentMethod.retrieve(pm_id)
|
||||
stripe.PaymentMethod.attach(pm_id, customer=request.user.stripe_customer_id)
|
||||
PaymentMethod.objects.create(
|
||||
user=request.user,
|
||||
stripe_pm_id=pm_id,
|
||||
last4=pm.card.last4,
|
||||
brand=pm.card.brand,
|
||||
)
|
||||
return JsonResponse({"last4": pm.card.last4, "brand": pm.card.brand})
|
||||
|
||||
Reference in New Issue
Block a user