added another state of error in payment if the payment is a success but the treatment has an error

This commit is contained in:
asus
2024-04-02 23:39:27 +02:00
parent 9e903a2ecf
commit 9abe24b3bb
10 changed files with 223 additions and 71 deletions

View File

@@ -59,14 +59,19 @@ function update_payment_messages_option_CIPF($request, $option_name, $option_dat
*/
$success = '';
$failure = '';
$problem = '';
if (!isset($request['message_success'])) {
return;
}
if (!isset($request['message_failure'])) {
return;
}
if (!isset($request['message_problem'])) {
return;
}
$success = $request['message_success'];
$failure = $request['message_failure'];
$problem = $request['message_problem'];
/*
@@ -77,6 +82,7 @@ function update_payment_messages_option_CIPF($request, $option_name, $option_dat
$data = array(
'success' => $success,
'failure' => $failure,
'problem' => $problem,
);
Plgntls::update_option_safe($option_name, $data);
}

View File

@@ -23,50 +23,179 @@ if (!defined('ABSPATH')) {
* 8. payments : email : account_will_expire : faire rappels emails avant expiration
* 9. payments : email : account_expired : desactiver carte expiree
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
function email_success_payment_CIPF($user_id) {
function prepare_emails_CIPF($email_name, $user_id) {
Plgntls::debug_infos();
error_log("in email success");
$emails_option_object = Cipf::OPTION_EMAILS;
if (!isset($emails_option_object['_default'][$email_name])) {
return false;
}
$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');
if (is_null($user_id)) {
$user_id = get_current_user_id();
}
$sent = wp_mail($to, $subject, $message, $headers);
$emails_option = Plgntls::get_option_safe($emails_option_object);
if (!$emails_option) {
return false;
}
if (!isset($emails_option[$email_name])) {
return false;
}
$email = $emails_option[$email_name];
// Check if the email was sent successfully
$emails = array();
if ($email['notification_send']) {
$tmp_email = array();
$tmp_email['to'] = $email['notification_to'];
$tmp_email['subject'] = $email['notification_subject'];
$tmp_email['message'] = $email['notification_message'];
$tmp_email['headers'] = array('Content-Type: text/html; charset=UTF-8');
$emails[] = $tmp_email;
}
if ($email['confirmation_send']) {
$tmp_email = array();
$tmp_email['to'] = $user_id;
$tmp_email['subject'] = $email['confirmation_subject'];
$tmp_email['message'] = $email['confirmation_message'];
$tmp_email['headers'] = array('Content-Type: text/html; charset=UTF-8');
$emails[] = $tmp_email;
}
return $emails;
}
function send_emails_CIPF($email_name, $user_id = null) {
Plgntls::debug_infos();
$emails = prepare_emails_CIPF($email_name, $user_id);
if (false === $emails) {
error_log('Email preparing failed!: ' . json_encode($emails));
return;
}
foreach ($emails as $email) {
$sent = wp_mail($email['to'], $email['subject'], $email['message'], $email['headers']);
}
if (!$sent) {
error_log('Email sending failed!');
error_log('Email sending failed!: ' . json_encode($email));
}
}
//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'=>"",
],
*/

View File

@@ -113,18 +113,21 @@ function get_payment_messages_option_CIPF() {
return Plgntls::get_option_safe($option_payment);
}
function get_payment_message_success_CIPF() {
Plgntls::debug_infos();
$payment_option = get_payment_messages_option_CIPF();
return $payment_option['success'];
}
function get_payment_message_failure_CIPF() {
Plgntls::debug_infos();
$payment_option = get_payment_messages_option_CIPF();
return $payment_option['failure'];
}
function get_payment_message_problem_CIPF() {
Plgntls::debug_infos();
$payment_option = get_payment_messages_option_CIPF();
return $payment_option['problem'];
}
?>

View File

@@ -55,15 +55,16 @@ function handle_orders_capture_request_CIPF($request) {
try {
update_user_post_capture_CIPF($json_response, 'end');
throw new HttpException('cannot find user with this order_id', 502);
return new WP_REST_Response($json_response, $http_status_code);
}
catch (HttpException $error) {
$status_code = $error->getStatusCode();
$message = 'Failed to handle order after capture in server :' . $error->getMessage();
$message = array('ERROR_TREATMENT'=>true, 'message'=>'Failed to handle order after capture in server: ' . $error->getMessage());
return new WP_REST_Response($message, $status_code);
}
catch (Exception $error) {
$message = 'Failed to handle order after capture in server :' . $error->getMessage();
$message = array('ERROR_TREATMENT'=>true, 'message'=>'Failed to handle order after capture in server: ' . $error->getMessage());
return new WP_REST_Response($message, 500);
}

View File

@@ -22,6 +22,7 @@ function paypal_shortcode_content_CIPF() {
$paypal_client_id = get_paypal_client_id_CIPF();
$paypal_message_success = get_payment_message_success_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();
@@ -45,6 +46,7 @@ function paypal_shortcode_content_CIPF() {
'paypal_redirection_failure',
'paypal_message_success',
'paypal_message_failure',
'paypal_message_problem',
),
);

View File

@@ -171,7 +171,7 @@ function success_payment_for_user_CIPF($user_id, $order_id) {
set_payment_success_CIPF($user_id);
set_account_valid_CIPF($user_id);
email_success_payment_CIPF($user_id);
send_emails_CIPF('payment_success', $user_id);
}