- 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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user