分条支付意图抛出无效整数



我一直在尝试生成条带支付意图,但我看到invalid Integer的此错误

Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/asgiref/sync.py", line 472, in thread_handler
raise exc_info[1]
File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 42, in inner
response = await get_response(request)
File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 253, in _get_response_async
response = await wrapped_callback(
File "/usr/local/lib/python3.8/site-packages/asgiref/sync.py", line 435, in __call__
ret = await asyncio.wait_for(future, timeout=None)
File "/usr/local/lib/python3.8/asyncio/tasks.py", line 455, in wait_for
return await fut
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.8/site-packages/asgiref/sync.py", line 476, in thread_handler
return func(*args, **kwargs)
File "/usr/local/lib/python3.8/contextlib.py", line 75, in inner
return func(*args, **kwds)
File "/usr/local/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/views/generic/base.py", line 84, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/yacht-away/bookings/views.py", line 94, in post
print(payment.create_payment_intent())
File "/yacht-away/bookings/payments.py", line 14, in create_payment_intent
payment = stripe.PaymentIntent.create(
File "/usr/local/lib/python3.8/site-packages/stripe/api_resources/abstract/createable_api_resource.py", line 22, in create
response, api_key = requestor.request("post", url, params, headers)
File "/usr/local/lib/python3.8/site-packages/stripe/api_requestor.py", line 122, in request
resp = self.interpret_response(rbody, rcode, rheaders)
File "/usr/local/lib/python3.8/site-packages/stripe/api_requestor.py", line 399, in interpret_response
self.handle_error_response(rbody, rcode, resp.data, rheaders)
File "/usr/local/lib/python3.8/site-packages/stripe/api_requestor.py", line 159, in handle_error_response
raise err
stripe.error.InvalidRequestError: Request req_4TngiwH4P1ztKp: Invalid integer: {:"0"=>"2400"}

我一直在遵循这个文档,并写了这样的支付类-

class Payments:
def __init__(self, amount):
self.amount = amount,
self.currency = "sgd",
self.automatic_payment_methods = {"enabled": True}
stripe.api_key = "sk_test_51LAvboSE9yL96I7XGzEIe7GQyAPWbVHMBULDK4yw0raYGn2NF4ksodn8nF7V5HKtKNiPMnOPOCd1neNcqolGXPjG00vCJUTtuX"
def create_payment_intent(self):
payment = stripe.PaymentIntent.create(
payment_method_types=["paynow"],
payment_method_data={"type": "paynow"},
amount=self.amount,
currency=self.currency,
)
print(payment)

这就是我调用支付意图方法的方式-

payment = Payments(
amount=int(bill["payable_amount"]) * 100,
)

我哪里错了?代码看起来不错,我使用的api_key与文档中给出的相同。

在你的问题的底部,你分享了请求idreq_4TngiwH4P1ztKp,可以直接加载到你的条纹仪表板:https://dashboard.stripe.com/test/logs/req_4TngiwH4P1ztKp

错误信息也试图显示你做错了什么,因为它读

无效的整数:{:"0"=祝辞;"2400"}

这通常意味着你没有按照API期望的方式传递参数。在某个地方,它期望一个整数,但相反,你传递了一个散列,其中整数与0键相关联。您的代码发送的唯一参数应该是整数amount。这意味着您现在的self.amount,而不是2400,{ 0: '2400'}可能是因为您从客户端发送它的方式。这是你要调试的部分。

我还建议仔细阅读Stripe关于错误处理的文档,因为它们涵盖了所有语言的API基础。在代码中清晰地捕获错误将使您能够立即看到错误及其来源。

相关内容

  • 没有找到相关文章

最新更新