- wip payment
- already solved success and failure messages and redirection - solved increase date multiple times - users redirection works if error AND partner to posts instead of project
This commit is contained in:
@@ -1,24 +1,2 @@
|
||||
<h1>old button :</h1>
|
||||
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
|
||||
<input type="hidden" name="cmd" value="_s-xclick" />
|
||||
<input type="hidden" name="hosted_button_id" value="H876N9DGSCLKS" />
|
||||
<input type="hidden" name="currency_code" value="EUR" />
|
||||
<input type="image" src="https://www.paypalobjects.com/fr_XC/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" title="PayPal, votre réflexe sécurité pour payer en ligne." alt="Acheter" />
|
||||
</form>
|
||||
<h1>new button :</h1>
|
||||
<div id="paypal-button-container"></div>
|
||||
<!--
|
||||
custom card fields
|
||||
@see https://developer.paypal.com/docs/checkout/advanced/integrate#link-addpaypalbuttonsandcardfields
|
||||
|
||||
<div id="card-name-field-container"></div>
|
||||
<div id="checkout-form">
|
||||
<div id="card-number-field-container"></div>
|
||||
<div id="card-expiry-field-container"></div>
|
||||
<div id="card-cvv-field-container"></div>
|
||||
<button id="card-field-submit-button" type="button">
|
||||
Pay now with Card
|
||||
</button>
|
||||
</div>
|
||||
-->
|
||||
<p id="result-message"></p>
|
||||
|
||||
@@ -37,25 +37,30 @@ export async function onApprove(data, actions) {
|
||||
} else if (!orderData.purchase_units) {
|
||||
throw new Error(JSON.stringify(orderData));
|
||||
} else {
|
||||
// (3) Successful transaction -> Show confirmation or thank you message
|
||||
// Or go to another URL: actions.redirect('thank_you.html');
|
||||
const transaction =
|
||||
orderData?.purchase_units?.[0]?.payments?.captures?.[0] ||
|
||||
orderData?.purchase_units?.[0]?.payments?.authorizations?.[0];
|
||||
// to show a message on page
|
||||
//resultMessage(`Transaction ${transaction.status}: ${transaction.id}<br><br>See console for all available details`,);
|
||||
console.log(
|
||||
"Capture result",
|
||||
orderData,
|
||||
JSON.stringify(orderData, null, 2),
|
||||
);
|
||||
actions.redirect('https://local_fipfcard_plugin.com/');
|
||||
try {
|
||||
// (3) Successful transaction -> Show confirmation or thank you message
|
||||
// Or go to another URL: actions.redirect('thank_you.html');
|
||||
const transaction =
|
||||
orderData?.purchase_units?.[0]?.payments?.captures?.[0] ||
|
||||
orderData?.purchase_units?.[0]?.payments?.authorizations?.[0];
|
||||
// to show a message on page
|
||||
//resultMessage(`Transaction ${transaction.status}: ${transaction.id}<br><br>See console for all available details`);
|
||||
resultMessage(eval(PLGNTLS_data.paypal_message_success));
|
||||
console.log(
|
||||
"Capture result",
|
||||
orderData,
|
||||
JSON.stringify(orderData, null, 2),
|
||||
);
|
||||
actions.redirect(PLGNTLS_data.paypal_redirection_success);
|
||||
} catch (error) {
|
||||
console.error("payment ok but error on traitment afterwards : ", error);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
resultMessage(
|
||||
`Sorry, your transaction could not be processed...<br><br>${error}`,
|
||||
);
|
||||
//resultMessage(`Sorry, your transaction could not be processed...<br><br>${error}`);
|
||||
resultMessage(eval(PLGNTLS_data.paypal_message_failure));
|
||||
actions.redirect(PLGNTLS_data.paypal_redirection_failure);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// Example function to show a result to the user. Your site's UI library can be used instead.
|
||||
//function resultMessage(message) {
|
||||
export function resultMessage(message) {
|
||||
const buttons = document.querySelector("#paypal-button-container");
|
||||
const container = document.querySelector("#result-message");
|
||||
buttons.style.display = 'none';
|
||||
container.innerHTML = message;
|
||||
}
|
||||
|
||||
@@ -42,36 +42,36 @@ add_action('template_redirect', 'check_paypal_request');
|
||||
/**
|
||||
* call to paypal_shortcode_content()
|
||||
*/
|
||||
function fipf_paypal_shortcode_content()
|
||||
function paypal_shortcode_content_FIPF()
|
||||
{
|
||||
$fipfcard_paypal = new PLGNTLS_class();
|
||||
|
||||
$pp_sdk_currency = "EUR";
|
||||
$pp_sdk_debug = "true";
|
||||
$pp_sdk_base_url="https://sandbox.paypal.com";
|
||||
$pp_sdk_base_url="https://www.paypal.com";
|
||||
// $pp_sdk_client_token="abc123xyz==";
|
||||
$pp_sdk_src="$pp_sdk_base_url/sdk/js?client-id=" . PAYPAL_CLIENT_ID . "¤cy=$pp_sdk_currency&debug=$pp_sdk_debug";
|
||||
$pp_sdk_src="$pp_sdk_base_url/sdk/js?client-id=" . PAYPAL_CLIENT_ID ;
|
||||
// $pp_sdk_attributes="src='$pp_sdk_src' data-client-token='$pp_sdk_client_token'";
|
||||
// $pp_sdk_attributes="src='$pp_sdk_src'";
|
||||
// $pp_sdk_html_script="<script $pp_sdk_attributes></script>";
|
||||
$pp_sdk_base_url = "https://www.paypal.com";
|
||||
$pp_sdk_url = "$pp_sdk_base_url/sdk/js?client-id=" . PAYPAL_CLIENT_ID . "¤cy=$pp_sdk_currency";
|
||||
|
||||
$paypal_redirection_success = PAYPAL_REDIRECTION_SUCCESS;
|
||||
$paypal_redirection_failure = PAYPAL_REDIRECTION_FAILURE;
|
||||
$paypal_message_success = PAYPAL_MESSAGE_SUCCESS;
|
||||
$paypal_message_failure = PAYPAL_MESSAGE_FAILURE;
|
||||
|
||||
$added_to_front = $fipfcard_paypal->add_to_front(
|
||||
array(
|
||||
$pp_sdk_src,
|
||||
// 'js/paypal/result_message.js',
|
||||
// 'js/paypal/create_order.js',
|
||||
// 'js/paypal/on_approve.js',
|
||||
//"js/paypal/paypal.js",
|
||||
$pp_sdk_url,
|
||||
array("js/paypal/paypal.js", 'type'=>'module'),
|
||||
"html/paypal/paypal.html",
|
||||
),
|
||||
compact (
|
||||
'paypal_redirection_success',
|
||||
'paypal_redirection_failure',
|
||||
'paypal_message_success',
|
||||
'paypal_message_failure',
|
||||
),
|
||||
);
|
||||
|
||||
return $added_to_front;
|
||||
}
|
||||
add_shortcode('fipf_paypal_shortcode', 'fipf_paypal_shortcode_content');
|
||||
add_shortcode('fipf_paypal_shortcode', 'paypal_shortcode_content_FIPF');
|
||||
|
||||
|
||||
|
||||
@@ -79,32 +79,32 @@ add_shortcode('fipf_paypal_shortcode', 'fipf_paypal_shortcode_content');
|
||||
/**
|
||||
* the js file paypal.js needs to be imported as a module to use import
|
||||
* @see https://developer.wordpress.org/reference/hooks/script_loader_tag/
|
||||
function fipf_add_id_to_script( $tag, $handle, $src ) {
|
||||
function add_id_to_script_FIPF( $tag, $handle, $src ) {
|
||||
if ( $handle === 'PLGNTLS_paypal_js' ) {
|
||||
$tag = '<script type="module" src="' . esc_url( $src ) . '" ></script>';
|
||||
}
|
||||
return $tag;
|
||||
}
|
||||
add_filter( 'script_loader_tag', 'fipf_add_id_to_script', 10, 3 );
|
||||
add_filter( 'script_loader_tag', 'add_id_to_script_FIPF', 10, 3 );
|
||||
*/
|
||||
|
||||
|
||||
// handling routes and endpoints
|
||||
// diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573
|
||||
function fipf_routes_endpoints()
|
||||
function routes_endpoints_FIPF()
|
||||
{
|
||||
$base_rest_route = "fipf_plugin/api/v1";
|
||||
register_rest_route($base_rest_route, '/orders', array(
|
||||
'methods' => 'POST',
|
||||
'callback' => 'fipf_handle_orders_request',
|
||||
'callback' => 'handle_orders_request_FIPF',
|
||||
));
|
||||
// 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(
|
||||
'methods' => 'POST',
|
||||
'callback' => 'fipf_handle_orders_capture_request',
|
||||
'callback' => 'handle_orders_capture_request_FIPF',
|
||||
));
|
||||
};
|
||||
add_action('rest_api_init', 'fipf_routes_endpoints');
|
||||
add_action('rest_api_init', 'routes_endpoints_FIPF');
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -15,17 +15,17 @@ include_once(PLGNTLS_class::get_path() . '/php/paypal/update_user_payment.php');
|
||||
/**
|
||||
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||
*/
|
||||
function fipf_handle_orders_request($request_data) {
|
||||
function handle_orders_request_FIPF($request_data) {
|
||||
try {
|
||||
// Extract cart information from request body
|
||||
$cart = $request_data['cart'];
|
||||
|
||||
// Process the order and get the response
|
||||
$order_response = fipf_create_order($cart);
|
||||
$order_response = create_order_FIPF($cart);
|
||||
$json_response = $order_response['json_response'];
|
||||
$http_status_code = $order_response['http_status_code'];
|
||||
|
||||
fipf_update_user_payment($json_response, 'start');
|
||||
update_user_payment_FIPF($json_response, 'start');
|
||||
|
||||
// Return response
|
||||
return new WP_REST_Response($json_response, $http_status_code);
|
||||
@@ -43,11 +43,11 @@ function fipf_handle_orders_request($request_data) {
|
||||
* Create an order to start the transaction.
|
||||
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_create
|
||||
*/
|
||||
function fipf_create_order( $cart )
|
||||
function create_order_FIPF( $cart )
|
||||
{
|
||||
// use the cart information passed from the front-end to calculate the purchase unit details
|
||||
|
||||
$access_token = fipf_generate_access_token();
|
||||
$access_token = generate_access_token_FIPF();
|
||||
|
||||
$url = PAYPAL_API_BASE_URL . '/v2/checkout/orders';
|
||||
$payload = array(
|
||||
@@ -55,8 +55,8 @@ function fipf_create_order( $cart )
|
||||
'purchase_units' => array(
|
||||
array(
|
||||
'amount' => array(
|
||||
'currency_code' => "USD",
|
||||
'value' => "100.00",
|
||||
'currency_code' => "EUR",
|
||||
'value' => "1.00",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -89,7 +89,7 @@ function fipf_create_order( $cart )
|
||||
curl_close($ch);
|
||||
|
||||
// in utils
|
||||
return fipf_handle_response($response);
|
||||
return handle_response_FIPF($response);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -11,18 +11,18 @@ if (!defined('ABSPATH')) {
|
||||
include_once(PLGNTLS_class::get_path() . '/php/paypal/route_api_utils.php');
|
||||
include_once(PLGNTLS_class::get_path() . '/php/paypal/update_user_payment.php');
|
||||
|
||||
function fipf_handle_orders_capture_request($request) {
|
||||
function handle_orders_capture_request_FIPF($request) {
|
||||
$order_id = $request['orderID'];
|
||||
|
||||
try {
|
||||
// Implement captureOrder function logic here
|
||||
// Make sure you implement captureOrder function similar to the Node.js code
|
||||
|
||||
$response_data = fipf_capture_order($order_id);
|
||||
$response_data = capture_order_FIPF($order_id);
|
||||
$http_status_code = $response_data['http_status_code'];
|
||||
$json_response = $response_data['json_response'];
|
||||
|
||||
fipf_update_user_payment($json_response, 'end');
|
||||
update_user_payment_FIPF($json_response, 'end');
|
||||
|
||||
return new WP_REST_Response($json_response, $http_status_code);
|
||||
}
|
||||
@@ -37,8 +37,8 @@ function fipf_handle_orders_capture_request($request) {
|
||||
* Capture payment for the created order to complete the transaction.
|
||||
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
||||
*/
|
||||
function fipf_capture_order($orderID) {
|
||||
$access_token = fipf_generate_access_token();
|
||||
function capture_order_FIPF($orderID) {
|
||||
$access_token = generate_access_token_FIPF();
|
||||
$url = PAYPAL_API_BASE_URL . '/v2/checkout/orders/' . $orderID . '/capture';
|
||||
|
||||
$headers = array(
|
||||
@@ -67,7 +67,7 @@ function fipf_capture_order($orderID) {
|
||||
curl_close($ch);
|
||||
|
||||
// in utils
|
||||
return fipf_handle_response($response);
|
||||
return handle_response_FIPF($response);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ if (!defined('ABSPATH')) {
|
||||
/**
|
||||
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||
*/
|
||||
function fipf_handle_response($response) {
|
||||
function handle_response_FIPF($response) {
|
||||
try
|
||||
{
|
||||
// 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/api/rest/authentication/
|
||||
*/
|
||||
function fipf_generate_access_token()
|
||||
function generate_access_token_FIPF()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* it means someone outside wp is accessing the file, in this case kill it.
|
||||
*/
|
||||
/*
|
||||
* it means someone outside wp is accessing the file, in this case kill it.
|
||||
*/
|
||||
if (!defined('ABSPATH')) {
|
||||
die('You can not access this file!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* see documentation in private 'paypal.md'
|
||||
* basically it check if the user who initiate the transaction
|
||||
* is the same that finish it
|
||||
*
|
||||
* add_user_meta('user_id', 'fipf_order_id', 'aaaaaa');
|
||||
* ['aaaaaa']
|
||||
* add_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
||||
* ['aaaaaa', 'bbbbbb']
|
||||
* add_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
||||
* ['aaaaaa', 'bbbbbb', 'bbbbbb']
|
||||
* get_user_meta('user_id', 'fipf_order_id');
|
||||
* ['aaaaaa', 'bbbbbb', 'bbbbbb']
|
||||
* $del_ret = delete_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
||||
* ['aaaaaa'] - $del_ret === true
|
||||
* $del_ret = delete_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
||||
* ['aaaaaa'] - $del_ret === false
|
||||
*
|
||||
*/
|
||||
function fipf_update_user_payment($message, $step)
|
||||
/*
|
||||
* see documentation in private 'paypal.md'
|
||||
* basically it check if the user who initiate the transaction
|
||||
* is the same that finish it
|
||||
*
|
||||
* add_user_meta('user_id', 'fipf_order_id', 'aaaaaa');
|
||||
* ['aaaaaa']
|
||||
* add_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
||||
* ['aaaaaa', 'bbbbbb']
|
||||
* add_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
||||
* ['aaaaaa', 'bbbbbb', 'bbbbbb']
|
||||
* get_user_meta('user_id', 'fipf_order_id');
|
||||
* ['aaaaaa', 'bbbbbb', 'bbbbbb']
|
||||
* $del_ret = delete_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
||||
* ['aaaaaa'] - $del_ret === true
|
||||
* $del_ret = delete_user_meta('user_id', 'fipf_order_id', 'bbbbbb');
|
||||
* ['aaaaaa'] - $del_ret === false
|
||||
*
|
||||
*/
|
||||
function update_user_payment_FIPF($message, $step)
|
||||
{
|
||||
|
||||
$order_id = $message->id;
|
||||
@@ -64,16 +64,14 @@ function fipf_update_user_payment($message, $step)
|
||||
// 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 a schedule event to delete this order_id
|
||||
fipf_schedule_delete_orderid($user_id, $order_id);
|
||||
fipf_validate_payment_for_user($user_id, $order_id);
|
||||
schedule_delete_orderid_FIPF($user_id, $order_id);
|
||||
|
||||
// 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
|
||||
$user_id_to_update = fipf_delete_order_id_on_success($user_id, $order_id);
|
||||
$user_id_to_update = delete_order_id_on_success_FIPF($user_id, $order_id);
|
||||
// proceed to validate payment for user
|
||||
fipf_validate_payment_for_user($user_id_to_update, $order_id);
|
||||
validate_payment_for_user_FIPF($user_id_to_update, $order_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,56 +86,65 @@ function fipf_update_user_payment($message, $step)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* change acf field [carte_est_valide](validite) to true
|
||||
* change acf field [date_d_achat](achat) to new current date
|
||||
* change acf field [date_fin_validite](echance) to previous date + 1 year
|
||||
*
|
||||
* create scheduled emails to inform of end of validity
|
||||
*
|
||||
* acf uses 'Y-m-d H:i:s' format :
|
||||
* -> https://www.advancedcustomfields.com/resources/date-time-picker/
|
||||
*/
|
||||
function fipf_validate_payment_for_user($user_id, $order_id)
|
||||
{
|
||||
/*
|
||||
*
|
||||
* const CARD_IS_VALID : acf field 'true false' [carte_est_valide](validite)
|
||||
* const CARD_DATE_PURCHASE : acf field 'date picker' [date_d_achat](achat)
|
||||
* const CARD_DATE_VALIDITY : acf field 'date picker' [date_fin_validite](echance)
|
||||
*
|
||||
* - change CARD_IS_VALID to true
|
||||
* - change CARD_DATE_PURCHASE to now
|
||||
* - change CARD_DATE_VALIDITY to previous value + 1 year
|
||||
*
|
||||
* - create scheduled emails to inform of end of validity
|
||||
*
|
||||
* acf uses 'Y-m-d H:i:s' format :
|
||||
* -> https://www.advancedcustomfields.com/resources/date-time-picker/
|
||||
*/
|
||||
function validate_payment_for_user_FIPF($user_id, $order_id) {
|
||||
$acf_date_format = 'Y-m-d H:i:s';
|
||||
|
||||
/**
|
||||
* update card validity to true
|
||||
*/
|
||||
/*
|
||||
* update card validity to true
|
||||
*/
|
||||
$post_id = 'user_'.$user_id;
|
||||
update_field('carte_est_valide', true, $post_id);
|
||||
update_field(CARD_IS_VALID, true, $post_id);
|
||||
|
||||
/**
|
||||
* update purchase date to now
|
||||
*/
|
||||
/*
|
||||
* update purchase date to now
|
||||
*/
|
||||
$date_now = date($acf_date_format);
|
||||
update_field('date_d_achat', $date_now, $post_id);
|
||||
update_field(CARD_DATE_PURCHASE, $date_now, $post_id);
|
||||
|
||||
/**
|
||||
* update date limit validity to add 1 year
|
||||
*/
|
||||
$current_date_limit = get_field('date_fin_validite', $post_id);
|
||||
/*
|
||||
* get current date limit
|
||||
* if no date, use now
|
||||
* if paste date, use now
|
||||
*/
|
||||
$current_date_limit = get_field(CARD_DATE_VALIDITY, $post_id);
|
||||
// output is in format 'dd/mm/yyyy' which is not understood by php dates functions
|
||||
// so i clean it
|
||||
// -> not a reliable solution, someone can change the ouput format in dashboard
|
||||
$current_date_limit = str_replace('/', '-', $current_date_limit);
|
||||
// id current date limit is not in the futur, use now date
|
||||
if ($current_date_limit === null)
|
||||
|
||||
if ($current_date_limit === null) {
|
||||
$current_date_limit = $date_now;
|
||||
}
|
||||
else
|
||||
{
|
||||
// compare 2 dates : https://stackoverflow.com/q/8722806/9497573
|
||||
// also I dont use strtotime to compare 2 ints,
|
||||
// because i don't know if it will fail one day (2000 bug like)
|
||||
// because i don't know if it will fail one day (2000 bug alike)
|
||||
$comp_current_date_limit = date_create($current_date_limit);
|
||||
$comp_date_now = date_create($date_now);
|
||||
$date_is_in_past = date_diff($comp_date_now, $comp_current_date_limit)->format("%R%a") < 0;
|
||||
if ($date_is_in_past)
|
||||
$current_date_limit = $date_now;
|
||||
}
|
||||
// add one year to current date limit
|
||||
|
||||
/*
|
||||
* update date limit validity to add 1 year
|
||||
*/
|
||||
$time_plus_one_year = strtotime('+1 year', strtotime($current_date_limit));
|
||||
$new_date_limit = date('Y-m-d H:i:s', $time_plus_one_year);
|
||||
update_field('date_fin_validite', $new_date_limit, $post_id);
|
||||
@@ -158,21 +165,21 @@ function fipf_validate_payment_for_user($user_id, $order_id)
|
||||
* -> https://codex.wordpress.org/Easier_Expression_of_Time_Constants
|
||||
* -> also strtotime : https://www.php.net/manual/en/function.strtotime.php
|
||||
*/
|
||||
function fipf_schedule_delete_orderid($user_id, $order_id)
|
||||
function schedule_delete_orderid_FIPF($user_id, $order_id)
|
||||
{
|
||||
$delay = time() + MINUTE_IN_SECONDS;
|
||||
wp_schedule_single_event($delay, 'fipf_orderid_deletion_event', array($user_id, $order_id));
|
||||
wp_schedule_single_event($delay, 'orderid_deletion_event_FIPF', array($user_id, $order_id));
|
||||
}
|
||||
/**
|
||||
* action hook for the scheduled event
|
||||
* TODO: ne marche pas je ne sais pas pourquoi, pas urgent a resoudre
|
||||
*/
|
||||
function fipf_delete_order_id_later($user_id, $order_id)
|
||||
function delete_order_id_later_FIPF($user_id, $order_id)
|
||||
{
|
||||
error_log("delete order_id[$order_id] from user_id[$user_id]");
|
||||
delete_user_meta($user_id, 'fipf_order_id', $order_id);
|
||||
}
|
||||
add_action('fipf_orderid_deletion_event', 'fipf_delete_order_id_later', 5, 2);
|
||||
add_action('orderid_deletion_event_FIPF', 'delete_order_id_later_FIPF', 5, 2);
|
||||
|
||||
|
||||
|
||||
@@ -183,7 +190,7 @@ add_action('fipf_orderid_deletion_event', 'fipf_delete_order_id_later', 5, 2);
|
||||
* @return mixed num - user_id
|
||||
* bool false - if no match found
|
||||
*/
|
||||
function fipf_delete_order_id_on_success($current_user_id, $order_id)
|
||||
function delete_order_id_on_success_FIPF($current_user_id, $order_id)
|
||||
{
|
||||
$del_ret = delete_user_meta($current_user_id, 'fipf_order_id', $order_id);
|
||||
if ($del_ret === true)
|
||||
|
||||
@@ -9,9 +9,13 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* redirect users to profil
|
||||
* if prof -> author page
|
||||
* if partenaire -> post page / project page / home page
|
||||
*/
|
||||
function redirection_page_CIPF(){
|
||||
if (!is_page('redirection_cipf'))
|
||||
if (!is_page(PROF_PARTENAIRE_REDIRECTION_PAGE))
|
||||
return;
|
||||
|
||||
$base_url = home_url();
|
||||
@@ -25,13 +29,18 @@ function redirection_page_CIPF(){
|
||||
}
|
||||
else if (current_user_can('partenaire')) {
|
||||
$args = array(
|
||||
'post_type' => 'project',
|
||||
'post_type' => 'post,project',
|
||||
'author' => $current_user_id,
|
||||
'posts_per_page' => 1,
|
||||
);
|
||||
$query = reset(get_posts($args));
|
||||
$post_id = $query->ID;
|
||||
$redirect_url = get_permalink($query->ID);
|
||||
$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;
|
||||
|
||||
@@ -17,16 +17,12 @@ const CONSOLE_OFF = true;
|
||||
*/
|
||||
const FIPFCARD_CONSOLE_OFF = false;
|
||||
|
||||
/*
|
||||
* a variable that will contain the name of the first script enqueued
|
||||
*/
|
||||
$fipfcard_first_script = null;
|
||||
|
||||
|
||||
/*
|
||||
* path to ajax.js file, from root of js dir
|
||||
* redirections users
|
||||
*/
|
||||
$fipfcard_ajax_file = "utils/ajax.js";
|
||||
const PROF_PARTENAIRE_REDIRECTION_PAGE = 'redirection_cipf';
|
||||
define('PROF_PARTENAIRE_REDIRECTION_URL', home_url() . '/' . PROF_PARTENAIRE_REDIRECTION_PAGE);
|
||||
|
||||
|
||||
/*
|
||||
@@ -51,4 +47,34 @@ const PAYPAL_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiR
|
||||
*/
|
||||
const PAYPAL_API_BASE_URL = "https://api-m.sandbox.paypal.com";
|
||||
|
||||
/*
|
||||
* paypal redirections
|
||||
*/
|
||||
const PAYPAL_REDIRECTION_SUCCESS = PROF_PARTENAIRE_REDIRECTION_URL;
|
||||
const PAYPAL_REDIRECTION_FAILURE = PROF_PARTENAIRE_REDIRECTION_URL;
|
||||
|
||||
/*
|
||||
* paypal messages
|
||||
* put the message betweeen backticks `message` and then between single quotes '`message`'
|
||||
* because it will be evaluated in front by js, so it need something to evaluate, in ``
|
||||
* you can then use variables available in the context of execution : '`Transaction ${transaction.status}`'
|
||||
* is it good strategy ? idk
|
||||
|
||||
const PAYPAL_MESSAGE_SUCCESS = '`Transaction ${transaction.status}: ${transaction.id}<br><br>See console for all available details`';
|
||||
const PAYPAL_MESSAGE_FAILURE = '`Sorry, your transaction could not be processed...<br><br>${error}`';
|
||||
|
||||
*/
|
||||
const PAYPAL_MESSAGE_SUCCESS = '`paiement reussi`';
|
||||
const PAYPAL_MESSAGE_FAILURE = '`paiement raté`';
|
||||
|
||||
/*
|
||||
* acf fields for card :
|
||||
* - card_is_valid : has valid card
|
||||
* - card_date_purchase : date of purchase
|
||||
* - card_date_validity : date end of validity
|
||||
*/
|
||||
const CARD_IS_VALID = 'carte_est_valide';
|
||||
const CARD_DATE_PURCHASE = 'date_d_achat';
|
||||
const CARD_DATE_VALIDITY = 'date_fin_validite';
|
||||
|
||||
?>
|
||||
|
||||
@@ -263,10 +263,10 @@ class PLGNTLS_class
|
||||
/*
|
||||
* uncomment to print all enqueued files, can be usefull
|
||||
*/
|
||||
/*
|
||||
global $wp_scripts;
|
||||
error_log("wp_scripts->queue:");
|
||||
error_log(json_encode($wp_scripts->queue));
|
||||
/*
|
||||
global $wp_styles;
|
||||
error_log("wp_styles->queue:");
|
||||
error_log(json_encode($wp_styles->queue));
|
||||
|
||||
2
private
2
private
Submodule private updated: c57d99e92f...ff731c1ad4
Reference in New Issue
Block a user