diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 7bb61a708c5..6066cc1a8f9 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -3,7 +3,7 @@ * Copyright (C) 2006-2017 Laurent Destailleur * Copyright (C) 2009-2012 Regis Houssin * Copyright (C) 2018 Juanjo Menent - * Copyright (C) 2018-2019 Thibault FOUCART + * Copyright (C) 2018-2021 Thibault FOUCART * Copyright (C) 2021 Waƫl Almoman * Copyright (C) 2021 Dorian Vabre * @@ -2252,7 +2252,7 @@ if (preg_match('/^dopayment/', $action)) { // If we choosed/click on the payme //if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION) || ! empty($paymentintent)) //{ print ' - +
'; if (!empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) { @@ -2260,18 +2260,14 @@ if (preg_match('/^dopayment/', $action)) { // If we choosed/click on the payme } print '
'; - print ''; + //print ''; if (!empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) { - print '
'; + //print '
'; } - print '
+ print '
-
'; - - print ' -
'; print '
'; @@ -2418,9 +2414,12 @@ if (preg_match('/^dopayment/', $action)) { // If we choosed/click on the payme // Create a Stripe client. var stripe = Stripe(''); - + var cardButton = document.getElementById('buttontopay'); + var clientSecret = cardButton.dataset.secret; + var options = { clientSecret: clientSecret,}; + // Create an instance of Elements - var elements = stripe.elements(); + var elements = stripe.elements(options); // Custom styling can be passed to options when creating an Element. // (Note that this demo uses a wider set of styles than the guide below.) @@ -2441,49 +2440,28 @@ if (preg_match('/^dopayment/', $action)) { // If we choosed/click on the payme } }; - var cardElement = elements.create('card', {style: style}); + var paymentElement = elements.create("payment"); // Add an instance of the card Element into the `card-element`
- cardElement.mount('#card-element'); - - // Handle real-time validation errors from the card Element. - cardElement.addEventListener('change', function(event) { - var displayError = document.getElementById('card-errors'); - if (event.error) { - console.log("Show event error (like 'Incorrect card number', ...)"); - displayError.textContent = event.error.message; - } else { - console.log("Reset error message"); - displayError.textContent = ''; - } - }); + paymentElement.mount("#payment-element"); // Handle form submission - var cardholderName = document.getElementById('cardholder-name'); var cardButton = document.getElementById('buttontopay'); - var clientSecret = cardButton.dataset.secret; cardButton.addEventListener('click', function(event) { console.log("We click on buttontopay"); event.preventDefault(); - if (cardholderName.value == '') - { - console.log("Field Card holder is empty"); - var displayError = document.getElementById('card-errors'); - displayError.textContent = 'trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardOwner"))); ?>'; - } - else - { /* Disable button to pay and show hourglass cursor */ jQuery('#hourglasstopay').show(); jQuery('#buttontopay').hide(); - stripe.handleCardPayment( - clientSecret, cardElement, { + stripe.confirmPayment({ + elements,confirmParams: { + return_url: '', payment_method_data: { billing_details: { - name: cardholderName.value + name: 'test' thirdparty) && !empty($object->thirdparty->email))) { ?>, email: 'thirdparty->email); ?>' @@ -2507,6 +2485,7 @@ if (preg_match('/^dopayment/', $action)) { // If we choosed/click on the payme } else { print 'false'; } ?> /* true when a customer was provided when creating payment intent. true ask to save the card */ + }, } ).then(function(result) { console.log(result); @@ -2527,7 +2506,7 @@ if (preg_match('/^dopayment/', $action)) { // If we choosed/click on the payme jQuery('#payment-form').submit(); } }); - } + });