Handle payment_intent requires SCA case
This commit is contained in:
parent
0b0c932e5a
commit
d0d5fb0196
1 changed files with 23 additions and 40 deletions
|
@ -783,7 +783,6 @@ class OrderConfirmationView(DetailView, FormView):
|
||||||
customer=stripe_api_cus_id
|
customer=stripe_api_cus_id
|
||||||
)
|
)
|
||||||
stripe_onetime_charge = charge_response.get('response_object')
|
stripe_onetime_charge = charge_response.get('response_object')
|
||||||
|
|
||||||
# Check if the payment was approved
|
# Check if the payment was approved
|
||||||
if not stripe_onetime_charge:
|
if not stripe_onetime_charge:
|
||||||
msg = charge_response.get('error')
|
msg = charge_response.get('error')
|
||||||
|
@ -893,13 +892,26 @@ class OrderConfirmationView(DetailView, FormView):
|
||||||
logger.debug(stripe_subscription_obj)
|
logger.debug(stripe_subscription_obj)
|
||||||
latest_invoice = stripe.Invoice.retrieve(
|
latest_invoice = stripe.Invoice.retrieve(
|
||||||
stripe_subscription_obj.latest_invoice)
|
stripe_subscription_obj.latest_invoice)
|
||||||
# ret = stripe.PaymentIntent.confirm(
|
|
||||||
# latest_invoice.payment_intent
|
# Check if the subscription was approved and is active
|
||||||
# )
|
if (stripe_subscription_obj is None
|
||||||
if ret.status == 'requires_source_action' or ret.status == 'requires_action':
|
or (stripe_subscription_obj.status != 'active'
|
||||||
|
and stripe_subscription_obj.status != 'incomplete')):
|
||||||
|
# At this point, we have created a Stripe API card and
|
||||||
|
# associated it with the customer; but the transaction failed
|
||||||
|
# due to some reason. So, we would want to dissociate this card
|
||||||
|
# here.
|
||||||
|
# ...
|
||||||
|
msg = subscription_result.get('error')
|
||||||
|
return show_error(msg, self.request)
|
||||||
|
elif stripe_subscription_obj.status == 'incomplete':
|
||||||
pi = stripe.PaymentIntent.retrieve(
|
pi = stripe.PaymentIntent.retrieve(
|
||||||
latest_invoice.payment_intent
|
latest_invoice.payment_intent
|
||||||
)
|
)
|
||||||
|
# TODO: requires_attention is probably wrong value to compare
|
||||||
|
if (pi.status == 'requires_attention' or
|
||||||
|
pi.status == 'requires_source_action'):
|
||||||
|
logger.debug("Display SCA authentication")
|
||||||
context = {
|
context = {
|
||||||
'sid': stripe_subscription_obj.id,
|
'sid': stripe_subscription_obj.id,
|
||||||
'payment_intent_secret': pi.client_secret,
|
'payment_intent_secret': pi.client_secret,
|
||||||
|
@ -907,38 +919,10 @@ class OrderConfirmationView(DetailView, FormView):
|
||||||
'showSCA': True
|
'showSCA': True
|
||||||
}
|
}
|
||||||
return JsonResponse(context)
|
return JsonResponse(context)
|
||||||
# Check if the subscription was approved and is active
|
else:
|
||||||
if (stripe_subscription_obj is None
|
logger.debug("Handle this case")
|
||||||
or stripe_subscription_obj.status != 'active'):
|
|
||||||
# At this point, we have created a Stripe API card and
|
|
||||||
# associated it with the customer; but the transaction failed
|
|
||||||
# due to some reason. So, we would want to dissociate this card
|
|
||||||
# here.
|
|
||||||
# ...
|
|
||||||
|
|
||||||
msg = subscription_result.get('error')
|
msg = subscription_result.get('error')
|
||||||
messages.add_message(self.request, messages.ERROR, msg,
|
return show_error(msg, self.request)
|
||||||
extra_tags='failed_payment')
|
|
||||||
response = {
|
|
||||||
'status': False,
|
|
||||||
'redirect': "{url}#{section}".format(
|
|
||||||
url=(reverse(
|
|
||||||
'show_product',
|
|
||||||
kwargs={'product_slug':
|
|
||||||
request.session['generic_payment_details']
|
|
||||||
['product_slug']}
|
|
||||||
) if 'generic_payment_details' in request.session else
|
|
||||||
reverse('datacenterlight:payment')
|
|
||||||
),
|
|
||||||
section='payment_error'
|
|
||||||
),
|
|
||||||
'msg_title': str(_('Error.')),
|
|
||||||
'msg_body': str(
|
|
||||||
_('There was a payment related error.'
|
|
||||||
' On close of this popup, you will be redirected back to'
|
|
||||||
' the payment page.'))
|
|
||||||
}
|
|
||||||
return JsonResponse(response)
|
|
||||||
|
|
||||||
# Create user if the user is not logged in and if he is not already
|
# Create user if the user is not logged in and if he is not already
|
||||||
# registered
|
# registered
|
||||||
|
@ -1184,4 +1168,3 @@ def show_error(msg, request):
|
||||||
' the payment page.'))
|
' the payment page.'))
|
||||||
}
|
}
|
||||||
return JsonResponse(response)
|
return JsonResponse(response)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue