Begin migrating to PaymentIntent

This commit is contained in:
PCoder 2020-12-24 19:34:06 +05:30
parent acba77976d
commit 1c4f297775
5 changed files with 35 additions and 2 deletions

View File

@ -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}}";
})();

View File

@ -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
), })

View File

@ -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 + ' <i class="fa fa-spinner fa-pulse"></i>');

View File

@ -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("-","")

View File

@ -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)