[英]aiohttp async with stripe Django
I am learning Django and I am trying to use aiohttp but I am unable to figure how can I use it with stripe API calls.我正在学习 Django 并且我正在尝试使用 aiohttp 但我无法弄清楚如何将它与条带 API 调用一起使用。
This is my code:这是我的代码:
class ListCardSerializer(serializers.Serializer):
pm = serializers.SerializerMethodField()
class Meta:
model = Bill
fields = ["pm"]
def get_pm(self, obj):
stripe.api_key = settings.STRIPE_API_KEY
cost = stripe.Customer.retrieve(customer_id)
pm = stripe.Customer.list_payment_methods(
customer_id, type="card"
)
return pm
I am new to Django any help will be appreciated.我是 Django 的新手,任何帮助将不胜感激。 I am trying to convert my functions into async await.
我正在尝试将我的函数转换为异步等待。
I've created a pure async stripe client for Python: https://github.com/bhch/async-stripe/ .我为 Python 创建了一个纯异步条带客户端: https://github.com/bhch/async-stripe/ 。
Every network call is an async coroutine.每个网络调用都是一个异步协程。
Usage:用法:
from async_stripe import stripe
stripe.api_key = '<your stripe api key>'
async def get_pm(self, obj):
cost = await stripe.Customer.retrieve(customer_id)
pm = await stripe.Customer.list_payment_methods(
customer_id, type="card"
)
return pm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.