- payment : first date error corrected
- payment : added httpErrorException - payment : error handling wip - profil page restriction gives access to admin and editor
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
|
||||
30
plugins/fipfcard_plugin/php/utils/http_errors.php
Normal file
30
plugins/fipfcard_plugin/php/utils/http_errors.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
|
||||
/*
|
||||
* it means someone outside wp is accessing the file, in this case kill it.
|
||||
*/
|
||||
if (!defined('ABSPATH')) {
|
||||
die('You can not access this file!');
|
||||
}
|
||||
|
||||
|
||||
// Define a custom exception class for HTTP errors
|
||||
class HttpErrorException extends Exception {
|
||||
// HTTP status code
|
||||
private $statusCode;
|
||||
|
||||
public function __construct($message, $statusCode) {
|
||||
parent::__construct($message);
|
||||
$this->statusCode = $statusCode;
|
||||
}
|
||||
|
||||
public function getStatusCode() {
|
||||
return $this->statusCode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
2
private
2
private
Submodule private updated: c4950c3dcd...e56631d8c9
Reference in New Issue
Block a user