| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708 |
- <?php
- /****************************
- * File : redeem.php
- * Author : Cygnusa
- * @2018
- ****************************/
- //SECURITY
- if (!defined('APPLICATION_PATH')) {
- exit('No direct script access allowed');
- }
- //FUNCTION LISTS
- class redeem
- {
- private $woohoo_url = WOOHOO_API_URL;
- public function __construct($parent)
- {
- //GET PAGE MESSAGE
- $this->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 = '<table width="100%" bgcolor="#dfdfdf" border="0" cellspacing="10" cellpadding="0" style="padding-top:10px;">
- <tr>
- <td><table width="700" border="0" align="center" cellpadding="0" cellspacing="0" style="background:#ffffff; margin-top:0px;">
- <tr>
- <td bgcolor="#4d90fe" height="36" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; color:#070000; text-align:left; font-weight:bold; padding-left:14px; color:#fff">HYPER-M</td>
- </tr>
- <tr>
- <td bgcolor="#333333" style="line-height:3px;"> </td>
- </tr>
- <tr><td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
- line-height: 1.5;"><div style="font-family:Arial, Helvetica, sans-serif; color:#333; font-size:12px; padding:5px;" ><p style="font-family:Arial, Helvetica, sans-serif; color:#333; font-size:12px; padding:5px;">Redeem point approval request</p><table width="100%" style="border-collapse: collapse;">
- <tr><th style=" border: 1px solid black;">Name</th><th style=" border: 1px solid black;">SMPIN</th><th style=" border: 1px solid black;">Dealer</th><th style=" border: 1px solid black;">Points</th><th style=" border: 1px solid black;">Amount</th></tr>
- <tr><td style=" border: 1px solid black;font-family:Arial, Helvetica, sans-serif;font-size:12px; ">' . $userdata->fname . ' ' . $userdata->lname . '</td><td style=" border: 1px solid black;font-family:Arial, Helvetica, sans-serif;font-size:12px; ">' . $userdata->smpin . '</td><td style=" border: 1px solid black;font-family:Arial, Helvetica, sans-serif;font-size:12px;">' . $userdata->dealer->dealer_name . '-' . $userdata->dealer->dealer_code . '</td><td style=" border: 1px solid black;font-family:Arial, Helvetica, sans-serif;font-size:12px; ">' . $points . '</td><td style=" border: 1px solid black;font-family:Arial, Helvetica, sans-serif;font-size:12px; ">' . $redeem_amount . '</td></tr>
- </div></table>
- <br><br>
- <tr>
- <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#3f3f3f; background:#fafafa; line-height:30px; text-align:center;"><div class="footer-con">
- <p>Thanks & Regards, <strong style="color:#070000;">HYPER-M Support Team</strong></p>
- </div></td>
- </tr>
- <tr>
- <td bgcolor="#4d90fe" style="line-height:1px;"> </td>
- </tr>
- </table></td>
- </tr>
- </table>';
- $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)
- {
- // try {
- // $url = $this->woohoo_url . $url;
- // //GET SETTING
- // $data['setting'] = 'REDEEM';
- // $redeem_set = globalfunc::getSiteSetting($parent, $data);
- // $insert_db = 0;
- // switch ($type) {
- // case 'status':
- // case 'order':
- // break;
- // case 'category':
- // $query_data = $parent->selectQuery(TABLE_WOOHOO_CATEGORY, "*", "modified_on>'" . date('Y-m', strtotime(NOW)) . "-01 00:00:00'", "1");
- // if ($query_data['nr']) {
- // if (strpos($query_data['result'][0]->category_data, 'API Partners') !== false) {
- // $query_data['result'][0]->category_data = @str_replace('API Partners', 'BRANDS', $query_data['result'][0]->category_data);
- // }
- // $return_data = json_decode(trim($query_data['result'][0]->category_data));
- // return $return_data;
- // } else {
- // $insert_db = 1;
- // }
- // break;
- // case 'category_product':
- // $cat_arr = @explode('category/', $url);
- // $ncat_arr = @explode('/products?', $cat_arr[1]);
- // $cat_id = $ncat_arr[0];
- // $query_data = $parent->selectQuery(TABLE_WOOHOO_CATEGORY_DETAILS, "*", "cat_id='" . $cat_id . "' AND modified_on>'" . date('Y-m', strtotime(NOW)) . "-01 00:00:00'", "1");
- // if ($query_data['nr']) {
- // if (strpos($query_data['result'][0]->category_data, 'API Partners') !== false) {
- // $query_data['result'][0]->category_data = @str_replace('API Partners', 'BRANDS', $query_data['result'][0]->category_data);
- // }
- // if (strpos($query_data['result'][0]->category_data, '/thumbnail') !== false) {
- // $query_data['result'][0]->category_data = @str_replace('/thumbnail', '/mobile', $query_data['result'][0]->category_data);
- // }
- // if (strtolower($parent->device_type) == 'web' && strpos($query_data['result'][0]->category_data, '/image') !== false) {
- // $query_data['result'][0]->category_data = @str_replace('/image', '/mobile', $query_data['result'][0]->category_data);
- // }
- // $return_data = json_decode(trim($query_data['result'][0]->category_data));
- // return $return_data;
- // } else {
- // $insert_db = 1;
- // }
- // break;
- // case 'product':
- // $product_arr = @explode('products/', $url);
- // $product_id = $product_arr[1];
- // $query_data = $parent->selectQuery(TABLE_WOOHOO_PRODUCT, "*", "product_id='" . $product_id . "' AND modified_on>'" . date('Y-m', strtotime(NOW)) . "-01 00:00:00'", "1");
- // if ($query_data['nr']) {
- // if (strpos($query_data['result'][0]->product_data, '/thumbnail') !== false) {
- // $query_data['result'][0]->product_data = @str_replace('/thumbnail', '/mobile', $query_data['result'][0]->product_data);
- // }
- // if (strtolower($parent->device_type) == 'web' && strpos($query_data['result'][0]->product_data, '/image') !== false) {
- // $query_data['result'][0]->product_data = @str_replace('/image', '/mobile', $query_data['result'][0]->product_data);
- // }
- // $return_data = json_decode(trim($query_data['result'][0]->product_data));
- // return $return_data;
- // } else {
- // $insert_db = 1;
- // }
- // break;
- // }
- // $requestHttpMethod = ($post) ? 'POST' : 'GET';
- // $requestBody = ($post) ? json_encode($post) : '';
- // // if ($post) {
- // // $requestBody = '{"address":{"firstname":"Jhon","lastname":"Deo","email":"jhon.deo@gmail.com","telephone":"+919004052509","line1":"C G MOTORS","line2":"Mumbai (Vashi)","city":"Mumbai (Vashi)","region":"Karnataka","country":"IN","postcode":"560076","billToThis":true},"billing":{"firstname":"Jhon ","lastname":"Deo","email":"jhon.deo@gmail.com","telephone":"+919004052509","line1":"C G MOTORS","line2":"Mumbai (Vashi)","city":"Mumbai (Vashi)","region":"Karnataka","country":"IN","postcode":"560076"},"payments":[{"code":"svc","amount":1000}],"refno":"00100000000abf","products":[{"sku":"CNPIN","price":1000,"qty":1,"currency":356,"giftMessage":"HYPER-M","theme":""}],"syncOnly":true,"couponCode":"","deliveryMode":"API"}';
- // // //$post = json_decode($post, false);
- // // }
- // $signature = hash_hmac('sha512', getConcatenateBaseString($url, $requestHttpMethod, $requestBody), WOOHOO_CONSUMERSECRET);
- // $datetime = new DateTime(NOW);
- // $datestamp = $datetime->format('c');
- // $authorization = "Authorization: Bearer " . $redeem_set->WOOHOO_OAUTH2_TOKEN;
- // $header = array("Cache-Control: no-cache", "Content-Type: application/json", $authorization, 'dateAtClient: ' . $datestamp, 'signature: ' . $signature);
- // //POST DATA
- // if ($post) {
- // $options = array(CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $requestBody, CURLOPT_HEADER => false, CURLOPT_HTTPHEADER => $header, CURLOPT_URL => $url, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 10, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
- // $request = $requestBody;
- // } else {
- // $options = array(CURLOPT_HTTPHEADER => $header,
- // CURLOPT_HEADER => false,
- // CURLOPT_URL => $url,
- // CURLOPT_CONNECTTIMEOUT => 10,
- // CURLOPT_TIMEOUT => 10,
- // CURLOPT_RETURNTRANSFER => true,
- // CURLOPT_SSL_VERIFYPEER => false);
- // $request = "";
- // }
- // //WOOHOO LOG
- // $parent->executeQuery("INSERT INTO " . TABLE_WOOHOO_LOG . "(`userid`, `url`, `request`,`created_on`) VALUES ( '" . $parent->current_user_id . "','" . $url . "','" . escape_str($request) . "','" . NOW . "')");
- // $logid = $parent->lastInsertId();
- // $ch = curl_init();
- // curl_setopt_array($ch, $options);
- // $response = curl_exec($ch);
- // $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- // curl_close($ch);
- // if ($response != '' && strpos($response, '/thumbnail') !== false) {
- // $response = @str_replace('/thumbnail', '/mobile', $response);
- // }
- // if ($response != '' && strtolower($parent->device_type) == 'web' && strpos($response, '/image') !== false) {
- // $response = @str_replace('/image', '/mobile', $response);
- // }
- // //CLIENT REQUEST
- // if (strpos($response, 'API Partners') !== false) {
- // $response = @str_replace('API Partners', 'BRANDS', $response);
- // }
- // $return_data = json_decode(trim($response));
- // //LOG RESPONSE
- // $parent->executeQuery("UPDATE " . TABLE_WOOHOO_LOG . " SET response='" . escape_str(trim($response)) . "' WHERE id='" . $logid . "'");
- // switch ($type) {
- // case 'status':
- // case 'order':
- // break;
- // case 'category':
- // if ($insert_db == '1') {
- // if (isset($return_data->id) && isset($return_data->name) && $return_data->id > 0) {
- // //DELETE OLD RECORD
- // $parent->executeQuery("TRUNCATE " . TABLE_WOOHOO_CATEGORY . " ");
- // //INSERT
- // $parent->executeQuery("INSERT INTO " . TABLE_WOOHOO_CATEGORY . " ( `category_data`, `created_on`, `modified_on`) VALUES ('" . escape_str(json_encode($return_data)) . "','" . NOW . "','" . NOW . "') ");}
- // }
- // break;
- // case 'category_product':
- // if ($insert_db == '1') {
- // if (isset($return_data->id) && isset($return_data->name) && $return_data->id > 0) {
- // //DELETE OLD RECORD
- // $parent->executeQuery("DELETE FROM " . TABLE_WOOHOO_CATEGORY_DETAILS . " WHERE cat_id='" . $cat_id . "'");
- // $parent->executeQuery("INSERT INTO " . TABLE_WOOHOO_CATEGORY_DETAILS . " (`cat_id`, `category_data`, `created_on`, `modified_on`) VALUES ('" . $cat_id . "','" . escape_str(json_encode($return_data)) . "','" . NOW . "','" . NOW . "') ");
- // }
- // }
- // break;
- // case 'product':
- // if ($insert_db == '1') {
- // if (isset($return_data->id) && isset($return_data->sku)) {
- // //DELETE OLD RECORD
- // $parent->executeQuery("DELETE FROM " . TABLE_WOOHOO_PRODUCT . " WHERE product_id='" . $product_id . "'");
- // $parent->executeQuery("INSERT INTO " . TABLE_WOOHOO_PRODUCT . " (`product_id`, `product_data`, `created_on`, `modified_on`) VALUES ('" . $product_id . "','" . escape_str(json_encode($return_data)) . "','" . NOW . "','" . NOW . "') ");
- // }
- // }
- // break;
- // }
- // return $return_data;
- // } catch (Exception $e) {
- // $parent->response(array('response' => 'failed', 'message' => $e->getMessage()), 500);
- // exit;
- // }
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- /* /////////////////////////////// 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 '<pre>';
- // print_r($return_data);
- // echo '</pre>';
- $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 = '<table width="100%" bgcolor="#dfdfdf" border="0" cellspacing="10" cellpadding="0" style="padding-top:10px;">
- <tbody><tr>
- <td><table width="700" border="0" align="center" cellpadding="0" cellspacing="0" style="background:#ffffff; margin-top:0px;">
- <tbody><tr>
- <td bgcolor="#2d2d2d" height="36" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; color:#e4e4e4; text-align:left; font-weight:bold; padding-left:14px; border-bottom:2px solid black">HYPER-M - WOOHOO API LOW BALANCE</td>
- </tr>
- <tr><td><table width="85%" align="center">
- <tbody> <tr><td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
- line-height: 1.5;"><div style="font-family:arial; color:#333; font-size:12px; padding:5px;" >Woohoo api balance is below 25000. <br>Balance Available : ' . $order_data->payments[0]->balance . '</div></td>
- </tr>
- </tbody></table>
- </td>
- </tr>
- <tr>
- <td style="padding-top:0px; padding-bottom:10px;"></td>
- </tr>
- <tr>
- <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#3f3f3f; background:#fafafa; line-height:30px; text-align:center;border-bottom:2px solid black"><div class="footer-con">
- <p>Thanks & Regards, <strong style="color:black;"> Support Team</strong></p>
- </div></td>
- </tr>
- </tbody></table></td>
- </tr>
- </tbody></table>';
- $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);
- }
- }
- /* //////////////////////////////////////////////////////////////////////////////////////////// */
- }
|