- added debug function
- fixed issues in acf fields use
This commit is contained in:
@@ -20,6 +20,7 @@ if (!defined('ABSPATH')) {
|
||||
*
|
||||
*/
|
||||
function handle_orders_request_CIPF($request_data) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
|
||||
// declaring outside the try..catch scope
|
||||
$order_response = array();
|
||||
@@ -96,8 +97,8 @@ function handle_orders_request_CIPF($request_data) {
|
||||
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_create
|
||||
*
|
||||
*/
|
||||
function create_order_CIPF()
|
||||
{
|
||||
function create_order_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL;
|
||||
|
||||
$access_token = generate_access_token_CIPF();
|
||||
|
||||
@@ -11,6 +11,7 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
|
||||
function handle_orders_capture_request_CIPF($request) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$order_id = $request['orderID'];
|
||||
// declaring outside the try..catch scope
|
||||
$response_json = array();
|
||||
@@ -74,6 +75,7 @@ function handle_orders_capture_request_CIPF($request) {
|
||||
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
||||
*/
|
||||
function capture_order_CIPF($order_id) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL;
|
||||
$access_token = generate_access_token_CIPF();
|
||||
$url = $paypal_api_base_url . '/v2/checkout/orders/' . $order_id . '/capture';
|
||||
|
||||
@@ -14,6 +14,7 @@ if (!defined('ABSPATH')) {
|
||||
*
|
||||
*/
|
||||
function handle_json_response_CIPF($response, $ch) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
if ($response === false)
|
||||
throw new HttpException('cURL error: ' . curl_error($ch), 502);
|
||||
|
||||
@@ -32,6 +33,7 @@ function handle_json_response_CIPF($response, $ch) {
|
||||
);
|
||||
}
|
||||
function handle_response_CIPF($response) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
try
|
||||
{
|
||||
// Decode JSON response
|
||||
@@ -57,8 +59,8 @@ function handle_response_CIPF($response) {
|
||||
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||
* @see https://developer.paypal.com/api/rest/authentication/
|
||||
*/
|
||||
function generate_access_token_CIPF()
|
||||
{
|
||||
function generate_access_token_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$paypal_client_id = PLGNTLS_class::PAYPAL_CLIENT_ID;
|
||||
$paypal_client_secret = PLGNTLS_class::PAYPAL_CLIENT_SECRET;
|
||||
$paypal_api_base_url = PLGNTLS_class::PAYPAL_API_BASE_URL;
|
||||
|
||||
@@ -11,8 +11,8 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
// handling routes and endpoints
|
||||
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
|
||||
function routes_endpoints_CIPF()
|
||||
{
|
||||
function routes_endpoints_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$base_rest_route = "cipf_plugin/api/v1";
|
||||
register_rest_route($base_rest_route, '/orders', array(
|
||||
'methods' => 'POST',
|
||||
|
||||
@@ -15,8 +15,8 @@ if (!defined('ABSPATH')) {
|
||||
/**
|
||||
* call to paypal_shortcode_content()
|
||||
*/
|
||||
function paypal_shortcode_content_CIPF()
|
||||
{
|
||||
function paypal_shortcode_content_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$slug_paypal_redirection_success = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_SUCCESS;
|
||||
$slug_paypal_redirection_failure = PLGNTLS_class::SLUG_PAYPAL_REDIRECTION_FAILURE;
|
||||
$paypal_client_id = PLGNTLS_class::PAYPAL_CLIENT_ID;
|
||||
@@ -55,6 +55,7 @@ add_shortcode('cipf_paypal_shortcode', 'paypal_shortcode_content_CIPF');
|
||||
|
||||
|
||||
function no_payment_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,9 @@ if (!defined('ABSPATH')) {
|
||||
*
|
||||
*/
|
||||
function update_user_pre_order_CIPF($message) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$meta_payement_status = PLGNTLS_class::META_PAYEMENT_STATUS;
|
||||
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
||||
|
||||
$order_id = $message->id;
|
||||
$user_id = get_current_user_id();
|
||||
@@ -46,8 +48,8 @@ function update_user_pre_order_CIPF($message) {
|
||||
* - addind order_id to cipf_order_id meta field
|
||||
*
|
||||
*/
|
||||
delete_user_meta($user_id, 'cipf_order_id');
|
||||
add_user_meta($user_id, 'cipf_order_id', $order_id);
|
||||
delete_user_meta($user_id, $meta_order_id);
|
||||
add_user_meta($user_id, $meta_order_id, $order_id);
|
||||
|
||||
/*
|
||||
* create a meta field to check states of payements on prof author page :
|
||||
@@ -69,6 +71,7 @@ function update_user_pre_order_CIPF($message) {
|
||||
*
|
||||
*/
|
||||
function update_user_post_capture_CIPF($message) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$meta_payement_status = PLGNTLS_class::META_PAYEMENT_STATUS;
|
||||
|
||||
$order_id = $message->id;
|
||||
@@ -94,7 +97,10 @@ function update_user_post_capture_CIPF($message) {
|
||||
*
|
||||
*/
|
||||
// find the user containing the order_id and delete this order_id
|
||||
find_user_with_order_id_CIPF($user_id, $order_id);
|
||||
$user_id_to_update = delete_order_id_on_success_CIPF($user_id, $order_id);
|
||||
if ($user_id_to_update === false)
|
||||
return;
|
||||
if ($status === 'COMPLETED') {
|
||||
// proceed to validate payment for user
|
||||
validate_payment_for_user_CIPF($user_id_to_update, $order_id);
|
||||
@@ -111,6 +117,7 @@ function update_user_post_capture_CIPF($message) {
|
||||
*
|
||||
*/
|
||||
function failure_payment_for_user_CIPF($user_id, $order_id) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
}
|
||||
|
||||
|
||||
@@ -119,6 +126,7 @@ function failure_payment_for_user_CIPF($user_id, $order_id) {
|
||||
*
|
||||
*/
|
||||
function validate_payment_for_user_CIPF($user_id, $order_id) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
||||
$acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION;
|
||||
$acf_prof_can_renew = PLGNTLS_class::ACF_PROF_CAN_RENEW;
|
||||
@@ -234,19 +242,61 @@ add_action('orderid_deletion_event_CIPF', 'delete_order_id_later_CIPF', 5, 2);
|
||||
* bool false - if no match found
|
||||
*
|
||||
*/
|
||||
function delete_order_id_on_success_CIPF($current_user_id, $order_id)
|
||||
{
|
||||
$del_ret = delete_user_meta($current_user_id, 'cipf_order_id', $order_id);
|
||||
function find_user_with_order_id_CIPF($current_user_id, $order_id) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
||||
$role_prof = PLGNTLS_class::ROLE_PROF;
|
||||
|
||||
$user_metas = get_user_meta($current_user_id, $meta_order_id, false);
|
||||
if (in_array($order_id, $user_metas)) {
|
||||
return $current_user_id;
|
||||
}
|
||||
|
||||
// it means the current user didn't have this order_id
|
||||
// so we look for another user
|
||||
// $users = get_users();
|
||||
// foreach ($users as $user) {
|
||||
// $user_id = $user->ID;
|
||||
// $del_ret = delete_user_meta($user_id, $meta_order_id, $order_id);
|
||||
// if ($del_ret === true)
|
||||
// return $user_id;
|
||||
// }
|
||||
|
||||
// https://developer.wordpress.org/reference/classes/WP_User_Query/prepare_query/
|
||||
$users = get_users(array(
|
||||
'role' => $role_prof,
|
||||
'meta_key' => $meta_order_id,
|
||||
'meta_value' => $order_id,
|
||||
'fields' => 'ID',
|
||||
));
|
||||
if (count($users) > 1)
|
||||
throw new HttpException('multiple users with same order_id', 502);
|
||||
else if (count($users) === 1)
|
||||
return reset($users);
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @return mixed num - user_id
|
||||
* bool false - if no match found
|
||||
*
|
||||
*/
|
||||
function delete_order_id_on_success_CIPF($current_user_id, $order_id) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$meta_order_id = PLGNTLS_class::META_ORDER_ID;
|
||||
|
||||
$del_ret = delete_user_meta($current_user_id, $meta_order_id, $order_id);
|
||||
if ($del_ret === true)
|
||||
return $current_user_id;
|
||||
|
||||
// it means the current user didn't have this order_id
|
||||
// so we look for another user
|
||||
$users = get_users();
|
||||
foreach ($users as $user)
|
||||
{
|
||||
foreach ($users as $user) {
|
||||
$user_id = $user->ID;
|
||||
$del_ret = delete_user_meta($user_id, 'cipf_order_id', $order_id);
|
||||
$del_ret = delete_user_meta($user_id, $meta_order_id, $order_id);
|
||||
if ($del_ret === true)
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +17,7 @@
|
||||
*
|
||||
*/
|
||||
function check_can_pay_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_payment_method = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
||||
$acf_card_price_choice = PLGNTLS_class::ACF_CARD_PRICE_CHOICE;
|
||||
$acf_card_price_delivery = PLGNTLS_class::ACF_CARD_PRICE_DELIVERY;
|
||||
@@ -38,13 +47,13 @@ function check_can_pay_CIPF() {
|
||||
$tarif = (int)get_field($acf_card_price_choice['_name'], $acf_id);
|
||||
$livraison = (int)get_field($acf_card_price_delivery['_name'], $acf_id);
|
||||
$price = $tarif + $livraison;
|
||||
update_field($acf_card_price_total, $price, $acf_id);
|
||||
update_field($acf_card_price_total['_name'], $price, $acf_id);
|
||||
|
||||
/*
|
||||
* price is not empty or 0
|
||||
*
|
||||
*/
|
||||
$price = get_field($acf_card_price_total, $acf_id);
|
||||
$price = get_field($acf_card_price_total['_name'], $acf_id);
|
||||
if (empty($price)) {
|
||||
return WP_Error('cannot_purchase', "no price selected");
|
||||
}
|
||||
@@ -52,6 +61,7 @@ function check_can_pay_CIPF() {
|
||||
return WP_Error('cannot_purchase', "price is 0, nothing to purchase");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* date validity is empty
|
||||
* or is paste
|
||||
|
||||
Reference in New Issue
Block a user