【问题标题】:Django Stripe PaymentIntentDjango Stripe PaymentIntent
【发布时间】: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


    【解决方案1】:

    我没有看到您收到的实际错误消息,您的服务器应该在您的 try-catch 块中注销错误,如下所示:https://stripe.com/docs/api/errors/handling?lang=python 允许您在构建集成时更好地调试和排除故障.

    最有可能的是,您已将 可发布密钥 设置为您的 stripe-python API 密钥。相反,您需要使用 密钥 初始化 stripehttps://stripe.com/docs/api/authentication?lang=python

    【讨论】:

    • 我刚刚收到一条错误消息:400 Bad Request。它立即给了我错误信息。我刚刚用我的密钥修复了我的条带初始化,但它仍然给出了同样的错误
    • 400 请求中有一条错误消息,请在 dashboard.stripe.com/test/logs 查看您的 Stripe Dashboard 日志以查看错误消息是什么,或者在您的 try-catch 块中将其注销跨度>
    猜你喜欢
    • 1970-01-01
    • 2019-11-20
    • 2019-09-26
    • 1970-01-01
    • 1970-01-01
    • 2020-08-07
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    相关资源
    最近更新 更多