diff --git a/datacenterlight/templates/datacenterlight/landing_payment.html b/datacenterlight/templates/datacenterlight/landing_payment.html index 66a0e63f..f112f0d9 100644 --- a/datacenterlight/templates/datacenterlight/landing_payment.html +++ b/datacenterlight/templates/datacenterlight/landing_payment.html @@ -187,6 +187,7 @@ window.enter_your_card_text = '{%trans "Enter your credit card number" %}'; (function () { + window.paymentIntentSecret = "{{payment_intent_secret}}"; window.stripeKey = "{{stripe_key}}"; window.current_lan = "{{LANGUAGE_CODE}}"; })(); diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 988be8d0..3c92506b 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -285,12 +285,28 @@ class PaymentOrderView(FormView): product = GenericProduct.objects.get( 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( prefix='generic_payment_form', initial={'product_name': product.product_name, 'amount': float(product.get_actual_price()), 'recurring': product.product_is_subscription, 'description': product.product_description, + 'payment_intent_secret': 'secret_here' }, product_id=product.id ), }) diff --git a/hosting/static/hosting/js/payment.js b/hosting/static/hosting/js/payment.js index fa89f218..be94a866 100644 --- a/hosting/static/hosting/js/payment.js +++ b/hosting/static/hosting/js/payment.js @@ -197,7 +197,7 @@ $(document).ready(function () { } else { var process_text = "Processing"; if (typeof window.processing_text !== 'undefined') { - process_text = window.processing_text + process_text = window.processing_text; } $form_new.find('[type=submit]').html(process_text + ' '); diff --git a/utils/stripe_utils.py b/utils/stripe_utils.py index f5df8aa8..bf731508 100644 --- a/utils/stripe_utils.py +++ b/utils/stripe_utils.py @@ -493,6 +493,19 @@ class StripeUtils(object): ) 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): _vat1 = vat1.replace(" ", "").replace(".", "").replace("-","") _vat2 = vat2.replace(" ", "").replace(".", "").replace("-","") diff --git a/webhook/views.py b/webhook/views.py index b0eac5df..416d07b7 100644 --- a/webhook/views.py +++ b/webhook/views.py @@ -221,7 +221,10 @@ def handle_webhook(request): if (invoice_obj.payment_failed and invoice_obj.billing_reason == "subscription_update"): 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: logger.error("Unhandled event : " + event.type) return HttpResponse(status=200)