Fix stripe import in uncloud_pay.models

This commit is contained in:
fnux 2020-03-04 11:05:21 +01:00
parent 9e8149135b
commit faca104459

View file

@ -10,6 +10,7 @@ import json
from .models import * from .models import *
from .serializers import * from .serializers import *
from datetime import datetime from datetime import datetime
import uncloud_pay.stripe as uncloud_stripe
### ###
# Standard user views: # Standard user views:
@ -79,15 +80,15 @@ class PaymentMethodViewSet(viewsets.ModelViewSet):
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
# Retrieve Stripe customer ID for user. # Retrieve Stripe customer ID for user.
customer_id = stripe.get_customer_id_for(request.user) customer_id = uncloud_stripe.get_customer_id_for(request.user)
if customer_id == None: if customer_id == None:
return Response( return Response(
{'error': 'Could not resolve customer stripe ID.'}, {'error': 'Could not resolve customer stripe ID.'},
status=status.HTTP_500_INTERNAL_SERVER_ERROR) status=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Register card under stripe customer. # Register card under stripe customer.
credit_card = stripe.CreditCard(**serializer.validated_data.pop('credit_card')) credit_card = uncloud_stripe.CreditCard(**serializer.validated_data.pop('credit_card'))
card_request = stripe.create_card(customer_id, credit_card) card_request = uncloud_stripe.create_card(customer_id, credit_card)
if card_request['error']: if card_request['error']:
return Response({'stripe_error': card_request['error']}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response({'stripe_error': card_request['error']}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
card_id = card_request['response_object']['id'] card_id = card_request['response_object']['id']