diff --git a/plugins/fipfcard_plugin/js/paypal/on_approve.js b/plugins/fipfcard_plugin/js/paypal/on_approve.js index f01ff91..69aeef0 100644 --- a/plugins/fipfcard_plugin/js/paypal/on_approve.js +++ b/plugins/fipfcard_plugin/js/paypal/on_approve.js @@ -33,6 +33,8 @@ export async function onApprove(data, actions) { return actions.restart(); } else if (errorDetail) { // (2) Other non-recoverable errors -> Show a failure message + console.log("errorDetail:"); + console.log(errorDetail); throw new Error(`${errorDetail.description} (${orderData.debug_id})`); } else if (!orderData.purchase_units) { throw new Error(JSON.stringify(orderData)); @@ -51,7 +53,7 @@ export async function onApprove(data, actions) { orderData, JSON.stringify(orderData, null, 2), ); - //actions.redirect(PLGNTLS_data.paypal_redirection_success); + actions.redirect(PLGNTLS_data.paypal_redirection_success); } catch (error) { console.error("payment ok but error on traitment afterwards : ", error); } diff --git a/plugins/fipfcard_plugin/php/author_restriction.php b/plugins/fipfcard_plugin/php/author_restriction.php index 7a763e8..2c0ef1b 100644 --- a/plugins/fipfcard_plugin/php/author_restriction.php +++ b/plugins/fipfcard_plugin/php/author_restriction.php @@ -3,7 +3,15 @@ function restrict_author_page_CIPF() { - if (!is_author()) + $can_access = false; + if (is_author()) + $can_access = true; + else if (current_user_can('administrator')) + $can_access = true; + else if (current_user_can('editor')) + $can_access = true; + + if ($can_access === false) return; global $post; diff --git a/plugins/fipfcard_plugin/php/paypal/paypal.php b/plugins/fipfcard_plugin/php/paypal/paypal.php index 4492286..fbcdf66 100644 --- a/plugins/fipfcard_plugin/php/paypal/paypal.php +++ b/plugins/fipfcard_plugin/php/paypal/paypal.php @@ -9,6 +9,7 @@ if (!defined('ABSPATH')) { +include_once(PLGNTLS_class::get_path() . '/php/utils/http_errors.php'); include_once(PLGNTLS_class::get_path() . '/php/paypal/route_api_utils.php'); include_once(PLGNTLS_class::get_path() . '/php/paypal/user_can_pay.php'); include_once(PLGNTLS_class::get_path() . '/php/paypal/update_user_payment.php'); diff --git a/plugins/fipfcard_plugin/php/paypal/route_api_orders.php b/plugins/fipfcard_plugin/php/paypal/route_api_orders.php index 536d844..b49e58f 100644 --- a/plugins/fipfcard_plugin/php/paypal/route_api_orders.php +++ b/plugins/fipfcard_plugin/php/paypal/route_api_orders.php @@ -19,9 +19,7 @@ function handle_orders_request_FIPF($request_data) { $can_pay = can_pay_now_CIPF(); if ($can_pay['success'] === false) - throw new Exception($can_pay['message']); - error_log("can_pay:"); - error_log(json_encode($can_pay)); + throw new HttpErrorException($can_pay['message'], 403); // Process the order and get the response //$order_response = create_order_FIPF($cart); @@ -33,11 +31,13 @@ function handle_orders_request_FIPF($request_data) { // Return response return new WP_REST_Response($json_response, $http_status_code); - } catch (Exception $error) { - // Handle errors - error_log('Failed to create order: '); - error_log(json_encode($error)); - return new WP_Error('500', 'Failed to create order :' . $error->getMessage(), array('status' => 500)); + } + catch (HttpErrorException $error) { + $status_code = $error->getStatusCode(); + return new WP_Error($status_code, 'Failed to create order in server :' . $error->getMessage(), array('status' => $status_code)); + } + catch (Exception $error) { + return new WP_Error('500', 'Failed to create order in server :' . $error->getMessage(), array('status' => 500)); } } @@ -62,6 +62,7 @@ function create_order_FIPF() $url = PAYPAL_API_BASE_URL . '/v2/checkout/orders'; $payload = array( 'intent' => "CAPTURE", + 'note' => 'ERRPYO005', 'purchase_units' => array( array( 'amount' => array( diff --git a/plugins/fipfcard_plugin/php/paypal/user_can_pay.php b/plugins/fipfcard_plugin/php/paypal/user_can_pay.php index 66d0974..a243f6c 100644 --- a/plugins/fipfcard_plugin/php/paypal/user_can_pay.php +++ b/plugins/fipfcard_plugin/php/paypal/user_can_pay.php @@ -20,9 +20,6 @@ function can_pay_now_CIPF() { $user_id = get_current_user_id(); $acf_id = 'user_' . $user_id; - error_log("etat_carte:"); - error_log(json_encode(get_field_object($acf_card_state, $acf_id))); - /* * check if payment is virement or immediat * @@ -62,18 +59,20 @@ function can_pay_now_CIPF() { * */ $validity_field = get_field_object($acf_card_expiration, $acf_id); + + if ($validity_field === false) + return array('success' => true); + $validity = $validity_field['value']; $format_field = $validity_field['return_format']; - $format_acf = 'Y-m-d H:i:s'; if (empty($validity)) return array('success' => true); - $date_now = date_create('now'); $date_validity = date_create_from_format($format_field, $validity); + + $date_now = date_create('today'); $diff = date_diff($date_now, $date_validity)->format('%R%a'); - error_log("diff"); - error_log($diff); if ((int)$diff <= 0) { // date end of validity in the past return array('success' => true); diff --git a/plugins/fipfcard_plugin/php/utils/http_errors.php b/plugins/fipfcard_plugin/php/utils/http_errors.php new file mode 100644 index 0000000..64124bc --- /dev/null +++ b/plugins/fipfcard_plugin/php/utils/http_errors.php @@ -0,0 +1,30 @@ +statusCode = $statusCode; + } + + public function getStatusCode() { + return $this->statusCode; + } +} + + + + +?> diff --git a/private b/private index c4950c3..e56631d 160000 --- a/private +++ b/private @@ -1 +1 @@ -Subproject commit c4950c3dcda13354dac8757bd81bf76d71c4343c +Subproject commit e56631d8c9b7755703e7239f8194ae33faf42af2