changed all instances of fipf to cipf
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: fipfcard_plugin
|
Plugin Name: cipfcard_plugin
|
||||||
Plugin URI:
|
Plugin URI:
|
||||||
Description:
|
Description:
|
||||||
Author: hugogogo
|
Author: hugogogo
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import { PLGNTLS_fetch } from '../../utils/plgntls_fetch.js';
|
|||||||
//async function createOrder() {
|
//async function createOrder() {
|
||||||
export async function createOrder() {
|
export async function createOrder() {
|
||||||
try {
|
try {
|
||||||
//const fetch_create_url = PLGNTLS_data.fetch_url + "/fipf_plugin/api/v1/orders";
|
//const fetch_create_url = PLGNTLS_data.fetch_url + "/cipf_plugin/api/v1/orders";
|
||||||
//console.log("fetch_create_url:", fetch_create_url);
|
//console.log("fetch_create_url:", fetch_create_url);
|
||||||
//const response = await fetch(fetch_create_url, {
|
//const response = await fetch(fetch_create_url, {
|
||||||
const response = await PLGNTLS_fetch('/fipf_plugin/api/v1/orders', {
|
const response = await PLGNTLS_fetch('/cipf_plugin/api/v1/orders', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -51,7 +51,7 @@ export async function createOrder() {
|
|||||||
*
|
*
|
||||||
// Call your server to set up the transaction
|
// Call your server to set up the transaction
|
||||||
function createOrder(data, actions) {
|
function createOrder(data, actions) {
|
||||||
const fetch_create_url = PLGNTLS_data.fetch_url + "/fipf_plugin/api/v1/orders";
|
const fetch_create_url = PLGNTLS_data.fetch_url + "/cipf_plugin/api/v1/orders";
|
||||||
console.log("fetch_create_url:", fetch_create_url);
|
console.log("fetch_create_url:", fetch_create_url);
|
||||||
return fetch(fetch_create_url, {
|
return fetch(fetch_create_url, {
|
||||||
method: 'post'
|
method: 'post'
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import { PLGNTLS_fetch } from '../../utils/plgntls_fetch.js';
|
|||||||
//async function onApprove(data, actions) {
|
//async function onApprove(data, actions) {
|
||||||
export async function onApprove(data, actions) {
|
export async function onApprove(data, actions) {
|
||||||
try {
|
try {
|
||||||
const fetch_approve_url = PLGNTLS_data.fetch_url + "/fipf_plugin/api/v1/orders/" + data.orderID + "/capture";
|
const fetch_approve_url = PLGNTLS_data.fetch_url + "/cipf_plugin/api/v1/orders/" + data.orderID + "/capture";
|
||||||
console.log("fetch_approve_url:", fetch_approve_url);
|
console.log("fetch_approve_url:", fetch_approve_url);
|
||||||
//const response = await fetch(fetch_approve_url, {
|
//const response = await fetch(fetch_approve_url, {
|
||||||
const response = await PLGNTLS_fetch('/fipf_plugin/api/v1/orders/' + data.orderID + '/capture', {
|
const response = await PLGNTLS_fetch('/cipf_plugin/api/v1/orders/' + data.orderID + '/capture', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -71,7 +71,7 @@ export async function onApprove(data, actions) {
|
|||||||
*
|
*
|
||||||
// Call your server to finalize the transaction
|
// Call your server to finalize the transaction
|
||||||
function onApprove (data, actions) {
|
function onApprove (data, actions) {
|
||||||
const fetch_approve_url = PLGNTLS_data.fetch_url + "/fipf_plugin/api/v1/orders/" + data.orderID + "/capture";
|
const fetch_approve_url = PLGNTLS_data.fetch_url + "/cipf_plugin/api/v1/orders/" + data.orderID + "/capture";
|
||||||
console.log("fetch_approve_url:", fetch_approve_url);
|
console.log("fetch_approve_url:", fetch_approve_url);
|
||||||
return fetch(fetch_approve_url, {
|
return fetch(fetch_approve_url, {
|
||||||
method: 'post'
|
method: 'post'
|
||||||
|
|||||||
@@ -13,18 +13,18 @@ if (!defined('ABSPATH')) {
|
|||||||
/*
|
/*
|
||||||
* menu plugin
|
* menu plugin
|
||||||
*/
|
*/
|
||||||
function fipfcard_plugin_menu()
|
function cipfcard_plugin_menu()
|
||||||
{
|
{
|
||||||
add_menu_page
|
add_menu_page
|
||||||
(
|
(
|
||||||
'fipf_card', // webpage title
|
'cipf_card', // webpage title
|
||||||
'fipf_card', // menu title
|
'cipf_card', // menu title
|
||||||
'manage_options', // capability
|
'manage_options', // capability
|
||||||
'fipfcard-plugin', // menu_slug
|
'cipfcard-plugin', // menu_slug
|
||||||
'fipfcard_plugin_content' // callback function to display page content
|
'cipfcard_plugin_content' // callback function to display page content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
add_action('admin_menu', 'fipfcard_plugin_menu');
|
add_action('admin_menu', 'cipfcard_plugin_menu');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -35,8 +35,8 @@ if (!defined('ABSPATH')) {
|
|||||||
die('You can not access this file!');
|
die('You can not access this file!');
|
||||||
}
|
}
|
||||||
|
|
||||||
function fipfcard_plugin_content() {
|
function cipfcard_plugin_content() {
|
||||||
$fipfcard = new PLGNTLS_class();
|
$cipfcard = new PLGNTLS_class();
|
||||||
|
|
||||||
$my_css = '
|
$my_css = '
|
||||||
#mytext {
|
#mytext {
|
||||||
@@ -46,7 +46,7 @@ function fipfcard_plugin_content() {
|
|||||||
background-color: lightgreen;
|
background-color: lightgreen;
|
||||||
}
|
}
|
||||||
';
|
';
|
||||||
echo $fipfcard->add_to_front( array(
|
echo $cipfcard->add_to_front( array(
|
||||||
array("js/menu/example_menu.js", 'type'=>'module'),
|
array("js/menu/example_menu.js", 'type'=>'module'),
|
||||||
"css/menu/menu.css",
|
"css/menu/menu.css",
|
||||||
"PLGNTLS_menu_css" => array('css'=>$my_css),
|
"PLGNTLS_menu_css" => array('css'=>$my_css),
|
||||||
@@ -66,17 +66,17 @@ ajax
|
|||||||
- to access the content of the data object properties of the ajax call :
|
- to access the content of the data object properties of the ajax call :
|
||||||
use $_POST['property_name']
|
use $_POST['property_name']
|
||||||
*/
|
*/
|
||||||
function fipfcard_menu_fetch_handler()
|
function cipfcard_menu_fetch_handler()
|
||||||
{
|
{
|
||||||
return new WP_REST_Response('hello', 200);
|
return new WP_REST_Response('hello', 200);
|
||||||
}
|
}
|
||||||
function fipfcard_menu_endpoint()
|
function cipfcard_menu_endpoint()
|
||||||
{
|
{
|
||||||
register_rest_route('plgntls', '/get_data', array(
|
register_rest_route('plgntls', '/get_data', array(
|
||||||
'methods' => 'POST',
|
'methods' => 'POST',
|
||||||
'callback' => 'fipfcard_menu_fetch_handler',
|
'callback' => 'cipfcard_menu_fetch_handler',
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
add_action('rest_api_init', 'fipfcard_menu_endpoint');
|
add_action('rest_api_init', 'cipfcard_menu_endpoint');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ function restrict_author_page_CIPF() {
|
|||||||
$current_user_id = get_current_user_id();
|
$current_user_id = get_current_user_id();
|
||||||
|
|
||||||
if ($current_user_id != $author_id) {
|
if ($current_user_id != $author_id) {
|
||||||
wp_redirect(home_url());
|
wp_redirect(home_url(), 301);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ if (!defined('ABSPATH')) {
|
|||||||
|
|
||||||
|
|
||||||
function test_modal_PLGNTLS() {
|
function test_modal_PLGNTLS() {
|
||||||
$fipf_modal = new PLGNTLS_class();
|
$cipf_modal = new PLGNTLS_class();
|
||||||
$fipf_modal->add_to_front(
|
$cipf_modal->add_to_front(
|
||||||
array(
|
array(
|
||||||
'js/form_builder_patch/multiple_modals.js',
|
'js/form_builder_patch/multiple_modals.js',
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ if (!defined('ABSPATH')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
function fipfcard_image_editor()
|
function cipfcard_image_editor()
|
||||||
{
|
{
|
||||||
// ob_start();
|
// ob_start();
|
||||||
// wp_image_editor('33545');
|
// wp_image_editor('33545');
|
||||||
// return ob_get_clean();
|
// return ob_get_clean();
|
||||||
$fipfcard_image_editor = new PLGNTLS_class();
|
$cipfcard_image_editor = new PLGNTLS_class();
|
||||||
return $fipfcard_image_editor->add_to_front(
|
return $cipfcard_image_editor->add_to_front(
|
||||||
array(
|
array(
|
||||||
"js/image_editor.js",
|
"js/image_editor.js",
|
||||||
"html/image_editor.html",
|
"html/image_editor.html",
|
||||||
@@ -24,7 +24,7 @@ function fipfcard_image_editor()
|
|||||||
// it returns error 400
|
// it returns error 400
|
||||||
|
|
||||||
}
|
}
|
||||||
add_shortcode('fipfcard_image_editor', 'fipfcard_image_editor');
|
add_shortcode('cipfcard_image_editor', 'cipfcard_image_editor');
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ if (!defined('ABSPATH')) {
|
|||||||
/**
|
/**
|
||||||
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||||
*/
|
*/
|
||||||
function handle_orders_request_FIPF($request_data) {
|
function handle_orders_request_CIPF($request_data) {
|
||||||
try {
|
try {
|
||||||
// Extract cart information from request body
|
// Extract cart information from request body
|
||||||
//$cart = $request_data['cart'];
|
//$cart = $request_data['cart'];
|
||||||
@@ -22,12 +22,12 @@ function handle_orders_request_FIPF($request_data) {
|
|||||||
throw new HttpErrorException($can_pay['message'], 403);
|
throw new HttpErrorException($can_pay['message'], 403);
|
||||||
|
|
||||||
// Process the order and get the response
|
// Process the order and get the response
|
||||||
//$order_response = create_order_FIPF($cart);
|
//$order_response = create_order_CIPF($cart);
|
||||||
$order_response = create_order_FIPF();
|
$order_response = create_order_CIPF();
|
||||||
$json_response = $order_response['json_response'];
|
$json_response = $order_response['json_response'];
|
||||||
$http_status_code = $order_response['http_status_code'];
|
$http_status_code = $order_response['http_status_code'];
|
||||||
|
|
||||||
update_user_payment_FIPF($json_response, 'start');
|
update_user_payment_CIPF($json_response, 'start');
|
||||||
|
|
||||||
// Return response
|
// Return response
|
||||||
return new WP_REST_Response($json_response, $http_status_code);
|
return new WP_REST_Response($json_response, $http_status_code);
|
||||||
@@ -48,12 +48,12 @@ function handle_orders_request_FIPF($request_data) {
|
|||||||
* Create an order to start the transaction.
|
* Create an order to start the transaction.
|
||||||
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_create
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_create
|
||||||
*/
|
*/
|
||||||
//function create_order_FIPF($cart)
|
//function create_order_CIPF($cart)
|
||||||
function create_order_FIPF()
|
function create_order_CIPF()
|
||||||
{
|
{
|
||||||
// use the cart information passed from the front-end to calculate the purchase unit details
|
// use the cart information passed from the front-end to calculate the purchase unit details
|
||||||
|
|
||||||
$access_token = generate_access_token_FIPF();
|
$access_token = generate_access_token_CIPF();
|
||||||
|
|
||||||
$user_id = get_current_user_id();
|
$user_id = get_current_user_id();
|
||||||
$acf_id = 'user_' . $user_id;
|
$acf_id = 'user_' . $user_id;
|
||||||
@@ -100,7 +100,7 @@ function create_order_FIPF()
|
|||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
// in utils
|
// in utils
|
||||||
return handle_response_FIPF($response);
|
return handle_response_CIPF($response);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,18 +10,18 @@ if (!defined('ABSPATH')) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function handle_orders_capture_request_FIPF($request) {
|
function handle_orders_capture_request_CIPF($request) {
|
||||||
$order_id = $request['orderID'];
|
$order_id = $request['orderID'];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Implement captureOrder function logic here
|
// Implement captureOrder function logic here
|
||||||
// Make sure you implement captureOrder function similar to the Node.js code
|
// Make sure you implement captureOrder function similar to the Node.js code
|
||||||
|
|
||||||
$response_data = capture_order_FIPF($order_id);
|
$response_data = capture_order_CIPF($order_id);
|
||||||
$http_status_code = $response_data['http_status_code'];
|
$http_status_code = $response_data['http_status_code'];
|
||||||
$json_response = $response_data['json_response'];
|
$json_response = $response_data['json_response'];
|
||||||
|
|
||||||
update_user_payment_FIPF($json_response, 'end');
|
update_user_payment_CIPF($json_response, 'end');
|
||||||
|
|
||||||
return new WP_REST_Response($json_response, $http_status_code);
|
return new WP_REST_Response($json_response, $http_status_code);
|
||||||
}
|
}
|
||||||
@@ -35,8 +35,8 @@ function handle_orders_capture_request_FIPF($request) {
|
|||||||
* Capture payment for the created order to complete the transaction.
|
* Capture payment for the created order to complete the transaction.
|
||||||
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
||||||
*/
|
*/
|
||||||
function capture_order_FIPF($orderID) {
|
function capture_order_CIPF($orderID) {
|
||||||
$access_token = generate_access_token_FIPF();
|
$access_token = generate_access_token_CIPF();
|
||||||
$url = PAYPAL_API_BASE_URL . '/v2/checkout/orders/' . $orderID . '/capture';
|
$url = PAYPAL_API_BASE_URL . '/v2/checkout/orders/' . $orderID . '/capture';
|
||||||
|
|
||||||
$headers = array(
|
$headers = array(
|
||||||
@@ -65,7 +65,7 @@ function capture_order_FIPF($orderID) {
|
|||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
// in utils
|
// in utils
|
||||||
return handle_response_FIPF($response);
|
return handle_response_CIPF($response);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ if (!defined('ABSPATH')) {
|
|||||||
/**
|
/**
|
||||||
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||||
*/
|
*/
|
||||||
function handle_response_FIPF($response) {
|
function handle_response_CIPF($response) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Decode JSON response
|
// Decode JSON response
|
||||||
@@ -54,7 +54,7 @@ async function handleResponse(response) {
|
|||||||
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||||
* @see https://developer.paypal.com/api/rest/authentication/
|
* @see https://developer.paypal.com/api/rest/authentication/
|
||||||
*/
|
*/
|
||||||
function generate_access_token_FIPF()
|
function generate_access_token_CIPF()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,20 +11,19 @@ if (!defined('ABSPATH')) {
|
|||||||
|
|
||||||
// handling routes and endpoints
|
// handling routes and endpoints
|
||||||
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
|
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
|
||||||
function routes_endpoints_FIPF()
|
function routes_endpoints_CIPF()
|
||||||
{
|
{
|
||||||
$base_rest_route = "fipf_plugin/api/v1";
|
$base_rest_route = "cipf_plugin/api/v1";
|
||||||
register_rest_route($base_rest_route, '/orders', array(
|
register_rest_route($base_rest_route, '/orders', array(
|
||||||
'methods' => 'POST',
|
'methods' => 'POST',
|
||||||
'callback' => 'handle_orders_request_FIPF',
|
'callback' => 'handle_orders_request_CIPF',
|
||||||
));
|
));
|
||||||
// https://local_fipfcard_plugin.com/wp-json/fipf_plugin/api/v1/orders/21T129305J264761D/capture
|
|
||||||
register_rest_route($base_rest_route, '/orders/(?P<orderID>[a-zA-Z0-9]+)/capture', array(
|
register_rest_route($base_rest_route, '/orders/(?P<orderID>[a-zA-Z0-9]+)/capture', array(
|
||||||
'methods' => 'POST',
|
'methods' => 'POST',
|
||||||
'callback' => 'handle_orders_capture_request_FIPF',
|
'callback' => 'handle_orders_capture_request_CIPF',
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
add_action('rest_api_init', 'routes_endpoints_FIPF');
|
add_action('rest_api_init', 'routes_endpoints_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ if (!defined('ABSPATH')) {
|
|||||||
/**
|
/**
|
||||||
* call to paypal_shortcode_content()
|
* call to paypal_shortcode_content()
|
||||||
*/
|
*/
|
||||||
function paypal_shortcode_content_FIPF()
|
function paypal_shortcode_content_CIPF()
|
||||||
{
|
{
|
||||||
// if (!can_pay_now_CIPF())
|
// if (!can_pay_now_CIPF())
|
||||||
// return no_payment_CIPF();
|
// return no_payment_CIPF();
|
||||||
$fipfcard_paypal = new PLGNTLS_class();
|
$cipfcard_paypal = new PLGNTLS_class();
|
||||||
|
|
||||||
$pp_client_id = PAYPAL_CLIENT_ID;
|
$pp_client_id = PAYPAL_CLIENT_ID;
|
||||||
$pp_sdk_currency = "EUR";
|
$pp_sdk_currency = "EUR";
|
||||||
@@ -31,7 +31,7 @@ function paypal_shortcode_content_FIPF()
|
|||||||
$paypal_message_success = PAYPAL_MESSAGE_SUCCESS;
|
$paypal_message_success = PAYPAL_MESSAGE_SUCCESS;
|
||||||
$paypal_message_failure = PAYPAL_MESSAGE_FAILURE;
|
$paypal_message_failure = PAYPAL_MESSAGE_FAILURE;
|
||||||
|
|
||||||
$added_to_front = $fipfcard_paypal->add_to_front(
|
$added_to_front = $cipfcard_paypal->add_to_front(
|
||||||
array(
|
array(
|
||||||
$pp_sdk_url,
|
$pp_sdk_url,
|
||||||
array("js/paypal/paypal.js", 'type'=>'module'),
|
array("js/paypal/paypal.js", 'type'=>'module'),
|
||||||
@@ -47,7 +47,7 @@ function paypal_shortcode_content_FIPF()
|
|||||||
|
|
||||||
return $added_to_front;
|
return $added_to_front;
|
||||||
}
|
}
|
||||||
add_shortcode('fipf_paypal_shortcode', 'paypal_shortcode_content_FIPF');
|
add_shortcode('cipf_paypal_shortcode', 'paypal_shortcode_content_CIPF');
|
||||||
|
|
||||||
|
|
||||||
function no_payment_CIPF() {
|
function no_payment_CIPF() {
|
||||||
|
|||||||
@@ -15,17 +15,17 @@ if (!defined('ABSPATH')) {
|
|||||||
* basically it check if the user who initiate the transaction
|
* basically it check if the user who initiate the transaction
|
||||||
* is the same that finish it
|
* is the same that finish it
|
||||||
*
|
*
|
||||||
* add_user_meta('user_id', 'fipf_order_id', 'aaaaaa');
|
* add_user_meta('user_id', 'cipf_order_id', 'aaaaaa');
|
||||||
* ['aaaaaa']
|
* ['aaaaaa']
|
||||||
* add_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
* add_user_meta('user_id', 'cipf_order_id', 'bbbbbb');
|
||||||
* ['aaaaaa', 'bbbbbb']
|
* ['aaaaaa', 'bbbbbb']
|
||||||
* add_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
* add_user_meta('user_id', 'cipf_order_id', 'bbbbbb');
|
||||||
* ['aaaaaa', 'bbbbbb', 'bbbbbb']
|
* ['aaaaaa', 'bbbbbb', 'bbbbbb']
|
||||||
* get_user_meta('user_id', 'fipf_order_id');
|
* get_user_meta('user_id', 'cipf_order_id');
|
||||||
* ['aaaaaa', 'bbbbbb', 'bbbbbb']
|
* ['aaaaaa', 'bbbbbb', 'bbbbbb']
|
||||||
* $del_ret = delete_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
* $del_ret = delete_user_meta('user_id', 'cipf_order_id', 'bbbbbb');
|
||||||
* ['aaaaaa'] - $del_ret === true
|
* ['aaaaaa'] - $del_ret === true
|
||||||
* $del_ret = delete_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
* $del_ret = delete_user_meta('user_id', 'cipf_order_id', 'bbbbbb');
|
||||||
* ['aaaaaa'] - $del_ret === false
|
* ['aaaaaa'] - $del_ret === false
|
||||||
*
|
*
|
||||||
* order status : https://developer.paypal.com/docs/api/orders/v2/#orders_capture!c=201&path=status&t=response
|
* order status : https://developer.paypal.com/docs/api/orders/v2/#orders_capture!c=201&path=status&t=response
|
||||||
@@ -37,16 +37,16 @@ if (!defined('ABSPATH')) {
|
|||||||
* PAYER_ACTION_REQUIRED
|
* PAYER_ACTION_REQUIRED
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function update_user_payment_FIPF($message, $step) {
|
function update_user_payment_CIPF($message, $step) {
|
||||||
$order_id = $message->id;
|
$order_id = $message->id;
|
||||||
$user_id = get_current_user_id();
|
$user_id = get_current_user_id();
|
||||||
$status = $message->status;
|
$status = $message->status;
|
||||||
|
|
||||||
// addind order_id to fipf_order_id meta field
|
// addind order_id to cipf_order_id meta field
|
||||||
// it can duplicate, it's not a problem : delete_user_meta will delete all
|
// it can duplicate, it's not a problem : delete_user_meta will delete all
|
||||||
add_user_meta($user_id, 'fipf_order_id', $order_id);
|
add_user_meta($user_id, 'cipf_order_id', $order_id);
|
||||||
// add a schedule event to delete this order_id
|
// add a schedule event to delete this order_id
|
||||||
schedule_delete_orderid_FIPF($user_id, $order_id);
|
schedule_delete_orderid_CIPF($user_id, $order_id);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* create a meta field to check states of payements on prof author page :
|
* create a meta field to check states of payements on prof author page :
|
||||||
@@ -55,17 +55,17 @@ function update_user_payment_FIPF($message, $step) {
|
|||||||
* - '' -> no message to output | on author page (after set to empty on author page)
|
* - '' -> no message to output | on author page (after set to empty on author page)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
delete_user_meta($user_id, 'fipf_payement_status');
|
delete_user_meta($user_id, 'cipf_payement_status');
|
||||||
add_user_meta($user_id, 'fipf_payement_status', 'started');
|
add_user_meta($user_id, 'cipf_payement_status', 'started');
|
||||||
|
|
||||||
// if transaction is COMPLETED, then delete order_id and update user
|
// if transaction is COMPLETED, then delete order_id and update user
|
||||||
if ($status === 'COMPLETED') {
|
if ($status === 'COMPLETED') {
|
||||||
// find the user containing the order_id and delete this order_id
|
// find the user containing the order_id and delete this order_id
|
||||||
$user_id_to_update = delete_order_id_on_success_FIPF($user_id, $order_id);
|
$user_id_to_update = delete_order_id_on_success_CIPF($user_id, $order_id);
|
||||||
// change payement status to success
|
// change payement status to success
|
||||||
update_user_meta($user_id_to_update, 'fipf_payement_status', 'success');
|
update_user_meta($user_id_to_update, 'cipf_payement_status', 'success');
|
||||||
// proceed to validate payment for user
|
// proceed to validate payment for user
|
||||||
validate_payment_for_user_FIPF($user_id_to_update, $order_id);
|
validate_payment_for_user_CIPF($user_id_to_update, $order_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ function update_user_payment_FIPF($message, $step) {
|
|||||||
* -> https://www.advancedcustomfields.com/resources/date-time-picker/
|
* -> https://www.advancedcustomfields.com/resources/date-time-picker/
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function validate_payment_for_user_FIPF($user_id, $order_id) {
|
function validate_payment_for_user_CIPF($user_id, $order_id) {
|
||||||
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
||||||
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
||||||
$card_duration = PLGNTLS_class::CARD_VALIDITY_TIME;
|
$card_duration = PLGNTLS_class::CARD_VALIDITY_TIME;
|
||||||
@@ -169,21 +169,21 @@ function validate_payment_for_user_FIPF($user_id, $order_id) {
|
|||||||
* -> also strtotime : https://www.php.net/manual/en/function.strtotime.php
|
* -> also strtotime : https://www.php.net/manual/en/function.strtotime.php
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function schedule_delete_orderid_FIPF($user_id, $order_id)
|
function schedule_delete_orderid_CIPF($user_id, $order_id)
|
||||||
{
|
{
|
||||||
$delay = time() + MINUTE_IN_SECONDS;
|
$delay = time() + MINUTE_IN_SECONDS;
|
||||||
wp_schedule_single_event($delay, 'orderid_deletion_event_FIPF', array($user_id, $order_id));
|
wp_schedule_single_event($delay, 'orderid_deletion_event_CIPF', array($user_id, $order_id));
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* action hook for the scheduled event
|
* action hook for the scheduled event
|
||||||
* TODO: ne marche pas je ne sais pas pourquoi, pas urgent a resoudre
|
* TODO: ne marche pas je ne sais pas pourquoi, pas urgent a resoudre
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function delete_order_id_later_FIPF($user_id, $order_id)
|
function delete_order_id_later_CIPF($user_id, $order_id)
|
||||||
{
|
{
|
||||||
delete_user_meta($user_id, 'fipf_order_id', $order_id);
|
delete_user_meta($user_id, 'cipf_order_id', $order_id);
|
||||||
}
|
}
|
||||||
add_action('orderid_deletion_event_FIPF', 'delete_order_id_later_FIPF', 5, 2);
|
add_action('orderid_deletion_event_CIPF', 'delete_order_id_later_CIPF', 5, 2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -195,9 +195,9 @@ add_action('orderid_deletion_event_FIPF', 'delete_order_id_later_FIPF', 5, 2);
|
|||||||
* bool false - if no match found
|
* bool false - if no match found
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function delete_order_id_on_success_FIPF($current_user_id, $order_id)
|
function delete_order_id_on_success_CIPF($current_user_id, $order_id)
|
||||||
{
|
{
|
||||||
$del_ret = delete_user_meta($current_user_id, 'fipf_order_id', $order_id);
|
$del_ret = delete_user_meta($current_user_id, 'cipf_order_id', $order_id);
|
||||||
if ($del_ret === true)
|
if ($del_ret === true)
|
||||||
return $current_user_id;
|
return $current_user_id;
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ function delete_order_id_on_success_FIPF($current_user_id, $order_id)
|
|||||||
foreach ($users as $user)
|
foreach ($users as $user)
|
||||||
{
|
{
|
||||||
$user_id = $user->ID;
|
$user_id = $user->ID;
|
||||||
$del_ret = delete_user_meta($user_id, 'fipf_order_id', $order_id);
|
$del_ret = delete_user_meta($user_id, 'cipf_order_id', $order_id);
|
||||||
if ($del_ret === true)
|
if ($del_ret === true)
|
||||||
return $user_id;
|
return $user_id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,13 +45,13 @@ function handle_prof_is_activ_CIPF($author_id) {
|
|||||||
*/
|
*/
|
||||||
$redirection_prof_inactiv = home_url() . '/' . $slug_wait_activation;
|
$redirection_prof_inactiv = home_url() . '/' . $slug_wait_activation;
|
||||||
|
|
||||||
wp_redirect($redirection_prof_inactiv);
|
wp_redirect($redirection_prof_inactiv, 301);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check meta field 'fipf_payement_status'
|
* check meta field 'cipf_payement_status'
|
||||||
* if field value is 'success'
|
* if field value is 'success'
|
||||||
* - hide block 'failure'
|
* - hide block 'failure'
|
||||||
* - and update field to '', so it will not show next time
|
* - and update field to '', so it will not show next time
|
||||||
@@ -62,9 +62,9 @@ function handle_prof_is_activ_CIPF($author_id) {
|
|||||||
* if field value is ''
|
* if field value is ''
|
||||||
* - hide both 'success' and 'failure' blocs
|
* - hide both 'success' and 'failure' blocs
|
||||||
*
|
*
|
||||||
* .fipf_prof_paiement_message -> on row, added display none in page css
|
* .cipf_prof_paiement_message -> on row, added display none in page css
|
||||||
* #fipf_prof_paiement_reussi -> on row
|
* #cipf_prof_paiement_reussi -> on row
|
||||||
* #fipf_prof_paiement_echoue -> on row
|
* #cipf_prof_paiement_echoue -> on row
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function show_prof_paiement_messages_CIPF($user_id) {
|
function show_prof_paiement_messages_CIPF($user_id) {
|
||||||
@@ -80,22 +80,22 @@ function show_prof_paiement_messages_CIPF($user_id) {
|
|||||||
if ($is_activ === 'Inactif')
|
if ($is_activ === 'Inactif')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$fipf_prof_payement = new PLGNTLS_class();
|
$cipf_prof_payement = new PLGNTLS_class();
|
||||||
|
|
||||||
$payement_status2 = get_user_meta($user_id, 'fipf_payement_status');
|
$payement_status2 = get_user_meta($user_id, 'cipf_payement_status');
|
||||||
$payement_status = get_user_meta($user_id, 'fipf_payement_status', true);
|
$payement_status = get_user_meta($user_id, 'cipf_payement_status', true);
|
||||||
if ($payement_status === 'success') {
|
if ($payement_status === 'success') {
|
||||||
$fipf_prof_payement->add_to_front(array(
|
$cipf_prof_payement->add_to_front(array(
|
||||||
array( 'css' => '#fipf_prof_paiement_reussi {display: block;}' )
|
array( 'css' => '#cipf_prof_paiement_reussi {display: block;}' )
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
else if ($payement_status === 'started') {
|
else if ($payement_status === 'started') {
|
||||||
$fipf_prof_payement->add_to_front(array(
|
$cipf_prof_payement->add_to_front(array(
|
||||||
array( 'css' => '#fipf_prof_paiement_echoue {display: block;}' )
|
array( 'css' => '#cipf_prof_paiement_echoue {display: block;}' )
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
update_user_meta($user_id, 'fipf_payement_status', '');
|
update_user_meta($user_id, 'cipf_payement_status', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
78
plugins/fipfcard_plugin/php/renew_card.php
Normal file
78
plugins/fipfcard_plugin/php/renew_card.php
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prevent users to fill the renew form if
|
||||||
|
* they are not prof and logged in,
|
||||||
|
* and if there card is not in renewable state
|
||||||
|
* except admins and editor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function renew_page_restrictions_CIPF(){
|
||||||
|
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||||
|
if (!is_page($slug_renew_card))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!is_user_logged_in()) {
|
||||||
|
wp_redirect($base_url, 301);
|
||||||
|
}
|
||||||
|
|
||||||
|
$base_url = home_url();
|
||||||
|
$current_user_id = get_current_user_id();
|
||||||
|
/*
|
||||||
|
if (current_user_can('professeur__professeure')) {
|
||||||
|
$user_page = get_author_posts_url($current_user_id);
|
||||||
|
wp_redirect($user_page, 301);
|
||||||
|
}
|
||||||
|
else if (current_user_can('partenaire')) {
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'post',
|
||||||
|
'author' => $current_user_id,
|
||||||
|
'posts_per_page' => 1,
|
||||||
|
);
|
||||||
|
$posts = get_posts($args);
|
||||||
|
if (empty($posts))
|
||||||
|
$redirect_url = $base_url;
|
||||||
|
else {
|
||||||
|
$query = reset($posts);
|
||||||
|
$post_id = $query->ID;
|
||||||
|
$redirect_url = get_permalink($query->ID);
|
||||||
|
}
|
||||||
|
wp_redirect($redirect_url, 301);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
add_action('template_redirect', 'renew_page_restrictions_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function renew_page_filter_message_CIPF(){
|
||||||
|
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||||
|
if (!is_page($slug_renew_card))
|
||||||
|
return;
|
||||||
|
|
||||||
|
$cipf_renew = new PLGNTLS_class();
|
||||||
|
$cipf_prof_payement->add_to_front(array(
|
||||||
|
array( 'css' => '#cipf_prof_paiement_reussi {display: block;}' )
|
||||||
|
));
|
||||||
|
}
|
||||||
|
add_action('wp_enqueue_scripts', 'renew_page_filter_message_CIPF');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -15,7 +15,7 @@ if (!defined('ABSPATH')) {
|
|||||||
/* switch console_log
|
/* switch console_log
|
||||||
const CONSOLE_OFF = true;
|
const CONSOLE_OFF = true;
|
||||||
*/
|
*/
|
||||||
const FIPFCARD_CONSOLE_OFF = false;
|
const CIPF_CONSOLE_OFF = false;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ if (!defined('ABSPATH')) {
|
|||||||
https://stackify.com/how-to-log-to-console-in-php/
|
https://stackify.com/how-to-log-to-console-in-php/
|
||||||
*/
|
*/
|
||||||
function console_log(...$outputs) {
|
function console_log(...$outputs) {
|
||||||
if (FIPFCARD_CONSOLE_OFF)
|
if (CIPF_CONSOLE_OFF)
|
||||||
return;
|
return;
|
||||||
foreach($outputs as $output)
|
foreach($outputs as $output)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ class PLGNTLS_class
|
|||||||
const CARD_VALIDITY_TIME = '1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days')
|
const CARD_VALIDITY_TIME = '1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days')
|
||||||
|
|
||||||
CONST SLUG_PROF_INACTIV = 'validation-en-cours';
|
CONST SLUG_PROF_INACTIV = 'validation-en-cours';
|
||||||
|
CONST SLUG_RENEW_CARD = 'commande';
|
||||||
|
|
||||||
CONST USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php)
|
CONST USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user