Handled proper endpoint naming

This commit is contained in:
Nedim Uka
2018-11-19 12:35:04 +01:00
parent 752df56d4a
commit f56377f606
3 changed files with 15 additions and 8 deletions

View File

@@ -14,7 +14,7 @@ class Wiaas_Support_Api {
public static function register_routes() {
register_rest_route(self::$namespace, self::$rest_base . '/sendSupportMail', array(
register_rest_route(self::$namespace, self::$rest_base . '/send-support-email', array(
'methods' => 'POST',
'callback' => array(__CLASS__, 'send_support_email'),
'permission_callback' => 'is_user_logged_in',
@@ -26,7 +26,7 @@ class Wiaas_Support_Api {
'required' => true,
'sanitize_callback' => 'absint',
),
'supportText' => array(
'support_text' => array(
'description' => __('Email text.', 'wiaas'),
'type' => 'string',
'required' => true
@@ -45,18 +45,22 @@ class Wiaas_Support_Api {
public static function send_support_email($request) {
$order_id = $request['id'];
$message = $request['supportText'];
$message = $request['support_text'];
$order = wc_get_order($order_id);
$customer_id = $order->get_customer_id();
$customer = get_user_by('id', $customer_id);
$mailer = WC()->mailer();
$recipient = WIAAS_SUPPORT_EMAIL;
$subject = __("Customer comment for order id: ".$order_id);
$subject = __('Customer: '.$customer->get('first_name').', '.''.$customer->get('last_name').' needs support for order number: ' .$order->get_order_number());
$headers = array();
$success = $mailer->send( $recipient, $subject, $message, $headers );
if ($success) {
wc_create_order_note($request['id'] , $message, true );
wc_create_order_note($order_id , $message, true );
return wiaas_api_notice('EMAIL_SENT', 'success');
}

View File

@@ -48,6 +48,9 @@ define('DB_CHARSET', 'utf8mb4');
define('DB_COLLATE', '');
$table_prefix = env('DB_PREFIX') ?: 'wp_';
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
/**
* Authentication Unique Keys and Salts
*/

View File

@@ -325,13 +325,13 @@ export const setSupportMessage = (message) => ({
supportText: message
});
export const sendSupportMail = (orderInfo, orderPackages, supportText) => {
export const sendSupportMail = (orderInfo, orderPackages, support_text) => {
let id = orderInfo.id;
return dispatch => {
return htmlClient.fetch({
url: `${API_SERVER}/wp-json/wiaas/support/sendSupportMail`,
url: `${API_SERVER}/wp-json/wiaas/support/send-support-email`,
method: 'post',
data: {id, supportText}
data: {id, support_text}
})
.then(response => {
if (typeof response.data !== 'undefined' && 'messages' in response.data) {