【发布时间】:2021-02-04 17:30:12
【问题描述】:
我正在尝试从 Stripe 设置 paymentIntent API,但我似乎无法弄清楚我遇到的错误。我跟着这个视频:https://www.youtube.com/watch?v=w1oLdAPyuok&t=1414s
我有一个反应前端,它向我的 Django 视图发出请求:
try {
const { data: clientSecret } = await axios.post("http://127.0.0.1:8000/paymentIntent/", {
amount: price * 100
});
我的看法:
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic import View
from django.views.decorators.csrf import csrf_exempt
import logging
from rest_framework.views import APIView
from rest_framework import status, generics
from rest_framework.response import Response
from rest_framework.decorators import api_view
from django.conf import settings
import stripe
stripe.api_key = "pk_test_51HWMwZB5hTmoPZOBJd00GjCvDYUg"
@api_view(['POST'])
def payment(request):
try:
amount = request.body
paymentIntent = stripe.PaymentIntent.create(
amount = amount,
currency = "usd",
# payment_method_types=['card'],
# capture_method='manual',
metadata={'integration_check': 'accept_a_payment'},
)
data = paymentIntent.client_secret
return Response(data,status=status.HTTP_200_OK)
except :
return Response(status=status.HTTP_400_BAD_REQUEST)
当我发出请求时,它只会显示 400 Bad Request 而没有响应数据
【问题讨论】:
标签: reactjs django django-rest-framework django-views stripe-payments