Checkout logic
This commit is contained in:
@@ -229,11 +229,13 @@ class Wiaas_Cart_API {
|
||||
$request['options_ids']
|
||||
);
|
||||
|
||||
if ($success) {
|
||||
return wiaas_api_notice('PACKAGE_ADDED', 'success');
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_notice('PACKAGE_ALREADY_IN_CART', 'error');
|
||||
}
|
||||
|
||||
return wiaas_api_notice('PACKAGE_ALREADY_IN_CART', 'error');
|
||||
return wiaas_api_notice('PACKAGE_ADDED', 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,11 +247,13 @@ class Wiaas_Cart_API {
|
||||
|
||||
$success = Wiaas_Cart::remove_package_from_cart($request['key']);
|
||||
|
||||
if ($success) {
|
||||
return wiaas_api_notice('PACKAGE_REMOVED_FROM_CART', 'success');
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_notice('INVALID_PACKAGE_FOR_REMOVE', 'error');
|
||||
}
|
||||
|
||||
return wiaas_api_notice('INVALID_PACKAGE_FOR_REMOVE', 'error');
|
||||
return wiaas_api_notice('PACKAGE_REMOVED_FROM_CART', 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,11 +264,13 @@ class Wiaas_Cart_API {
|
||||
|
||||
$success = Wiaas_Cart::update_package_quantity($request['key'], $request['quantity']);
|
||||
|
||||
if ($success) {
|
||||
return wiaas_api_notice('QUANTITY_UPDATED', 'success');
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_notice('QUANTITY_NOT_UPDATED', 'error');
|
||||
}
|
||||
|
||||
return wiaas_api_notice('QUANTITY_NOT_UPDATED', 'error');
|
||||
return wiaas_api_notice('QUANTITY_UPDATED', 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,25 +289,15 @@ class Wiaas_Cart_API {
|
||||
* @return mixed|WP_REST_Response
|
||||
*/
|
||||
public static function upload_cart_document($request) {
|
||||
$result = Wiaas_Cart::upload_cart_document($request['doc_type'], $request['package_key']);
|
||||
$success = Wiaas_Cart::upload_cart_document($request['doc_type'], $request['package_key']);
|
||||
|
||||
if (is_wp_error($result)) {
|
||||
$error_code = $result->get_error_code();
|
||||
|
||||
if ($error_code === 'wiaas_upload_missing_file') {
|
||||
return wiaas_api_generate_error('NO_FILE');
|
||||
}
|
||||
|
||||
if ($error_code === 'wiaas_upload_error') {
|
||||
return wiaas_api_generate_error('UPLOAD_ERROR');
|
||||
}
|
||||
|
||||
return wiaas_api_generate_error('NOT_LINKED_TO_CART');
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_generate_error('UPLOAD_ERROR');
|
||||
}
|
||||
|
||||
return wiaas_api_notice('FILE_UPLOADED', 'success', array(
|
||||
'id_document' => $result,
|
||||
));
|
||||
return wiaas_api_notice('FILE_UPLOADED', 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -325,6 +321,10 @@ class Wiaas_Cart_API {
|
||||
|
||||
Wiaas_Checkout::process_checkout($request->get_body_params());
|
||||
|
||||
if (wc_notice_count('error') > 0) {
|
||||
return wiaas_api_cart_error_notices();
|
||||
}
|
||||
|
||||
return wiaas_api_notice('ORDER_PLACED', 'success');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user