Test PaymentIntent for payment of generic onetime products
This commit is contained in:
		
					parent
					
						
							
								ec1da8fbdf
							
						
					
				
			
			
				commit
				
					
						e9c596de66
					
				
			
		
					 2 changed files with 33 additions and 13 deletions
				
			
		|  | @ -291,22 +291,21 @@ class PaymentOrderView(FormView): | ||||||
|                 payment_intent_response = stripe_utils.get_payment_intent( |                 payment_intent_response = stripe_utils.get_payment_intent( | ||||||
|                     int(product.get_actual_price() * 100) |                     int(product.get_actual_price() * 100) | ||||||
|                 ) |                 ) | ||||||
|                 if not payment_intent_response.get('response_object'): |                 payment_intent = payment_intent_response.get('response_object') | ||||||
|  |                 if not payment_intent: | ||||||
|                     logger.error("Could not create payment_intent %s" % |                     logger.error("Could not create payment_intent %s" % | ||||||
|                                  str(payment_intent_response)) |                                  str(payment_intent_response)) | ||||||
|                 else: |                 else: | ||||||
|                     logger.debug("*******") |                     logger.debug("payment_intent_obj = %s" % | ||||||
|                     logger.debug( |                                  str(payment_intent)) | ||||||
|                         "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' |                         'payment_intent_secret': payment_intent.client_secret | ||||||
|                     }, |                     }, | ||||||
|                     product_id=product.id |                     product_id=product.id | ||||||
|                 ), }) |                 ), }) | ||||||
|  |  | ||||||
|  | @ -178,7 +178,28 @@ $(document).ready(function () { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     var $form_new = $('#payment-form-new'); |     var $form_new = $('#payment-form-new'); | ||||||
|     $form_new.submit(payWithStripe_new); |     $form_new.submit(payWithPaymentIntent); | ||||||
|  |     function payWithPaymentIntent(e) { | ||||||
|  |         e.preventDefault(); | ||||||
|  | 
 | ||||||
|  |         stripe.confirmCardPayment( | ||||||
|  |           window.paymentIntentSecret, | ||||||
|  |           { | ||||||
|  |             payment_method: {card: cardNumberElement} | ||||||
|  |           } | ||||||
|  |         ).then(function(result) { | ||||||
|  |           if (result.error) { | ||||||
|  |             // Display error.message in your UI.
 | ||||||
|  |             var errorElement = document.getElementById('card-errors'); | ||||||
|  |             errorElement.textContent = result.error.message; | ||||||
|  |           } else { | ||||||
|  |             // The payment has succeeded
 | ||||||
|  |             // Display a success message
 | ||||||
|  |             alert("Thanks for the order. Your product will be provisioned " + | ||||||
|  |                 "as soon as we receive the payment. Thank you."); | ||||||
|  |           } | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|     function payWithStripe_new(e) { |     function payWithStripe_new(e) { | ||||||
|         e.preventDefault(); |         e.preventDefault(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue