From db4cd0ad554b17e8a0a9eefc65c16d1db2729e5d Mon Sep 17 00:00:00 2001 From: asus Date: Tue, 9 Apr 2024 20:02:03 +0200 Subject: [PATCH] =?UTF-8?q?added=20change=20card=20prof=205=E2=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/cipf_plugin/cipf_plugin.php | 13 ++- .../css/display_states/changer_carte.css | 4 + plugins/cipf_plugin/php/_actions_emails.php | 107 ------------------ plugins/cipf_plugin/php/_utils_acf_fields.php | 67 +++++++++++ .../cipf_plugin/php/_utils_display_css.php | 8 ++ .../cipf_plugin/php/paypal/payment_page.php | 36 +++++- plugins/cipf_plugin/php/paypal/shortcode.php | 6 - .../php/paypal/update_user_payment.php | 34 +++++- .../cipf_plugin/php/paypal/user_can_pay.php | 12 +- 9 files changed, 169 insertions(+), 118 deletions(-) create mode 100644 plugins/cipf_plugin/css/display_states/changer_carte.css diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php index a01ebdd..d2ab2e7 100644 --- a/plugins/cipf_plugin/cipf_plugin.php +++ b/plugins/cipf_plugin/cipf_plugin.php @@ -4,7 +4,7 @@ Plugin Name: hggg_cipf Plugin URI: Description: Author: hugogogo -Version: 0.5.5 +Version: 0.5.6 Author URI: */ @@ -83,6 +83,7 @@ class Cipf { const ACF_PAGE_STATE = ['_name'=>'etat_page_partenaire', 'publish'=>'Publiee', 'draft'=>'Brouillon']; const ACF_CARD_ORDER_ID = ['_name'=>'order_id']; const ACF_HISTORY = ['_name'=>'history']; + const ACF_PROF_CHANGE_CARD = ['_name'=>'changement_de_carte']; // META const META_PAYEMENT_STATUS = 'cipf_payement_status'; @@ -205,6 +206,16 @@ contactez la fipf directement", 'confirmation_subject'=>"[CIPF - virement validé]", 'confirmation_message'=>"votre virement a été validé", ], + 'change_card_success'=>[ + 'name'=>'prof - le paiement pour changer la carte a réussi', + 'notification_send'=>true, + 'notification_to'=>'$$__admin_email__$$', + 'notification_subject'=>"[CIPF /prof - paiement changer carte reussi]", + 'notification_message'=>'paiement pour changer sa carte a réussi de la part de $$user_login$$ : $$__author_page_url__$$', + 'confirmation_send'=>true, + 'confirmation_subject'=>"[CIPF - paiement changement carte réussi]", + 'confirmation_message'=>"paiement changement carte réussi", + ], 'account_deleted'=>[ 'name'=>'prof - le compte a été supprimé', 'notification_send'=>true, diff --git a/plugins/cipf_plugin/css/display_states/changer_carte.css b/plugins/cipf_plugin/css/display_states/changer_carte.css new file mode 100644 index 0000000..dd39560 --- /dev/null +++ b/plugins/cipf_plugin/css/display_states/changer_carte.css @@ -0,0 +1,4 @@ + +[class*='cipf_display_'].cipf_display_changer_carte { display: block !important; } +[class*='cipf_display_'].cipf_display_changer_carte.cipf_flex { display: flex !important; } + diff --git a/plugins/cipf_plugin/php/_actions_emails.php b/plugins/cipf_plugin/php/_actions_emails.php index 078f730..f757f09 100644 --- a/plugins/cipf_plugin/php/_actions_emails.php +++ b/plugins/cipf_plugin/php/_actions_emails.php @@ -90,113 +90,6 @@ function send_emails_CIPF($email_name, $user_id = null) { } -//function email_payment_success_CIPF($user_id = null) { -// Plgntls::debug_infos(); -//error_log("email payment success: " . json_encode($email_payment_success)); -// -// send_email_CIPF($email_payment_success, $user_id); -// $user = get_user_by('id', $user_id); -//// $to = $user->user_email; -// $to = '$$__admin_email__$$'; -// $subject = 'My Custom Email Subject'; -// $message = 'Hello, This is a test email sent from my WordPress plugin!'; -// $headers = array('Content-Type: text/html; charset=UTF-8'); -// -// -// // Check if the email was sent successfully -//} - -/* - 'payment_success'=>[ - 'notification_send'=>true, - 'notification_to'=>'$$__admin_email__$$', - 'notification_subject'=>"paiement réussi", - 'notification_message'=>"par ici la monnaie", - 'confirmation_send'=>true, - 'confirmation_subject'=>"paiement réussi", - 'confirmation_mesage'=>"donne l'argent", - ], -// 2. profs : email : payment_failure : validation payment prof echec, send email - 'payment_echec'=>[ - 'notification_send'=>true, - 'notification_to'=>'$$__admin_email__$$', - 'notification_subject'=>"", - 'notification_message'=>"", - 'confirmation_send'=>true, - 'confirmation_subject'=>"", - 'confirmation_mesage'=>"", - ], -// 3. profs : email : transfert_success : validation transfert prof reussi, send email - 'transfert_success'=>[ - 'notification_send'=>true, - 'notification_to'=>'$$__admin_email__$$', - 'notification_subject'=>"", - 'notification_message'=>"", - 'confirmation_send'=>true, - 'confirmation_subject'=>"", - 'confirmation_mesage'=>"", - ], -// 4. profs : email : transfert_failures : validation transfert prof echec, send email - 'transfert_echec'=>[ - 'notification_send'=>true, - 'notification_to'=>'$$__admin_email__$$', - 'notification_subject'=>"", - 'notification_message'=>"", - 'confirmation_send'=>true, - 'confirmation_subject'=>"", - 'confirmation_mesage'=>"", - ], -// 5. partners : email : offer_expired : offres temporaires -> gerer qu'elles disparaissent apres la date de validite -> la passer en masquer - 'offer_expired'=>[ - 'notification_send'=>true, - 'notification_to'=>'$$__admin_email__$$', - 'notification_subject'=>"", - 'notification_message'=>"", - 'confirmation_send'=>true, - 'confirmation_subject'=>"", - 'confirmation_mesage'=>"", - ], -// 6. partners : email : offer_will_expire : la gestion des offres à échéance - 'offer_will_expire'=>[ - 'notification_send'=>true, - 'notification_to'=>'$$__admin_email__$$', - 'notification_subject'=>"", - 'notification_message'=>"", - 'confirmation_send'=>true, - 'confirmation_subject'=>"", - 'confirmation_mesage'=>"", - ], -// 7. payments : email : account_deleted : schedule event pour supprimer le compte xx temps (6 mois ?) apres fin de validite de la carte - 'account_deleted'=>[ - 'notification_send'=>true, - 'notification_to'=>'$$__admin_email__$$', - 'notification_subject'=>"", - 'notification_message'=>"", - 'confirmation_send'=>true, - 'confirmation_subject'=>"", - 'confirmation_mesage'=>"", - ], -// 8. payments : email : account_will_expire : faire rappels emails avant expiration - 'eccount_will_expire'=>[ - 'notification_send'=>true, - 'notification_to'=>'$$__admin_email__$$', - 'notification_subject'=>"", - 'notification_message'=>"", - 'confirmation_send'=>true, - 'confirmation_subject'=>"", - 'confirmation_mesage'=>"", - ], -// 9. payments : email : account_expired : desactiver carte expiree - 'account_expired'=>[ - 'notification_send'=>true, - 'notification_to'=>'$$__admin_email__$$', - 'notification_subject'=>"", - 'notification_message'=>"", - 'confirmation_send'=>true, - 'confirmation_subject'=>"", - 'confirmation_mesage'=>"", - ], -*/ diff --git a/plugins/cipf_plugin/php/_utils_acf_fields.php b/plugins/cipf_plugin/php/_utils_acf_fields.php index 0dda8ff..a332616 100644 --- a/plugins/cipf_plugin/php/_utils_acf_fields.php +++ b/plugins/cipf_plugin/php/_utils_acf_fields.php @@ -46,6 +46,8 @@ if (!defined('ABSPATH')) { * * [/] card price ('somme_a_regler') * +* [/] prof change card ('changement_de_carte') +* * */ @@ -55,6 +57,7 @@ function get_field_init_CIPF($acf_field_name, $acf_id) { Plgntls::debug_infos(); $acf_state = get_field($acf_field_name, $acf_id); +error_log("acf_state: " . json_encode($acf_state)); if ($acf_state !== null) { return $acf_state; } @@ -69,6 +72,8 @@ function get_field_init_CIPF($acf_field_name, $acf_id) { update_field($acf_field_name, '', $acf_id); $acf_object = get_field_object($acf_field_name, $acf_id); +error_log("acf_object: " . json_encode($acf_object)); + $default = ''; if (isset($acf_object['default_value'])) { $default = $acf_object['default_value']; @@ -549,6 +554,9 @@ function reset_acf_cgv_CIPF($user_id = null) { + + + /* * card price * @@ -563,6 +571,65 @@ function get_card_price_CIPF($user_id = null) { $acf_id = 'user_'.$user_id; return get_acf_field_CIPF($acf_card_price_total, $acf_id); } +//function set_card_price_CIPF($value, $user_id = null) { +// Plgntls::debug_infos(); +// $acf_card_price_total = Cipf::ACF_CARD_PRICE_TOTAL; +// +// if (is_null($user_id)) { +// $user_id = get_current_user_id(); +// } +// $acf_id = 'user_'.$user_id; +// set_acf_field_CIPF($acf_card_price_total, $value, $acf_id); +//} +//function reset_card_price_CIPF($user_id = null) { +// Plgntls::debug_infos(); +// $acf_card_price_total = Cipf::ACF_CARD_PRICE_TOTAL; +// +// if (is_null($user_id)) { +// $user_id = get_current_user_id(); +// } +// $acf_id = 'user_'.$user_id; +// set_acf_field_CIPF($acf_card_price_total, 0, $acf_id); +//} + + + + + +/* +* prof change card +* +*/ +function reset_acf_prof_change_card_CIPF($user_id = null) { + Plgntls::debug_infos(); + $acf_prof_change_card = Cipf::ACF_PROF_CHANGE_CARD; + + if (is_null($user_id)) { + $user_id = get_current_user_id(); + } + $acf_id = 'user_'.$user_id; + set_acf_field_CIPF($acf_prof_change_card, false, $acf_id); +} +function set_acf_prof_change_card_CIPF($user_id = null) { + Plgntls::debug_infos(); + $acf_prof_change_card = Cipf::ACF_PROF_CHANGE_CARD; + + if (is_null($user_id)) { + $user_id = get_current_user_id(); + } + $acf_id = 'user_'.$user_id; + set_acf_field_CIPF($acf_prof_change_card, true, $acf_id); +} +function is_acf_prof_change_card_CIPF($user_id = null) { + Plgntls::debug_infos(); + $acf_prof_change_card = Cipf::ACF_PROF_CHANGE_CARD; + + if (is_null($user_id)) { + $user_id = get_current_user_id(); + } + $acf_id = 'user_'.$user_id; + return is_acf_field_CIPF($acf_prof_change_card, true, $acf_id); +} diff --git a/plugins/cipf_plugin/php/_utils_display_css.php b/plugins/cipf_plugin/php/_utils_display_css.php index 4eee3e0..19cfeaf 100644 --- a/plugins/cipf_plugin/php/_utils_display_css.php +++ b/plugins/cipf_plugin/php/_utils_display_css.php @@ -92,6 +92,14 @@ function display_states_css_CIPF($user_id = null) { $css_for_states[] = 'css/display_states/type_virement.css'; } + /* + * prof change carte + * + */ + if (is_acf_prof_change_card_CIPF($user_id)) { + $css_for_states[] = 'css/display_states/changer_carte.css'; + } + /* * page partenaire * - 'Publiee' diff --git a/plugins/cipf_plugin/php/paypal/payment_page.php b/plugins/cipf_plugin/php/paypal/payment_page.php index c3e7157..82ea85d 100644 --- a/plugins/cipf_plugin/php/paypal/payment_page.php +++ b/plugins/cipf_plugin/php/paypal/payment_page.php @@ -10,6 +10,27 @@ if (!defined('ABSPATH')) { +/* +* action to be done at the init state of the page +* +*/ +function prof_payment_page_init_CIPF() { + Plgntls::debug_infos(2); + + if (!is_prof_CIPF()) { + return; + } + Plgntls::debug_infos(); + + // https://developer.wordpress.org/reference/functions/get_query_var/#more-information + global $wp; + $wp->add_query_var('prof_card_change'); +} +add_action('init','prof_payment_page_init_CIPF'); + + + + /* @@ -29,7 +50,18 @@ function payment_page_checks_CIPF() { // get the user id $user_id = get_current_user_id(); - // do checks here + /* + * check for query card change + * and modify acf field accordingly + * + */ + $is_card_change = get_query_var('prof_card_change', false); + if ($is_card_change == true) { + set_acf_prof_change_card_CIPF(); + } + else { + reset_acf_prof_change_card_CIPF(); + } } add_action('wp', 'payment_page_checks_CIPF'); @@ -37,6 +69,8 @@ add_action('wp', 'payment_page_checks_CIPF'); + + /* * only profs can access this page * diff --git a/plugins/cipf_plugin/php/paypal/shortcode.php b/plugins/cipf_plugin/php/paypal/shortcode.php index 48ee262..5933b70 100644 --- a/plugins/cipf_plugin/php/paypal/shortcode.php +++ b/plugins/cipf_plugin/php/paypal/shortcode.php @@ -24,8 +24,6 @@ function paypal_shortcode_content_CIPF() { $paypal_message_failure = get_payment_message_failure_CIPF(); $paypal_message_problem = get_payment_message_problem_CIPF(); -// if (!can_pay_now_CIPF()) -// return no_payment_CIPF(); $pp_client_id = $paypal_client_id; $pp_sdk_currency = "EUR"; @@ -55,10 +53,6 @@ function paypal_shortcode_content_CIPF() { add_shortcode('cipf_paypal_shortcode', 'paypal_shortcode_content_CIPF'); -function no_payment_CIPF() { - Plgntls::debug_infos(); - return; -} diff --git a/plugins/cipf_plugin/php/paypal/update_user_payment.php b/plugins/cipf_plugin/php/paypal/update_user_payment.php index 20c5839..c4a2903 100644 --- a/plugins/cipf_plugin/php/paypal/update_user_payment.php +++ b/plugins/cipf_plugin/php/paypal/update_user_payment.php @@ -128,11 +128,26 @@ function failure_payment_for_user_CIPF($user_id, $order_id, $status) { schedule_delete_orderid_CIPF($order_id, $user_id); set_payment_failure_CIPF($user_id); - set_account_to_pay_CIPF($user_id); send_emails_CIPF('payment_echec', $user_id); + + /* + * if payment was only for card change + * + */ + if (is_acf_prof_change_card_CIPF($user_id)) { + reset_acf_prof_change_card_CIPF($user_id); + return; + } + + /* + * else + * + */ + set_account_to_pay_CIPF($user_id); } + /* * things to do when a payment is a success * @@ -141,9 +156,24 @@ function success_payment_for_user_CIPF($user_id, $order_id) { Plgntls::debug_infos(); schedule_delete_orderid_CIPF($order_id, $user_id); + + /* + * if payment was only for card change + * + */ + if (is_acf_prof_change_card_CIPF($user_id)) { + reset_acf_prof_change_card_CIPF($user_id); + send_emails_CIPF('change_card_success', $user_id); + return; + } + + /* + * else + * + */ update_card_date_expiration_CIPF($user_id); - if (is_card_new_CIPF()) { + if (is_card_new_CIPF($user_id)) { set_card_number_CIPF($user_id); set_card_renew_CIPF($user_id); } diff --git a/plugins/cipf_plugin/php/paypal/user_can_pay.php b/plugins/cipf_plugin/php/paypal/user_can_pay.php index 8e47a64..e6439be 100644 --- a/plugins/cipf_plugin/php/paypal/user_can_pay.php +++ b/plugins/cipf_plugin/php/paypal/user_can_pay.php @@ -56,7 +56,7 @@ function check_can_pay_CIPF() { -schedule_prof_account_deletion_CIPF($user_id); +//schedule_prof_account_deletion_CIPF($user_id); /* * check if payment is virement or immediat @@ -98,6 +98,16 @@ schedule_prof_account_deletion_CIPF($user_id); return new WP_Error('cannot_purchase', "price is 0, nothing to purchase"); } + /* + * if is new account and is only to change card + * + */ + if (is_card_new_CIPF()) { + if (is_acf_prof_change_card_CIPF()) { + return new WP_Error('cannot_purchase', "account is new, you cannot change your card"); + } + } + /* * date validity is empty