page_data = globalfunc::getMessage($parent, $parent->lang, 'redeem');
if (count($parent->params) == 0) {
$parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
} else {
$qry_params = explode("?", $parent->params[0]);
$parameter_val = strtolower($qry_params[0]);
switch ($parameter_val) {
case "wallet":
case "category":
case "product":
case "order":
case "orderstatus":
$this->$parameter_val($parent);
break;
default:
$parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
break;
}
}
$parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
}
/* /////////////////////////////// ADD TO WALLET //////////////////////////////////////////////// */
private function wallet($parent)
{
globalfunc::checkMethodType($parent, array('GET'));
globalfunc::checkParamCount($parent, 1);
globalfunc::checkAuthrozation($parent, array('type' => 'user'));
// REDEEM VALIDATION
if (!projectfunc::checkValidReedem($parent)) {
$parent->response(array('response' => 'failed', 'message' => $this->page_data["error1"]), 406);
}
//CHECK POINTS
$query_points = $parent->selectQuery(TABLE_USER_EPOINTS, "*", " smpin='" . $parent->current_smpin . "'", "1");
if (!$query_points['nr'] > 0) {
$parent->response(array('response' => 'failed', 'message' => $this->page_data["error5"]), 406);
}
$points = $query_points['result'][0]->points;
//MUST COMPLETE ON CERTIFICATION
$query_learn = $parent->selectQuery(TABLE_USER_LEARNING, "smpin,lvl_id", "smpin='" . $parent->current_smpin . "' AND status=3 ORDER by lvl_id DESC", "1");
if (!$query_learn['nr'] > 0) {
$parent->response(array('response' => 'failed', 'message' => $this->page_data["error12"]), 406);
}
//GET USER CURRENT LEVEL
//$query_learn=$parent->selectQuery(TABLE_USER_LEARNING,"*","smpin='".$parent->current_smpin."' AND (status=3 OR (lvl_id IN (3,4) AND status NOT IN(4,6) ) ORDER by lvl_id DESC","1");
if ($query_learn['nr'] > 0) {
$query_multply = $parent->selectQuery(TABLE_TRAINING_LEVEL, "*", "lvl_id='" . $query_learn['result'][0]->lvl_id . "' ", "1");
}
// else
// {
// $query_multply=$parent->selectQuery(TABLE_TRAINING_LEVEL,"*","lvl_id='1' ","1");
// }
$balance_point = 0;
//NEW LEVEL BASED COND
switch ($query_learn['result'][0]->lvl_id) {
case '1':
$newpoints = round($points * .5);
$balance_point = $points - $newpoints;
$points = $newpoints;
break;
case '2':
$newpoints = round($points * .75);
$balance_point = $points - $newpoints;
$points = $newpoints;
break;
case '3':
//no condition
$balance_point = 0;
break;
case '4':
//no condition
$balance_point = 0;
break;
case '5':
//no condition
$balance_point = 0;
break;
case '6':
//no condition
$balance_point = 0;
break;
}
$redeem_amount = $query_multply['result'][0]->lvl_points * $points;
//ADD WALLET AMOUNTS
// $obj=new stdClass();
// $obj->type="redeem";
// $obj->type_id=TIMETOKEN.$parent->current_user_id;
// $obj->description="REDEEM POINTS";
// $obj->amount=$redeem_amount;
// $obj->lvl_points=$query_multply['result'][0]->lvl_points;
// projectfunc::userAddWallet($parent,$obj,$parent->current_user_id);
$parent->executeQuery("INSERT INTO " . TABLE_USER_EPOINTS_HISTORY . "( `smpin`, `type`, `type_id`, `description`, `points`, `transaction_type`, `created_on`, `modified_on`) VALUES ('" . $parent->current_smpin . "','redeem','" . TIMETOKEN . $parent->current_user_id . "','REDEEM POINTS','" . $points . "' ,'D','" . NOW . "','" . NOW . "')");
//UPDATE POINT IN USER
$parent->executeQuery("UPDATE " . TABLE_USER_EPOINTS . " SET points=" . $balance_point . " WHERE smpin='" . $parent->current_smpin . "' ");
//GET USER DETAILS
$query_rewardpointarr = $parent->selectQuery(TABLE_USER_EPOINTS, "*", "smpin='" . $parent->current_smpin . "' ", "1");
$earning = ($query_rewardpointarr['nr'] > 0) ? (string) $query_rewardpointarr['result'][0]->points : '0';
$is_redeem_point = (projectfunc::checkValidReedem($parent)) ? "1" : "0";
$wallet_amount = projectfunc::userWalletamount($parent, $parent->current_smpin);
//SEND NOTIFICATION
$nobj = new stdClass();
$nobj->notificationtitle = 'Redemptions of redeem points';
$nobj->notificationtext = 'Redemptions of redeem points will update to wallet on admin approval.';
$nobj->notificationtype = '6';
$nobj->notificationdata = new stdClass();
// projectfunc::sendUserNotification($parent, $nobj);
//ADDED TO APPROVAL
$parent->executeQuery("INSERT INTO " . TABLE_USER_WALLET_APPROVE . "( `smpin`, `points`, `amount`, `lvl_id`, `is_approved`, `approved_id`, `created_on`, `modified_on`) VALUES ('" . $parent->current_smpin . "','" . $points . "','" . $redeem_amount . "','" . $query_multply['result'][0]->lvl_id . "','0' ,'0','" . NOW . "','" . NOW . "')");
//GET UNAPPROVE AMOUNT
$unapproved_amount = projectfunc::userUnapprovedamount($parent, $parent->current_smpin);
$data_arr = array('earning' => $earning, 'is_redeem_point' => $is_redeem_point, 'wallet_amount' => $wallet_amount, 'unapproved_amount' => $unapproved_amount);
$userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
//MAIL ADMIN
$message = '
| HYPER-M |
| |
Redeem point approval request
| Name | SMPIN | Dealer | Points | Amount |
| ' . $userdata->fname . ' ' . $userdata->lname . ' | ' . $userdata->smpin . ' | ' . $userdata->dealer->dealer_name . '-' . $userdata->dealer->dealer_code . ' | ' . $points . ' | ' . $redeem_amount . ' |
|
| |
| |
';
$obj = array();
$obj['from'] = SUPPORT_EMAIL;
$obj['to'] = SUPPORT_EMAIL;
$obj['subject'] = "Redeem point approval request";
$obj['message'] = $message;
// globalfunc::sendMai($parent, $obj);
//LOG
$logstr = 'ADD WALLET AMOUNT';
globalfunc::insertUserLog($parent, $logstr);
$parent->response(array('response' => 'success', 'message' => "SUCCESS", 'data' => $data_arr), 200);
}
/* //////////////////////////////////////////////////////////////////////////////////////////// */
/* /////////////////////////////// WOOHOO //////////////////////////////////////////////// */
private function woohooCurl($parent, $url, $post = null, $type)
{
}
/* //////////////////////////////////////////////////////////////////////////////////////////// */
/* /////////////////////////////// CATEGORY //////////////////////////////////////////////// */
private function category($parent)
{
globalfunc::checkMethodType($parent, array('GET'));
//globalfunc::checkParamCount($parent,1);
globalfunc::checkAuthrozation($parent, array('type' => 'user'));
projectfunc::generateWoohoo($parent);
if (!projectfunc::userWalletamount($parent, $parent->current_smpin)) {$parent->response(array('response' => 'failed', 'message' => $this->page_data["error7"]), 406);}
//GET CATEGORY
if (count($parent->params) == 1) {
$url = "catalog/categories";
$return_data = $this->woohooCurl($parent, $url, null, 'category');
$category = new stdClass();
$category->root_category = (object) array('category_id' => $return_data->id, 'category_name' => $return_data->name, 'category_image' => '');
//LOG
$logstr = 'WOOHOO CATEGORY';
globalfunc::insertUserLog($parent, $logstr);
$parent->response(array('response' => 'success', 'message' => "SUCCESS", 'data' => $category), 200);
} else if (count($parent->params) == 2) {
//GET CATEGORY DETAILS
$categoryid = $parent->params[1];
if (!is_numeric($categoryid)) {$parent->response(array('response' => 'failed', 'message' => $this->page_data["error2"]), 406);}
$url = "catalog/categories/" . $categoryid . '/products?offset=0&limit=1000';
$return_data = $this->woohooCurl($parent, $url, null, 'category_product');
// echo '';
// print_r($return_data);
// echo '';
$category = new stdClass();
$product = new stdClass();
foreach ($return_data->products as $k => $v) {
$return_data->products[$k]->id = $v->sku;
$return_data->products[$k]->price_type = 'Range';
$return_data->products[$k]->min_custom_price = $v->minPrice;
$return_data->products[$k]->max_custom_price = $v->maxPrice;
//BASE
$return_data->products[$k]->images->base = ($return_data->products[$k]->images->base != '') ? $return_data->products[$k]->images->base : NOIMAGE_URL;
$return_data->products[$k]->images->base_image = $return_data->products[$k]->images->base;
//SMALL
$return_data->products[$k]->images->small = ($return_data->products[$k]->images->small != '') ? $return_data->products[$k]->images->small : NOIMAGE_URL;
$return_data->products[$k]->images->small_image = $return_data->products[$k]->images->small;
}
$product->product = $return_data->products;
$category = (object) array('id' => $return_data->id, 'name' => $return_data->name, 'description' => $return_data->description, 'count' => $return_data->productsCount, '_embedded' => $product);
//LOG
$logstr = 'WOOHOO CATEGORY PRODUCTS';
globalfunc::insertUserLog($parent, $logstr);
if (isset($return_data->id) && $return_data->id > 0) {
$parent->response(array('response' => 'success', 'message' => "SUCCESS", 'data' => $category), 200);
} else {
$parent->response(array('response' => 'failed', 'message' => $this->page_data["error3"]), 406);
}
}
}
/* //////////////////////////////////////////////////////////////////////////////////////////// */
/* /////////////////////////////// PRODUCT //////////////////////////////////////////////// */
private function product($parent)
{
globalfunc::checkMethodType($parent, array('GET'));
globalfunc::checkParamCount($parent, 2);
globalfunc::checkAuthrozation($parent, array('type' => 'user'));
projectfunc::generateWoohoo($parent);
if (!projectfunc::userWalletamount($parent, $parent->current_smpin)) {$parent->response(array('response' => 'failed', 'message' => $this->page_data["error7"]), 406);}
//GET PRODUCT DETAILS
$productid = $parent->params[1];
//if (!is_numeric($productid)) {$parent->response(array('response' => 'failed', 'message' => $this->page_data["error4"]), 406);}
$url = "catalog/products/" . $productid;
$return_data = $this->woohooCurl($parent, $url, null, 'product');
//print_r($return_data);
$product = new stdClass();
$return_data->id = $return_data->sku;
$return_data->price_type = ucfirst(strtolower($return_data->price->type));
$return_data->min_custom_price = $return_data->price->min;
$return_data->max_custom_price = $return_data->price->max;
$return_data->images = ($return_data->images->base) ? $return_data->images->base : NOIMAGE_URL;
$return_data->tnc_mobile = $return_data->tnc->link;
$return_data->tnc_web = $return_data->tnc->link;
$return_data->custom_denominations = @implode(',', $return_data->price->denominations);
//LOG
$logstr = 'WOOHOO PRODUCT DETAILS';
globalfunc::insertUserLog($parent, $logstr);
if (isset($return_data->id) && $return_data->id != '') {
$parent->response(array('response' => 'success', 'message' => "SUCCESS", 'data' => $return_data), 200);
} else {
$parent->response(array('response' => 'failed', 'message' => $this->page_data["error4"]), 406);
}
}
/* //////////////////////////////////////////////////////////////////////////////////////////// */
/* /////////////////////////////// ORDER //////////////////////////////////////////////// */
private function order($parent)
{
globalfunc::checkMethodType($parent, array('POST'));
globalfunc::checkParamCount($parent, 1);
globalfunc::checkAuthrozation($parent, array('type' => 'user'));
projectfunc::generateWoohoo($parent);
if (!projectfunc::userWalletamount($parent, $parent->current_smpin)) {$parent->response(array('response' => 'failed', 'message' => $this->page_data["error7"]), 406);}
//GET PRODUCT DETAILS
$REQUEST_KEYS = array('product_id' => 'string', 'product_price' => 'number');
globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
$product_id = escape_str($parent->_request["product_id"]);
$product_price = escape_str($parent->_request["product_price"]);
$url = "catalog/products/" . $product_id;
$return_data = $this->woohooCurl($parent, $url, null, 'product');
//print_r($return_data);
$return_data->price_type = ucfirst(strtolower($return_data->price->type));
$return_data->custom_denominations = $return_data->price->denominations;
$return_data->images = ($return_data->images->base) ? $return_data->images->base : NOIMAGE_URL;
//LOG
$logstr = 'WOOHOO ORDER';
globalfunc::insertUserLog($parent, $logstr);
$current_amount = projectfunc::userWalletamount($parent, $parent->current_smpin);
//print_r($return_data);
if (isset($return_data->id) && isset($return_data->sku)) {
if (!($current_amount >= $product_price)) {
$parent->response(array('response' => 'failed', 'message' => $this->page_data["error7"]), 406);
}
switch (strtolower($return_data->price_type)) {
case "range":
if (!($return_data->price->min <= $product_price && $return_data->price->max >= $product_price)) {
$parent->response(array('response' => 'failed', 'message' => $this->page_data["error9"]), 406);
}
break;
case "slab":
if (isset($return_data->custom_denominations) && is_array($return_data->custom_denominations)) {
$slab_arr = $return_data->custom_denominations;
//$slab_arr = @explode(',', $return_data->custom_denominations);
if (!in_array($product_price, $slab_arr)) {
$parent->response(array('response' => 'failed', 'message' => $this->page_data["error9"]), 406);
}
} else {
$parent->response(array('response' => 'failed', 'message' => $this->page_data["error10"]), 406);
}
break;
default:$parent->response(array('response' => 'failed', 'message' => $this->page_data["error8"]), 406);
break;
}
//BILLING DETAILS
$billing_obj = new stdClass();
$shipping_obj = new stdClass();
$billing_obj->firstname = $parent->current_user_data->fname;
$billing_obj->lastname = $parent->current_user_data->lname;
$billing_obj->email = $parent->current_user_data->emailid;
$billing_obj->telephone = '+91' . $parent->current_user_data->mobileno;
$user_data = projectfunc::getuserdata($parent, $parent->current_user_id);
$billing_obj->line1 = $user_data->dealer->dealer_name;
$billing_obj->line2 = $user_data->dealer->city;
$billing_obj->city = $user_data->dealer->city;
$billing_obj->region = $user_data->dealer->state;
$billing_obj->country = "IN";
$billing_obj->postcode = "560076";
//$billing_obj->company = '';
//SHIPPING DETAILS
$shipping_obj->firstname = $parent->current_user_data->fname;
$shipping_obj->lastname = $parent->current_user_data->lname;
$shipping_obj->email = $parent->current_user_data->emailid;
$shipping_obj->telephone = '+91' . $parent->current_user_data->mobileno;
$shipping_obj->line1 = $user_data->dealer->dealer_name;
$shipping_obj->line2 = $user_data->dealer->city;
$shipping_obj->city = $user_data->dealer->city;
$shipping_obj->region = $user_data->dealer->state;
$shipping_obj->country = "IN";
$shipping_obj->postcode = "560076";
$shipping_obj->billToThis = true;
//$shipping_obj->company = '';
$post_obj = new stdClass();
$post_obj->address = $shipping_obj;
$post_obj->billing = $billing_obj;
$post_obj->payments = array(array('code' => 'svc', 'amount' => (int) $product_price));
$product_qty = 1;
//INSERT INTO ORDER
$parent->executeQuery("INSERT INTO " . TABLE_ORDER . "( `userid`,`smpin`, `product_id`, `product_name`, `product_desc`,images, `qty`, `product_amount`, `is_success`, `is_refund`, `created_on`, `modfified_on`) VALUES ( '" . $parent->current_user_id . "','" . $parent->current_smpin . "','" . $product_id . "','" . escape_str($return_data->name) . "','" . escape_str($return_data->name) . "','" . escape_str($return_data->images) . "','" . $product_qty . "','" . $product_price . "' ,'0','0','" . NOW . "','" . NOW . "')");
$orderid = $parent->lastInsertId();
//UDPATE ORDER ID
$order_id = "SUZ" . date('ymd', strtotime(CUR_DATE)) . $orderid;
$parent->executeQuery("UPDATE " . TABLE_ORDER . " SET order_id='" . $order_id . "' WHERE id='" . $orderid . "'");
//WALLET UPDATE
$new_balance = $current_amount - $product_price;
$parent->executeQuery("UPDATE " . TABLE_USER_WALLET . " SET amount='" . $new_balance . "' WHERE smpin='" . $parent->current_smpin . "' ");
$parent->executeQuery("INSERT INTO " . TABLE_USER_WALLET_HISTORY . "( `smpin`, `type`, `type_id`, `description`, `amount`, `transaction_type`, `created_on`, `modified_on`) VALUES ('" . $parent->current_smpin . "','ORDER','" . $orderid . "','ORDER','" . $product_price . "' ,'D','" . NOW . "','" . NOW . "')");
$post_obj->refno = $order_id;
//$post_obj->successUrl = "https://baseurl/ordercomplete/success";
//$post_obj->failureUrl = "https://baseurl/ordercomplete/failure";
$post_obj->products = array(array('sku' => $product_id, 'price' => (int) $product_price, 'qty' => $product_qty, 'currency' => 356, 'giftMessage' => '', "theme" => '')); //, "theme" => "bwi"
$post_obj->syncOnly = true;
$post_obj->deliveryMode = 'API';
$url = "orders";
//print_r($post_obj);
$order_data = $this->woohooCurl($parent, $url, (array) $post_obj, 'order');
if (isset($order_data->orderId) && $order_data->orderId != '') {
$card_data = '';
if (isset($order_data->cards) && count($order_data->cards) > 0) {
//$key_name = key((array) $order_data->carddetails);
//$card_obj = new stdClass();
//$card_obj = $order_data->carddetails->$key_name[0];
//$card_obj->name = $key_name;
$card_data = escape_str(json_encode($order_data->cards[0]));
}
$parent->executeQuery("UPDATE " . TABLE_ORDER . " SET is_success='1',woohoo_order_id='" . escape_str($order_data->order_id) . "',woohoo_order_status='" . escape_str($order_data->status) . "',card_data='" . $card_data . "' WHERE id='" . $orderid . "'");
//SEND NOTIFICATION
$nobj = new stdClass();
$nobj->notificationtitle = 'Order Placed successfully';
$nobj->notificationtext = 'Order Placed successfully.';
$nobj->notificationtype = '7';
$nobj->notificationdata = new stdClass();
// projectfunc::sendUserNotification($parent, $nobj);
if ($order_data->payments[0]->balance < 25000) {
$message = '
| HYPER-M - WOOHOO API LOW BALANCE |
Woohoo api balance is below 25000. Balance Available : ' . $order_data->payments[0]->balance . ' |
|
|
|
|
';
$obj = array();
$obj['from'] = SUPPORT_EMAIL;
//$obj['replayto']=SUPPORT_EMAIL;
$obj['to'] = SUPPORT_EMAIL;
$obj['subject'] = "Woohoo balance is less.";
$obj['message'] = $message;
// globalfunc::sendMai($parent, $obj);
}
$parent->response(array('response' => 'success', 'type' => '1', 'message' => "SUCCESS"), 200);
} else {
//REFUND WALLET
/*
* REFUND FROM CRON REFUND service only
*
$obj=new stdClass();
$obj->type="REFUND";
$obj->type_id=$orderid;
$obj->description="REFUND ORDER";
$obj->amount=$product_price;
projectfunc::userAddWallet($parent,$obj,$parent->current_user_id);
$parent->executeQuery("UPDATE ".TABLE_ORDER." SET is_refund='1' WHERE id='".$orderid."'");
*
*/
$parent->response(array('response' => 'success', 'type' => '2', 'message' => "SUCCESS"), 200);
//$parent->response(array('response'=>'failed','message'=>$this->page_data["error10"]),406);
}
} else {
$parent->response(array('response' => 'failed', 'message' => $this->page_data["error4"]), 406);
}
}
/* //////////////////////////////////////////////////////////////////////////////////////////// */
/* /////////////////////////////// ORDER //////////////////////////////////////////////// */
private function orderstatus($parent)
{
globalfunc::checkMethodType($parent, array('GET'));
globalfunc::checkParamCount($parent, 2);
globalfunc::checkAuthrozation($parent, array('type' => 'user'));
projectfunc::generateWoohoo($parent);
$order_id = escape_str($parent->params[1]);
$query_order_arr = $parent->selectQuery(TABLE_ORDER, "*", "is_success=1 AND smpin='" . $parent->current_smpin . "' AND id='" . $order_id . "' ", "1");
if (!$query_order_arr['nr'] > 0) {
$parent->response(array('response' => 'failed', 'message' => $this->page_data['error11']), 406);
}
$order_ref = $query_order_arr['result'][0]->order_id;
$url = "order/" . $order_ref . "/status";
$return_data = $this->woohooCurl($parent, $url, null, 'status');
if ($return_data->status == 'COMPLETE') {
$parent->executeQuery("UPDATE " . TABLE_ORDER . " SET woohoo_order_id='" . $return_data->orderId . "',woohoo_order_status='" . $return_data->status . "' ,modfified_on='" . NOW . "' WHERE id='" . $order_id . "'");
$query_arr = $parent->selectQuery(TABLE_ORDER, "*", " smpin='" . $parent->current_smpin . "' AND is_success='1' AND smpin='" . $parent->current_smpin . "' AND id='" . $order_id . "' ", "1");
$parent->response(array('response' => 'success', 'data' => $query_arr['result'][0], 'message' => "SUCCESS"), 200);
} else {
$parent->response(array('response' => 'failed', 'message' => $this->page_data["error10"]), 406);
}
}
/* //////////////////////////////////////////////////////////////////////////////////////////// */
}