Added support for sending customer emails
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Support_Api {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint namespace.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $namespace = 'wiaas';
|
||||||
|
|
||||||
|
private static $rest_base = 'support';
|
||||||
|
|
||||||
|
|
||||||
|
public static function register_routes() {
|
||||||
|
|
||||||
|
register_rest_route(self::$namespace, self::$rest_base . '/sendSupportMail', array(
|
||||||
|
'methods' => 'POST',
|
||||||
|
'callback' => array(__CLASS__, 'send_support_email'),
|
||||||
|
'permission_callback' => 'is_user_logged_in',
|
||||||
|
//this.props.order, this.props.order.packages, this.props.supportText
|
||||||
|
'args' => array(
|
||||||
|
'id' => array(
|
||||||
|
'description' => __('Order ID.', 'wiaas'),
|
||||||
|
'type' => 'integer',
|
||||||
|
'required' => true,
|
||||||
|
'sanitize_callback' => 'absint',
|
||||||
|
),
|
||||||
|
'supportText' => array(
|
||||||
|
'description' => __('Email text.', 'wiaas'),
|
||||||
|
'type' => 'string',
|
||||||
|
'required' => true
|
||||||
|
)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send support email and save massage to order notes
|
||||||
|
*
|
||||||
|
* @param WP_REST_Request $request Request data.
|
||||||
|
*
|
||||||
|
* @return WP_REST_Response
|
||||||
|
*/
|
||||||
|
public static function send_support_email($request) {
|
||||||
|
|
||||||
|
$order_id = $request['id'];
|
||||||
|
$message = $request['supportText'];
|
||||||
|
|
||||||
|
$mailer = WC()->mailer();
|
||||||
|
|
||||||
|
$recipient = WIAAS_SUPPORT_EMAIL;
|
||||||
|
$subject = __("Customer comment for order id: ".$order_id);
|
||||||
|
|
||||||
|
$headers = array();
|
||||||
|
$success = $mailer->send( $recipient, $subject, $message, $headers );
|
||||||
|
|
||||||
|
if ($success) {
|
||||||
|
wc_create_order_note($message = $request['id'] , $message, true );
|
||||||
|
return wiaas_api_notice('EMAIL_SENT', 'success');
|
||||||
|
}
|
||||||
|
|
||||||
|
return wiaas_api_notice('EMAIL_NOT_SENT', 'failed');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,7 +43,8 @@ class Wiaas_API {
|
|||||||
|
|
||||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-order-projects-api.php';
|
include_once dirname( __FILE__ ) . '/api/class-wiaas-order-projects-api.php';
|
||||||
|
|
||||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-wc- package-api-integration.php';
|
include_once dirname( __FILE__ ) . '/api/class-wiaas-wc-package-api-integration.php';
|
||||||
|
include_once dirname( __FILE__ ) . '/api/class-wiaas-support-api.php';
|
||||||
|
|
||||||
// API functions
|
// API functions
|
||||||
include_once dirname( __FILE__ ) . '/api/wiaas-api-functions.php';
|
include_once dirname( __FILE__ ) . '/api/wiaas-api-functions.php';
|
||||||
@@ -58,6 +59,7 @@ class Wiaas_API {
|
|||||||
'Wiass_REST_User_API',
|
'Wiass_REST_User_API',
|
||||||
'Wiaas_REST_Customer_API',
|
'Wiaas_REST_Customer_API',
|
||||||
'Wiaas_Order_Projects_API',
|
'Wiaas_Order_Projects_API',
|
||||||
|
'Wiaas_Support_Api',
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $controllers as $controller ) {
|
foreach ( $controllers as $controller ) {
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ define('SENDGRID_FROM_NAME', env('WP_SENDGRID_FROM_NAME' ?: 'Wiaas'));
|
|||||||
* Wiaas Env variables
|
* Wiaas Env variables
|
||||||
*/
|
*/
|
||||||
define('WIAAS_CUSTOMER_INTERFACE', env('WIAAS_CUSTOMER_INTERFACE') ?: WP_HOME);
|
define('WIAAS_CUSTOMER_INTERFACE', env('WIAAS_CUSTOMER_INTERFACE') ?: WP_HOME);
|
||||||
|
define('WIAAS_SUPPORT_EMAIL', env('WIAAS_SUPPORT_EMAIL') ?: 'support@co-ideation.com');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom Settings
|
* Custom Settings
|
||||||
|
|||||||
@@ -326,11 +326,12 @@ export const setSupportMessage = (message) => ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const sendSupportMail = (orderInfo, orderPackages, supportText) => {
|
export const sendSupportMail = (orderInfo, orderPackages, supportText) => {
|
||||||
|
let id = orderInfo.id;
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
return htmlClient.fetch({
|
return htmlClient.fetch({
|
||||||
url: `${API_SERVER}/orders/api/sendSupportMail`,
|
url: `${API_SERVER}/wp-json/wiaas/support/sendSupportMail`,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: {orderInfo, orderPackages, supportText}
|
data: {id, supportText}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||||
|
|||||||
Reference in New Issue
Block a user