Refactor code
This commit is contained in:
parent
1e214f7b21
commit
5cd62abc70
1 changed files with 21 additions and 71 deletions
|
@ -564,30 +564,6 @@ class OrderConfirmationView(DetailView):
|
||||||
user=custom_user, stripe_id=stripe_api_cus_id
|
user=custom_user, stripe_id=stripe_api_cus_id
|
||||||
)
|
)
|
||||||
stripe_customer_id = stripe_customer.id
|
stripe_customer_id = stripe_customer.id
|
||||||
|
|
||||||
if 'token' in request.session:
|
|
||||||
ucd = UserCardDetail.get_or_create_user_card_detail(
|
|
||||||
stripe_customer=self.request.user.stripecustomer,
|
|
||||||
card_details=card_details_response
|
|
||||||
)
|
|
||||||
UserCardDetail.save_default_card_local(
|
|
||||||
self.request.user.stripecustomer.stripe_id,
|
|
||||||
ucd.card_id
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
|
||||||
card_id = request.session.get('card_id')
|
|
||||||
user_card_detail = UserCardDetail.objects.get(id=card_id)
|
|
||||||
card_details_dict = {
|
|
||||||
'last4': user_card_detail.last4,
|
|
||||||
'brand': user_card_detail.brand,
|
|
||||||
'card_id': user_card_detail.card_id
|
|
||||||
}
|
|
||||||
if not user_card_detail.preferred:
|
|
||||||
UserCardDetail.set_default_card(
|
|
||||||
stripe_api_cus_id=stripe_api_cus_id,
|
|
||||||
stripe_source_id=user_card_detail.card_id
|
|
||||||
)
|
|
||||||
except CustomUser.DoesNotExist:
|
except CustomUser.DoesNotExist:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Customer {} does not exist.".format(user.get('email')))
|
"Customer {} does not exist.".format(user.get('email')))
|
||||||
|
@ -607,35 +583,9 @@ class OrderConfirmationView(DetailView):
|
||||||
new_user = authenticate(username=custom_user.email,
|
new_user = authenticate(username=custom_user.email,
|
||||||
password=password)
|
password=password)
|
||||||
login(request, new_user)
|
login(request, new_user)
|
||||||
|
|
||||||
if 'token' in request.session:
|
|
||||||
ucd = UserCardDetail.get_or_create_user_card_detail(
|
|
||||||
stripe_customer=self.request.user.stripecustomer,
|
|
||||||
card_details=card_details_response
|
|
||||||
)
|
|
||||||
UserCardDetail.save_default_card_local(
|
|
||||||
self.request.user.stripecustomer.stripe_id,
|
|
||||||
ucd.card_id
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
|
||||||
card_id = request.session.get('card_id')
|
|
||||||
user_card_detail = UserCardDetail.objects.get(id=card_id)
|
|
||||||
card_details_dict = {
|
|
||||||
'last4': user_card_detail.last4,
|
|
||||||
'brand': user_card_detail.brand,
|
|
||||||
'card_id': user_card_detail.card_id
|
|
||||||
}
|
|
||||||
if not user_card_detail.preferred:
|
|
||||||
UserCardDetail.set_default_card(
|
|
||||||
stripe_api_cus_id=stripe_api_cus_id,
|
|
||||||
stripe_source_id=user_card_detail.card_id
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# We assume that if the user is here, his/her StripeCustomer
|
# We assume that if the user is here, his/her StripeCustomer
|
||||||
# object already exists
|
# object already exists
|
||||||
stripe_customer = request.user.stripecustomer
|
|
||||||
stripe_customer_id = request.user.stripecustomer.id
|
stripe_customer_id = request.user.stripecustomer.id
|
||||||
custom_user = request.user
|
custom_user = request.user
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue