Begin migrating to PaymentIntent
This commit is contained in:
parent
acba77976d
commit
1c4f297775
5 changed files with 35 additions and 2 deletions
|
@ -187,6 +187,7 @@
|
||||||
window.enter_your_card_text = '{%trans "Enter your credit card number" %}';
|
window.enter_your_card_text = '{%trans "Enter your credit card number" %}';
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
|
window.paymentIntentSecret = "{{payment_intent_secret}}";
|
||||||
window.stripeKey = "{{stripe_key}}";
|
window.stripeKey = "{{stripe_key}}";
|
||||||
window.current_lan = "{{LANGUAGE_CODE}}";
|
window.current_lan = "{{LANGUAGE_CODE}}";
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -285,12 +285,28 @@ class PaymentOrderView(FormView):
|
||||||
product = GenericProduct.objects.get(
|
product = GenericProduct.objects.get(
|
||||||
id=self.request.session['product_id']
|
id=self.request.session['product_id']
|
||||||
)
|
)
|
||||||
|
# TODO get the correct price of the product from order
|
||||||
|
# confirmation
|
||||||
|
stripe_utils = StripeUtils()
|
||||||
|
payment_intent_response = stripe_utils.get_payment_intent(
|
||||||
|
float(product.get_actual_price())
|
||||||
|
)
|
||||||
|
if not payment_intent_response.get('response_object'):
|
||||||
|
logger.error("Could not create payment_intent %s" %
|
||||||
|
str(payment_intent_response))
|
||||||
|
else:
|
||||||
|
logger.debug("*******")
|
||||||
|
logger.debug(
|
||||||
|
"payment_intent_obj = %s" %
|
||||||
|
str(payment_intent_response.get('response_object')))
|
||||||
|
logger.debug("*******")
|
||||||
context.update({'generic_payment_form': ProductPaymentForm(
|
context.update({'generic_payment_form': ProductPaymentForm(
|
||||||
prefix='generic_payment_form',
|
prefix='generic_payment_form',
|
||||||
initial={'product_name': product.product_name,
|
initial={'product_name': product.product_name,
|
||||||
'amount': float(product.get_actual_price()),
|
'amount': float(product.get_actual_price()),
|
||||||
'recurring': product.product_is_subscription,
|
'recurring': product.product_is_subscription,
|
||||||
'description': product.product_description,
|
'description': product.product_description,
|
||||||
|
'payment_intent_secret': 'secret_here'
|
||||||
},
|
},
|
||||||
product_id=product.id
|
product_id=product.id
|
||||||
), })
|
), })
|
||||||
|
|
|
@ -197,7 +197,7 @@ $(document).ready(function () {
|
||||||
} else {
|
} else {
|
||||||
var process_text = "Processing";
|
var process_text = "Processing";
|
||||||
if (typeof window.processing_text !== 'undefined') {
|
if (typeof window.processing_text !== 'undefined') {
|
||||||
process_text = window.processing_text
|
process_text = window.processing_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
$form_new.find('[type=submit]').html(process_text + ' <i class="fa fa-spinner fa-pulse"></i>');
|
$form_new.find('[type=submit]').html(process_text + ' <i class="fa fa-spinner fa-pulse"></i>');
|
||||||
|
|
|
@ -493,6 +493,19 @@ class StripeUtils(object):
|
||||||
)
|
)
|
||||||
return tax_id_obj
|
return tax_id_obj
|
||||||
|
|
||||||
|
@handleStripeError
|
||||||
|
def get_payment_intent(self, amount):
|
||||||
|
"""
|
||||||
|
Adds VM metadata to a subscription
|
||||||
|
:param amount: the amount of payment_intent
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
payment_intent_obj = stripe.PaymentIntent.create(
|
||||||
|
amount=amount,
|
||||||
|
currency='chf'
|
||||||
|
)
|
||||||
|
return payment_intent_obj
|
||||||
|
|
||||||
def compare_vat_numbers(self, vat1, vat2):
|
def compare_vat_numbers(self, vat1, vat2):
|
||||||
_vat1 = vat1.replace(" ", "").replace(".", "").replace("-","")
|
_vat1 = vat1.replace(" ", "").replace(".", "").replace("-","")
|
||||||
_vat2 = vat2.replace(" ", "").replace(".", "").replace("-","")
|
_vat2 = vat2.replace(" ", "").replace(".", "").replace("-","")
|
||||||
|
|
|
@ -221,7 +221,10 @@ def handle_webhook(request):
|
||||||
if (invoice_obj.payment_failed and
|
if (invoice_obj.payment_failed and
|
||||||
invoice_obj.billing_reason == "subscription_update"):
|
invoice_obj.billing_reason == "subscription_update"):
|
||||||
logger.debug("Payment failed, inform the users")
|
logger.debug("Payment failed, inform the users")
|
||||||
|
elif event.type == 'payment_intent.succeeded':
|
||||||
|
payment_intent_obj = event.data.object
|
||||||
|
logger.debug("Webhook Event: payment_intent.succeeded")
|
||||||
|
logger.debug("payment_intent_obj %s " % str(payment_intent_obj))
|
||||||
else:
|
else:
|
||||||
logger.error("Unhandled event : " + event.type)
|
logger.error("Unhandled event : " + event.type)
|
||||||
return HttpResponse(status=200)
|
return HttpResponse(status=200)
|
||||||
|
|
Loading…
Reference in a new issue