-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from Eoxia/2.5.0
2.5.0
- Loading branch information
Showing
38 changed files
with
322 additions
and
1,021 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
* @author Eoxia <[email protected]> | ||
* @copyright (c) 2011-2020 Eoxia <[email protected]>. | ||
* @since 2.0.0 | ||
* @version 2.0.0 | ||
* @version 2.5.0 | ||
*/ | ||
|
||
namespace wpshop; | ||
|
@@ -74,7 +74,7 @@ public function check_cap( $cap, $request ) { | |
* Initialise les routes de l'API. | ||
* | ||
* @since 2.0.0 | ||
* @version 2.0.0 | ||
* @version 2.5.0 | ||
*/ | ||
public function callback_rest_api_init() { | ||
register_rest_route( 'wpshop/v2', '/statut', array( | ||
|
@@ -85,19 +85,12 @@ public function callback_rest_api_init() { | |
}, | ||
) ); | ||
|
||
register_rest_route( 'wpshop/v2', '/wps_gateway_paypal', array( | ||
'methods' => array( 'GET', 'POST' ), | ||
'callback' => array( $this, 'callback_wps_gateway_paypal' ), | ||
) ); | ||
|
||
register_rest_route( 'wpshop/v2', '/wps_gateway_stripe', array( | ||
'methods' => array( 'GET', 'POST' ), | ||
'callback' => array( $this, 'callback_wps_gateway_stripe' ), | ||
) ); | ||
|
||
register_rest_route( 'wpshop/v2', '/product/search', array( | ||
'methods' => array( 'GET' ), | ||
'callback' => array( $this, 'callback_search' ), | ||
'permission_callback' => function( $request ) { | ||
return Rest_Class::g()->check_cap( 'get', $request ); | ||
}, | ||
) ); | ||
|
||
register_rest_route( 'wpshop/v2', '/create/order', array( | ||
|
@@ -139,6 +132,22 @@ public function callback_rest_api_init() { | |
return Rest_Class::g()->check_cap( 'get', $request ); | ||
}, | ||
) ); | ||
|
||
register_rest_route( 'wpshop/v2', '/wpml_insert_data', array( | ||
'methods' => array( 'POST' ), | ||
'callback' => array( $this, 'callback_wpml_insert_data' ), | ||
'permission_callback' => function( $request ) { | ||
return Rest_Class::g()->check_cap( 'get', $request ); | ||
}, | ||
) ); | ||
|
||
register_rest_route( 'wpshop/v2', '/wpml_delete_data', array( | ||
'methods' => array( 'POST' ), | ||
'callback' => array( $this, 'callback_wpml_delete_data' ), | ||
'permission_callback' => function( $request ) { | ||
return Rest_Class::g()->check_cap( 'get', $request ); | ||
}, | ||
) ); | ||
} | ||
|
||
/** | ||
|
@@ -208,55 +217,6 @@ public function check_statut( $request ) { | |
return new \WP_REST_Response( true ); | ||
} | ||
|
||
/** | ||
* Gestion de la route Paypal. | ||
* Data is validated in wps_gateway_paypal | ||
* | ||
* @since 2.0.0 | ||
* @version 2.0.0 | ||
* | ||
* @param WP_Request $request L'objet contenant les informations de la requête. | ||
*/ | ||
public function callback_wps_gateway_paypal( $request ) { | ||
$data = $request->get_body_params(); | ||
|
||
// translators: Paypal Gateway data: {json_data}. | ||
LOG_Util::log( sprintf( 'Paypal Gateway data: %s', json_encode( $data ) ), 'wpshop2' ); | ||
|
||
$txn_id = get_post_meta( $data['custom'], 'payment_txn_id', true ); | ||
|
||
if ( $txn_id !== $data['txn_id'] ) { | ||
// @todo: Pensé différement, envoyé vers dolibarr ? | ||
update_post_meta( $data['custom'], 'payment_data', $data ); | ||
update_post_meta( $data['custom'], 'payment_txn_id', $data['txn_id'] ); | ||
update_post_meta( $data['custom'], 'payment_method', 'paypal' ); | ||
|
||
do_action( 'wps_gateway_paypal', $data ); | ||
} | ||
} | ||
|
||
/** | ||
* Gestion de la route Stripe. | ||
* | ||
* @since 2.0.0 | ||
* @version 2.0.0 | ||
* | ||
* @todo: Validate data request | ||
* | ||
* @param WP_Request $request L'objet contenant les informations de la requête. | ||
*/ | ||
public function callback_wps_gateway_stripe( $request ) { | ||
$param = json_decode( $request->get_body(), true ); | ||
|
||
// translators: Stripe Gateway data: {json_data}. | ||
LOG_Util::log( sprintf( 'Stripe Gateway data: %s', json_encode( $param ) ), 'wpshop2' ); | ||
LOG_Util::log( sprintf( 'Stripe Gateway found dolibarr order id: %s', $param['data']['object']['metadata']['order_id'] ), 'wpshop2' ); | ||
|
||
$param['custom'] = $param['data']['object']['metadata']['order_id']; | ||
|
||
do_action( 'wps_gateway_stripe', $param ); | ||
} | ||
|
||
/** | ||
* Recherche un produit depuis l'API. | ||
* | ||
|
@@ -477,6 +437,72 @@ public function callback_create_payment( $request ) { | |
|
||
return $propal; | ||
} | ||
|
||
/** | ||
* Gestion de la route pour insérer un post traduit par WPML. | ||
* | ||
* @since 2.5.0 | ||
* @version 2.5.0 | ||
* | ||
* @param WP_REST_Request $request L'objet contenant les informations de la requête. | ||
* | ||
* @return integer l'ID du post crée. | ||
*/ | ||
public function callback_wpml_insert_data( $request ) { | ||
$param = $request->get_params(); | ||
|
||
// Create post object | ||
$my_post = array( | ||
'post_title' => $param['label'], | ||
'post_content' => $param['description'], | ||
'post_type' => 'wps-product', | ||
'post_status' => 'publish', | ||
'post_author' => 1, | ||
'post_category' => array(2) | ||
); | ||
|
||
$output = wp_insert_post($my_post); | ||
|
||
if ( $output ) { | ||
// https://wpml.org/wpml-hook/wpml_element_type/ | ||
$wpml_element_type = apply_filters( 'wpml_element_type', 'wps-product' ); | ||
|
||
// get the language info of the original post | ||
// https://wpml.org/wpml-hook/wpml_element_language_details/ | ||
$get_language_args = array('element_id' => $param['wpshop_id'], 'element_type' => 'wps-product' ); | ||
$original_post_language_info = apply_filters( 'wpml_element_language_details', null, $get_language_args ); | ||
|
||
$set_language_args = array( | ||
'element_id' => $output, | ||
'element_type' => 'post_wps-product', | ||
'trid' => $original_post_language_info->trid, | ||
'language_code' => $param['language_code'], | ||
'source_language_code' => $original_post_language_info->language_code | ||
); | ||
|
||
do_action( 'wpml_set_element_language_details', $set_language_args ); | ||
} | ||
|
||
return $output; | ||
} | ||
|
||
/** | ||
* Gestion de la route pour supprimer un post WPML. | ||
* | ||
* @since 2.5.0 | ||
* @version 2.5.0 | ||
* | ||
* @param WP_REST_Request $request L'objet contenant les informations de la requête. | ||
* | ||
* @return integer L'id du post supprimé. | ||
*/ | ||
public function callback_wpml_delete_data( $request ) { | ||
$param = $request->get_params(); | ||
|
||
$output = wp_delete_post($param['id']); | ||
|
||
return $output; | ||
} | ||
} | ||
|
||
new API_Action(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
* @author Eoxia <[email protected]> | ||
* @copyright (c) 2011-2020 Eoxia <[email protected]>. | ||
* @since 2.0.0 | ||
* @version 2.0.0 | ||
* @version 2.5.0 | ||
*/ | ||
|
||
namespace wpshop; | ||
|
@@ -47,7 +47,7 @@ public function __construct() { | |
* @Todo bouger dans class-cart.php | ||
* | ||
* @since 2.0.0 | ||
* @version 2.0.0 | ||
* @version 2.5.0 | ||
*/ | ||
public function callback_calculate_totals() { | ||
$shipping_cost_option = get_option( 'wps_shipping_cost', Settings::g()->shipping_cost_default_settings ); | ||
|
@@ -71,10 +71,10 @@ public function callback_calculate_totals() { | |
if ( $shipping_cost_option['shipping_product_id'] !== $line['id'] ) { | ||
if ( $dolibarr_option['price_min'] > ( $line['price_ttc'] * $line['qty'] ) ) { | ||
$tva_amount += $dolibarr_option['price_min'] * $line['tva_tx'] / 100; | ||
$price_no_shipping += $dolibarr_option['price_min'] - $tva_amount; | ||
$price_no_shipping = $price; | ||
} else { | ||
$tva_amount += $line['tva_amount'] * $line['qty']; | ||
$price_no_shipping += $line['price'] * $line['qty']; | ||
$price_no_shipping = $price; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
* @author Eoxia <[email protected]> | ||
* @copyright (c) 2011-2020 Eoxia <[email protected]>. | ||
* @since 2.0.0 | ||
* @version 2.0.0 | ||
* @version 2.5.0 | ||
*/ | ||
|
||
namespace wpshop; | ||
|
@@ -181,7 +181,7 @@ public function validate_checkout( &$data, &$errors ) { | |
* Procède au paiement. | ||
* | ||
* @since 2.0.0 | ||
* @version 2.0.0 | ||
* @version 2.5.0 | ||
* | ||
* @param Order $order Les données de la commande. | ||
*/ | ||
|
@@ -200,33 +200,20 @@ public function process_order_payment( $order ) { | |
'url' => Pages::g()->get_checkout_link() . '/received/order/' . $order->data['external_id'] . '/', | ||
) ); | ||
break; | ||
case 'paypal': | ||
$result = Paypal::g()->process_payment( $order ); | ||
case 'online_payment': | ||
$result = Request_Util::g()->get( 'doliwpshop/getOnlinePaymentUrl?doli_id=' . $order->data['external_id'] ); | ||
|
||
Cart_Session::g()->destroy(); | ||
if ( ! empty( $result['url'] ) ) { | ||
if ( ! empty( $result ) ) { | ||
wp_send_json_success( array( | ||
'namespace' => 'wpshopFrontend', | ||
'module' => 'checkout', | ||
'callback_success' => 'redirectToPayment', | ||
'url' => $result['url'], | ||
) ); | ||
} | ||
break; | ||
case 'stripe': | ||
$result = Stripe::g()->process_payment( $order ); | ||
Cart_Session::g()->destroy(); | ||
|
||
if ( ! empty( $result['id'] ) ) { | ||
wp_send_json_success( array( | ||
'namespace' => 'wpshopFrontend', | ||
'module' => 'stripe', | ||
'callback_success' => 'redirectToPayment', | ||
'id' => $result['id'], | ||
'url' => $result, | ||
) ); | ||
} | ||
break; | ||
} | ||
|
||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
* @author Eoxia <[email protected]> | ||
* @copyright (c) 2011-2020 Eoxia <[email protected]>. | ||
* @since 2.1.0 | ||
* @version 2.1.0 | ||
* @version 2.5.0 | ||
*/ | ||
|
||
namespace wpshop; | ||
|
@@ -80,7 +80,7 @@ class Doli_Category extends Term_Class { | |
* | ||
* @var integer | ||
*/ | ||
public $limit = 10; | ||
public $limit = 1000; | ||
|
||
/** | ||
* Le nom de l'option pour la limite par page. | ||
|
@@ -120,6 +120,7 @@ public function display() { | |
|
||
$doli_categories = Request_Util::get( $route ); | ||
|
||
|
||
foreach ( $doli_categories as $key => $doli_category ) { | ||
if ( $doli_category->array_options->options__wps_id == 0 ) { | ||
unset( $doli_categories[$key] ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.