Associate card only if it has not already been done
This commit is contained in:
parent
06a5cba50e
commit
d2ae94327a
1 changed files with 17 additions and 19 deletions
|
@ -610,28 +610,22 @@ class SettingsView(LoginRequiredMixin, FormView):
|
||||||
stripe_customer = StripeCustomer.get_or_create(
|
stripe_customer = StripeCustomer.get_or_create(
|
||||||
email=request.user.email, token=token
|
email=request.user.email, token=token
|
||||||
)
|
)
|
||||||
card_details_response = card_details['response_object']
|
card = card_details['response_object']
|
||||||
try:
|
if UserCardDetail.contains(stripe_customer, card):
|
||||||
UserCardDetail.objects.get(
|
|
||||||
stripe_customer=stripe_customer,
|
|
||||||
fingerprint=card_details_response['fingerprint'],
|
|
||||||
exp_month=card_details_response['exp_month'],
|
|
||||||
exp_year=card_details_response['exp_year']
|
|
||||||
)
|
|
||||||
msg = _('You seem to have already added this card')
|
msg = _('You seem to have already added this card')
|
||||||
messages.add_message(request, messages.ERROR, msg)
|
messages.add_message(request, messages.ERROR, msg)
|
||||||
except UserCardDetail.DoesNotExist:
|
else:
|
||||||
preferred = False
|
preferred = False
|
||||||
if stripe_customer.usercarddetail_set.count() == 0:
|
if stripe_customer.usercarddetail_set.count() == 0:
|
||||||
preferred = True
|
preferred = True
|
||||||
UserCardDetail.create(
|
UserCardDetail.create(
|
||||||
stripe_customer=stripe_customer,
|
stripe_customer=stripe_customer,
|
||||||
last4=card_details_response['last4'],
|
last4=card['last4'],
|
||||||
brand=card_details_response['brand'],
|
brand=card['brand'],
|
||||||
fingerprint=card_details_response['fingerprint'],
|
fingerprint=card['fingerprint'],
|
||||||
exp_month=card_details_response['exp_month'],
|
exp_month=card['exp_month'],
|
||||||
exp_year=card_details_response['exp_year'],
|
exp_year=card['exp_year'],
|
||||||
card_id=card_details_response['card_id'],
|
card_id=card['card_id'],
|
||||||
preferred=preferred
|
preferred=preferred
|
||||||
)
|
)
|
||||||
stripe_utils.associate_customer_card(
|
stripe_utils.associate_customer_card(
|
||||||
|
@ -857,10 +851,14 @@ class OrdersHostingDetailView(LoginRequiredMixin,
|
||||||
'last4': card_details_response['last4'],
|
'last4': card_details_response['last4'],
|
||||||
'brand': card_details_response['brand']
|
'brand': card_details_response['brand']
|
||||||
}
|
}
|
||||||
stripe_utils.associate_customer_card(
|
ucd = UserCardDetail.contains(
|
||||||
stripe_api_cus_id, request.session['token'],
|
request.user.stripecustomer, card_details_response
|
||||||
set_as_default=True
|
|
||||||
)
|
)
|
||||||
|
if not ucd:
|
||||||
|
stripe_utils.associate_customer_card(
|
||||||
|
stripe_api_cus_id, request.session['token'],
|
||||||
|
set_as_default=True
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
card_id = request.session.get('card_id')
|
card_id = request.session.get('card_id')
|
||||||
user_card_detail = UserCardDetail.objects.get(id=card_id)
|
user_card_detail = UserCardDetail.objects.get(id=card_id)
|
||||||
|
@ -921,7 +919,7 @@ class OrdersHostingDetailView(LoginRequiredMixin,
|
||||||
)
|
)
|
||||||
ucd.save_default_card(
|
ucd.save_default_card(
|
||||||
self.request.user.stripecustomer.stripe_id,
|
self.request.user.stripecustomer.stripe_id,
|
||||||
card_details_response['card_id']
|
ucd.card_id
|
||||||
)
|
)
|
||||||
user = {
|
user = {
|
||||||
'name': self.request.user.name,
|
'name': self.request.user.name,
|
||||||
|
|
Loading…
Reference in a new issue