created functions to handle all state changes

This commit is contained in:
asus
2024-03-19 12:37:16 +01:00
parent f221e43807
commit 5010b70d79
7 changed files with 317 additions and 97 deletions

View File

@@ -60,7 +60,7 @@ function update_user_pre_order_CIPF($message) {
* - 'nothing' -> output nothing on author page
*
*/
update_field($acf_payment_status['_name'], $acf_payment_status['started'], $acf_id);
set_payment_started($user_id);
}
@@ -128,18 +128,10 @@ function update_user_post_capture_CIPF($message) {
*/
function failure_payment_for_user_CIPF($user_id, $order_id, $status) {
PLGNTLS_class::debug_infos();
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
$acf_account_state = PLGNTLS_class::ACF_ACCOUNT_STATE;
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
$card_duration = PLGNTLS_class::CARD_VALIDITY_TIME;
$prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
$acf_payment_status = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
$acf_id = 'user_'.$user_id;
/*
* remove the order_id from user meta
*
@@ -147,25 +139,8 @@ function failure_payment_for_user_CIPF($user_id, $order_id, $status) {
delete_user_meta($user_id, $meta_order_id, $order_id);
/*
* change payement status to failed
* - 'started' -> at order creation
* - 'success' -> at capture success (on author page, it means success, then mark it 'nothing')
* - 'failure' -> at capture failure (on author page, it means failure, then mark it 'nothing')
* - 'nothing' -> output nothing on author page
*
*/
update_field($acf_payment_status['_name'], $acf_payment_status['failure'], $acf_id);
/*
* other changes on user :
* //- pofil is inactive
* - account_stat is to_pay
*
*/
//update_field($prof_is_activ['_name'], $prof_is_activ['inactiv'], $acf_id);
update_field($acf_account_state['_name'], $acf_account_state['to_pay'], $acf_id);
set_payment_failure($user_id);
set_account_to_pay_CIPF($user_id);
}
@@ -176,26 +151,10 @@ function failure_payment_for_user_CIPF($user_id, $order_id, $status) {
function success_payment_for_user_CIPF($user_id, $order_id) {
PLGNTLS_class::debug_infos();
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
$acf_account_state = PLGNTLS_class::ACF_ACCOUNT_STATE;
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
$acf_card_number = PLGNTLS_class::ACF_CARD_NUMBER;
$card_duration = PLGNTLS_class::CARD_VALIDITY_TIME;
$prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
$acf_payment_status = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
/*
$acf_cgv = PLGNTLS_class::ACF_PROF_CGV;
$acf_payement = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
$acf_delivery = PLGNTLS_class::ACF_CARD_PRICE_DELIVERY;
$acf_price = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
*/
/*
* acf uses 'Y-m-d H:i:s' format : https://www.advancedcustomfields.com/resources/date-time-picker/
*
*/
$acf_id = 'user_'.$user_id;
@@ -206,53 +165,14 @@ function success_payment_for_user_CIPF($user_id, $order_id) {
delete_user_meta($user_id, $meta_order_id, $order_id);
/*
* update date limit validity to add 1 year
*
*/
update_card_expiration_CIPF($user_id, $card_duration);
/*
* - if card status is command, create card id
* - make card status to renewal
*/
$card_status = get_field($acf_card_state['_name'], $acf_id);
if ($card_status === $acf_card_state['new']) {
$card_id = $date_now->format('Ymd') . $user_id;
error_log("-------");
error_log("card_id");
error_log($card_id);
update_field($acf_card_number['_name'], $card_id, $acf_id);
if (is_card_new_CIPF()) {
set_card_number_CIPF($user_id);
}
update_field($acf_card_state['_name'], $acf_card_state['renew'], $acf_id);
set_card_renew_CIPF($user_id);
/*
* change user :
* //- profile is active
* - payement status is success
* - account_state is valid
*
*/
//update_field($prof_is_activ['_name'], $prof_is_activ['activ'], $acf_id);
update_field($acf_payment_status['_name'], $acf_payment_status['success'], $acf_id);
update_field($acf_account_state['_name'], $acf_account_state['valid'], $acf_id);
/*
* reset some fields for the form to buy the card
* - cgv
* - paiement
* - livraison
* - tarif
*
* could make sense to put it here,
* but actually it needs to be put at begining of form
*
update_field($acf_cgv['_name'] , array(""), 'user_'.$user_id);
update_field($acf_payement['_name'], array(""), 'user_'.$user_id);
update_field($acf_delivery['_name'], array(""), 'user_'.$user_id);
update_field($acf_price['_name'] , array(""), 'user_'.$user_id);
*/
set_payment_success($user_id);
}

View File

@@ -65,11 +65,11 @@ function check_can_pay_CIPF() {
/*
* ABANDONNED : formbuilder disfunction when acf field has value:label and return on label, so it's easier for us to just believe their calculation
* calculate price
* update the price even if form builder already did it
* in case it was changed from admin pannel
*
*/
$tarif = get_acf_value_CIPF($acf_card_price_choice['_name'], $acf_id);
$livraison = get_acf_value_CIPF($acf_card_price_delivery['_name'], $acf_id);
if ($tarif !== null && $livraison !== null) {
@@ -79,7 +79,6 @@ function check_can_pay_CIPF() {
$price = 0;
}
update_field($acf_card_price_total['_name'], $price, $acf_id);
*/
/*