21/03/23 - 22h
parent
243d736481
commit
25cbdd88eb
|
@ -143,6 +143,8 @@ function CheckOut(props) {
|
|||
|
||||
|
||||
|
||||
const [stripe_existing_souscription_id, setstripe_existing_souscription_id] = useState();
|
||||
|
||||
const [stripe_account_id, setstripe_account_id] = useState("aaa");
|
||||
const [stripe_paymentmethod_id, setstripe_paymentmethod_id] = useState();
|
||||
|
||||
|
@ -273,6 +275,12 @@ function CheckOut(props) {
|
|||
document.getElementsByName("telephone")[0].style.backgroundColor = "#ECEFF1";
|
||||
}
|
||||
|
||||
|
||||
if (mylocaltraining.stripe_subscription_id) {
|
||||
|
||||
setstripe_existing_souscription_id(mylocaltraining.stripe_subscription_id);
|
||||
}
|
||||
|
||||
desablefield1();
|
||||
|
||||
}
|
||||
|
@ -462,51 +470,110 @@ function CheckOut(props) {
|
|||
return;
|
||||
}
|
||||
|
||||
console.log(" ### stripe_existing_souscription_id = ", stripe_existing_souscription_id);
|
||||
|
||||
//initpayement_front();
|
||||
|
||||
// ---------- debut
|
||||
|
||||
setpayment_in_process("1");
|
||||
var myurl = process.env.REACT_APP_API_URL + "myclass/api/create-subscription/";
|
||||
|
||||
var form1 = new FormData();
|
||||
|
||||
var local_souscription_id;
|
||||
var local_souscription_id2;
|
||||
/*
|
||||
IMPORTANT :
|
||||
Quand c'est la première fois ou si le partenaire n'a pas de deja un abonnement en cours,
|
||||
alors on faire une creation.
|
||||
|
||||
form1.append("customerid", cust_strip_id_global);
|
||||
form1.append("pack", currentpack);
|
||||
form1.append("qty", nb_formations);
|
||||
Si non c'est une mise à jour qu'il faut faire
|
||||
|
||||
fetch(myurl, {
|
||||
method: 'POST',
|
||||
body: form1,
|
||||
}).then((data) => data.json())
|
||||
.then((data) => {
|
||||
//console.log(' #### retour myclass/api/create-subscription/ = subscription_id:', data['subscription_id'], ' ### payment_intent_client_secret:', data['payment_intent_client_secret'], "data['Status'] = ", data['status'],);
|
||||
local_souscription_id = data['subscription_id'];
|
||||
la souscription_id du partenaire est stocké ici : stripe_existing_souscription_id
|
||||
*/
|
||||
if (!stripe_existing_souscription_id) {
|
||||
// Le client n'a pas de soucription id, donc on fait une creation.
|
||||
var myurl = process.env.REACT_APP_API_URL + "myclass/api/create-subscription/";
|
||||
|
||||
//console.log(" ### INSIDE initpayement_front(); : local_souscription_id = ", local_souscription_id);
|
||||
setpayement_id(data['subscription_id']);
|
||||
var form1 = new FormData();
|
||||
|
||||
if (String(data['status']) === String("true")) {
|
||||
//console.log(" subscriptionId = " + subscriptionId + " -- et clientSecret = " + clientSecret);
|
||||
setclientSecret_id(data['payment_intent_client_secret']);
|
||||
var local_souscription_id;
|
||||
var local_souscription_id2;
|
||||
|
||||
form1.append("customerid", cust_strip_id_global);
|
||||
form1.append("pack", currentpack);
|
||||
form1.append("qty", nb_formations);
|
||||
|
||||
fetch(myurl, {
|
||||
method: 'POST',
|
||||
body: form1,
|
||||
}).then((data) => data.json())
|
||||
.then((data) => {
|
||||
//console.log(' #### retour myclass/api/create-subscription/ = subscription_id:', data['subscription_id'], ' ### payment_intent_client_secret:', data['payment_intent_client_secret'], "data['Status'] = ", data['status'],);
|
||||
local_souscription_id = data['subscription_id'];
|
||||
|
||||
//console.log(" ### INSIDE initpayement_front(); : local_souscription_id = ", local_souscription_id);
|
||||
setpayement_id(data['subscription_id']);
|
||||
|
||||
local_souscription_id2 = data['subscription_id'];
|
||||
if (String(data['status']) === String("true")) {
|
||||
//console.log(" subscriptionId = " + subscriptionId + " -- et clientSecret = " + clientSecret);
|
||||
setclientSecret_id(data['payment_intent_client_secret']);
|
||||
setpayement_id(data['subscription_id']);
|
||||
|
||||
//setSubscriptionData(data['subscription_id'], data['payment_intent_client_secret'] );
|
||||
//alert(" subscriptionId = " + data['subscription_id'] + " -- et clientSecret = " + data['payment_intent_client_secret']);
|
||||
local_souscription_id2 = data['subscription_id'];
|
||||
|
||||
}
|
||||
//setSubscriptionData(data['subscription_id'], data['payment_intent_client_secret'] );
|
||||
//alert(" subscriptionId = " + data['subscription_id'] + " -- et clientSecret = " + data['payment_intent_client_secret']);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}).catch((error) => {
|
||||
//console.log('Error:', error.message);
|
||||
});
|
||||
}).catch((error) => {
|
||||
//console.log('Error:', error.message);
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
// Le client a une souscription id, donc on fait une mise à jour
|
||||
var myurl = process.env.REACT_APP_API_URL + "myclass/api/strip_update_subscription_plan/";
|
||||
|
||||
var form1 = new FormData();
|
||||
|
||||
var local_souscription_id;
|
||||
var local_souscription_id2;
|
||||
|
||||
const stored_cookie = getCookie('tokenmysypart');
|
||||
form1.append("token", stored_cookie);
|
||||
form1.append("pack", currentpack);
|
||||
form1.append("qty", nb_formations);
|
||||
|
||||
fetch(myurl, {
|
||||
method: 'POST',
|
||||
body: form1,
|
||||
}).then((data) => data.json())
|
||||
.then((data) => {
|
||||
console.log(" #### status", data['status'], ' ### message : ', data['message']);
|
||||
//local_souscription_id = data['subscription_id'];
|
||||
|
||||
//console.log(" ### INSIDE initpayement_front(); : local_souscription_id = ", local_souscription_id);
|
||||
//setpayement_id(data['subscription_id']);
|
||||
|
||||
if (String(data['status']) === String("true")) {
|
||||
|
||||
console.log(" status = OKKK ");
|
||||
//console.log(" subscriptionId = " + subscriptionId + " -- et clientSecret = " + clientSecret);
|
||||
//setclientSecret_id(data['payment_intent_client_secret']);
|
||||
//setpayement_id(data['subscription_id']);
|
||||
|
||||
//local_souscription_id2 = data['subscription_id'];
|
||||
|
||||
//setSubscriptionData(data['subscription_id'], data['payment_intent_client_secret'] );
|
||||
//alert(" subscriptionId = " + data['subscription_id'] + " -- et clientSecret = " + data['payment_intent_client_secret']);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}).catch((error) => {
|
||||
//console.log('Error:', error.message);
|
||||
});
|
||||
}
|
||||
// ----- end
|
||||
|
||||
//console.log(" ### apres initpayement_front(); : local_souscription_id = ", local_souscription_id, " local_souscription_id2 = ",local_souscription_id2);
|
||||
|
@ -519,7 +586,7 @@ function CheckOut(props) {
|
|||
//form.append("prix_ht", "1");
|
||||
form.append("discount", "0");
|
||||
form.append("pack", currentpack);
|
||||
|
||||
|
||||
/*
|
||||
/!\ : Important, il faut preciser le nombre d'article envoyé avec ceci : form.append("nb_product", nb_article);
|
||||
*/
|
||||
|
@ -564,13 +631,44 @@ function CheckOut(props) {
|
|||
setgotocheckout("");
|
||||
|
||||
console.log(" ### packprice = ", packprice);
|
||||
if (parseFloat(packprice) > 0)
|
||||
finalize_abonnement(local_souscription_id);
|
||||
else if (String(props.packs).toLowerCase() === String("decouverte")) {
|
||||
MySy_LMS_Account_Management();
|
||||
window.location.reload();
|
||||
|
||||
/*
|
||||
IMPORTANT :
|
||||
On fait une finalisation d'abonnement que si c'est la première fois qu'il souscrit
|
||||
*/
|
||||
if (!stripe_existing_souscription_id) {
|
||||
if (parseFloat(packprice) > 0)
|
||||
finalize_abonnement(local_souscription_id);
|
||||
else if (String(props.packs).toLowerCase() === String("decouverte")) {
|
||||
MySy_LMS_Account_Management();
|
||||
window.location.reload();
|
||||
}
|
||||
}else{
|
||||
console.log(" laaaaa ")
|
||||
if (String(props.packs).toLowerCase() === String("decouverte")) {
|
||||
MySy_LMS_Account_Management();
|
||||
alert(" La mise à jour de votre abonnement a été correctement traitée. Vous allez recevoir par email les details de la commande et la facture.")
|
||||
window.location.reload();
|
||||
}else{
|
||||
MySy_LMS_Account_Management();
|
||||
alert(" La mise à jour de votre abonnement a été correctement traitée. Vous allez recevoir par email les details de la commande et la facture.")
|
||||
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
/*
|
||||
JE suis ici.
|
||||
la mise à jour du pack semble fonctionner.
|
||||
a faire :
|
||||
tester à fond.
|
||||
si changement de forfait. desactivier toutes les formations avant (dans mysy et le lms)
|
||||
|
||||
pb : coté backoffice. la gestion du : #salt = salt.decode('UTF-8')
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
|
@ -585,8 +683,6 @@ function CheckOut(props) {
|
|||
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
const [paymentadded, setpaymentadded] = useState("");
|
||||
|
@ -616,7 +712,7 @@ function CheckOut(props) {
|
|||
var myurl = process.env.REACT_APP_API_URL + "myclass/api/Check_MySy_LMS_Account/";
|
||||
|
||||
axios.post(myurl, formData_tpm).then(res => {
|
||||
console.log('In MySy_LMS_Account_Management status = ', res.data.status, " -- message = ", res.data.message);
|
||||
console.log('In MySy_LMS_Account_Management status = ', res.data.status, " -- message = ", res.data.message);
|
||||
if (String(res.data.status) === String("true")) {
|
||||
setMySy_LMS_Account_Management_api("true");
|
||||
|
||||
|
@ -965,7 +1061,7 @@ function CheckOut(props) {
|
|||
|
||||
const change_nb_formations = event => {
|
||||
|
||||
if( String(payment_in_process) === "1"){
|
||||
if (String(payment_in_process) === "1") {
|
||||
// un payement est en cours, on ne modifie pas cette valeur
|
||||
return;
|
||||
}
|
||||
|
@ -1029,15 +1125,17 @@ function CheckOut(props) {
|
|||
|
||||
{String(menu) === String("default") && <div>
|
||||
<h2 style={{ "textAlign": "center", "marginBottom": "2rem" }} ref={scrollDiv}> Récapitulatif de votre commande </h2>
|
||||
|
||||
|
||||
<br />
|
||||
|
||||
{payement_3DS_url && <div>
|
||||
|
||||
|
||||
<iframe src={payement_3DS_url} id="3DS_iframe"
|
||||
style={{ "border": "solid 2px", "width": "90%", "height": "600px",
|
||||
"marginBottom":"2rem",
|
||||
"marginLeft":"5%" }}>
|
||||
style={{
|
||||
"border": "solid 2px", "width": "90%", "height": "600px",
|
||||
"marginBottom": "2rem",
|
||||
"marginLeft": "5%"
|
||||
}}>
|
||||
|
||||
</iframe>
|
||||
|
||||
|
@ -1808,12 +1906,12 @@ function CheckOut(props) {
|
|||
<div className="div_row_center">
|
||||
|
||||
{(String(okcommande) !== String("ko") ||
|
||||
(String(props.packs).toLowerCase() === String("decouverte"))) &&
|
||||
(String(props.packs).toLowerCase() === String("decouverte"))) &&
|
||||
String(payment_in_process) !== "1"
|
||||
&& <Button variant="contained" color="success" className="div_row22 btn_enreg_cmd " onClick={Ordervalidation}>Confirmer la commande</Button>}
|
||||
{String(okcommande) === String("ko") && (String(props.packs).toLowerCase() !== String("decouverte")) &&
|
||||
String(payment_in_process) !== "1"
|
||||
&& <Button variant="contained" disabled className="div_row22 btn_enreg_cmd " onClick={""}>Confirmer la commande</Button>}
|
||||
String(payment_in_process) !== "1"
|
||||
&& <Button variant="contained" disabled className="div_row22 btn_enreg_cmd " onClick={""}>Confirmer la commande</Button>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue