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(
|
||||
email=request.user.email, token=token
|
||||
)
|
||||
card_details_response = card_details['response_object']
|
||||
try:
|
||||
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']
|
||||
)
|
||||
card = card_details['response_object']
|
||||
if UserCardDetail.contains(stripe_customer, card):
|
||||
msg = _('You seem to have already added this card')
|
||||
messages.add_message(request, messages.ERROR, msg)
|
||||
except UserCardDetail.DoesNotExist:
|
||||
else:
|
||||
preferred = False
|
||||
if stripe_customer.usercarddetail_set.count() == 0:
|
||||
preferred = True
|
||||
UserCardDetail.create(
|
||||
stripe_customer=stripe_customer,
|
||||
last4=card_details_response['last4'],
|
||||
brand=card_details_response['brand'],
|
||||
fingerprint=card_details_response['fingerprint'],
|
||||
exp_month=card_details_response['exp_month'],
|
||||
exp_year=card_details_response['exp_year'],
|
||||
card_id=card_details_response['card_id'],
|
||||
last4=card['last4'],
|
||||
brand=card['brand'],
|
||||
fingerprint=card['fingerprint'],
|
||||
exp_month=card['exp_month'],
|
||||
exp_year=card['exp_year'],
|
||||
card_id=card['card_id'],
|
||||
preferred=preferred
|
||||
)
|
||||
stripe_utils.associate_customer_card(
|
||||
|
@ -857,6 +851,10 @@ class OrdersHostingDetailView(LoginRequiredMixin,
|
|||
'last4': card_details_response['last4'],
|
||||
'brand': card_details_response['brand']
|
||||
}
|
||||
ucd = UserCardDetail.contains(
|
||||
request.user.stripecustomer, card_details_response
|
||||
)
|
||||
if not ucd:
|
||||
stripe_utils.associate_customer_card(
|
||||
stripe_api_cus_id, request.session['token'],
|
||||
set_as_default=True
|
||||
|
@ -921,7 +919,7 @@ class OrdersHostingDetailView(LoginRequiredMixin,
|
|||
)
|
||||
ucd.save_default_card(
|
||||
self.request.user.stripecustomer.stripe_id,
|
||||
card_details_response['card_id']
|
||||
ucd.card_id
|
||||
)
|
||||
user = {
|
||||
'name': self.request.user.name,
|
||||
|
|
Loading…
Reference in a new issue