Reputation: 115
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.
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. I am trying to convert my functions into async await.
Upvotes: 2
Views: 303
Reputation: 21844
I've created a pure async stripe client for 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
Upvotes: 1