示例#1
0
 /**
  * function to store redeem point for user
  *
  * @param referral_code
  */
 public function store()
 {
     /* get for redirect route to */
     $to = Input::get('to');
     /* array parameter to API */
     $data = ['user_id' => Session::get('whoami')['id'], 'code' => Input::get('referral_code')];
     $APIUser = new APIUser();
     $result = $APIUser->postMeRedeemCode($data);
     if (isset($result['message'])) {
         $this->errors = $result['message'];
     } else {
         $this->page_attributes->success = 'Selamat anda poin Anda menjadi ' . $result['data']['total_point'];
     }
     return $this->generateRedirectRoute($to);
 }
 /**
  * function to sign up by invitation
  *
  * @param object view
  */
 public function post($code = "", $link = "")
 {
     if (preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\\.browser|up\\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"])) {
         $dob = Carbon::createFromFormat('Y-m-d', Input::get('date_of_birth'))->format('Y-m-d H:i:s');
     } else {
         $dob = Carbon::createFromFormat('d-m-Y', Input::get('date_of_birth'))->format('Y-m-d H:i:s');
     }
     $data = ['id' => '', 'name' => Input::get('name'), 'email' => Input::get('email'), 'password' => Input::get('password'), 'date_of_birth' => $dob, 'gender' => Input::get('gender'), 'role' => 'customer', 'reference_code' => $code, 'invitation_link' => $link];
     if (Input::has('password')) {
         $validator = Validator::make(Input::only('password', 'password_confirmation'), ['password' => 'required|min:8|confirmed']);
         if (!$validator->passes()) {
             $this->errors = $validator->errors();
             $type = 'signup';
         }
     }
     Session::set('API_token', Session::get('API_token_public'));
     // API User
     $API_user = new APIUser();
     $user = $API_user->postDataSignUp($data);
     if ($user['status'] != 'success') {
         $this->errors = $user['message'];
         $type = 'signup';
     } else {
         $infos = [];
         foreach ($this->balin['info'] as $key => $value) {
             $infos[$value['type']] = $value['value'];
         }
         $infos['action'] = route(env('ROUTE_BALIN_CLAIM_VOUCHER'), $user['data']['activation_link']);
         $mail = new APISendMail();
         $result = $mail->welcomemail($user['data'], $infos);
         if (isset($result['message'])) {
             $this->errors = $result['message'];
             $type = 'signup';
         }
         $type = 'login';
     }
     $this->page_attributes->success = "Terima kasih sudah mendaftar, Balin telah mengirimkan hadiah selamat datang untuk Anda melalui email Anda.";
     return $this->generateRedirectRoute('balin.get.login', ['type' => $type]);
 }
示例#3
0
 /**
  * function to resend invoice only order status 'wait'
  */
 public function resend_invoice($id = null)
 {
     //1. Get order detail
     $APIUser = new APIUser();
     $order = $APIUser->getMeOrderDetail(['user_id' => Session::get('whoami')['id'], 'order_id' => $id]);
     //2. Check order
     if ($order['status'] != 'success') {
         $this->errors = $order['message'];
     } else {
         $infos = [];
         foreach ($this->balin['info'] as $key => $value) {
             $infos[$value['type']] = $value['value'];
         }
         $mail = new APISendMail();
         $result = $mail->invoice($order['data'], $infos);
         // if (isset($result['message']))
         // {
         // 	$this->errors					= $result['message'];
         // }
     }
     $this->page_attributes->success = "Resend invoice terkirim.";
     return $this->generateRedirectRoute('my.balin.profile');
 }
 /**
  * function to store invitation for others
  *
  * @param referral_code
  */
 public function store()
 {
     /* get for redirect route to */
     $APIUser = new APIUser();
     $whoami = $APIUser->getMeDetail(['user_id' => Session::get('whoami')['id']]);
     $invitations = [];
     $emails = explode(',', Input::get('emails'));
     $rules = ['email' => 'required|email|max:255'];
     foreach ($emails as $key => $value) {
         $invitation['email'] = trim($value);
         $validator = Validator::make($invitation, $rules);
         if (!$validator->passes()) {
             $this->errors = ['Email "' . $invitation['email'] . '" tidak sah'];
             return $this->generateRedirectRoute('my.balin.redeem.index');
         }
         $invitations[] = $invitation['email'];
     }
     /* array parameter to API */
     $data = ['user_id' => Session::get('whoami')['id'], 'invitations' => $emails];
     $result = $APIUser->postMeInvitation($data);
     if (isset($result['message'])) {
         $this->errors = $result['message'];
     } else {
         $infos = [];
         foreach ($this->balin['info'] as $key => $value) {
             $infos[$value['type']] = $value['value'];
         }
         $infos['action'] = route(env('ROUTE_BALIN_INVITATION_GET'), $whoami['data']['code_referral']);
         $mail = new APISendMail();
         $result = $mail->invitation($whoami['data'], $emails, $infos);
         if (isset($result['message'])) {
             $this->errors = $result['message'];
         }
         $this->page_attributes->success = 'Anda telah mengirimkan  ' . count($emails) . ' undangan kepada teman Anda';
     }
     return $this->generateRedirectRoute('my.balin.redeem.index');
 }
示例#5
0
 /**
  * function to store an item to cart or transaction detail
  *
  * 1. Parsing data
  * 2. Check quantity of varian
  * 3. Check logged user
  * 4. return data
  * @param current cart, changes product, changes qty, changes varian
  */
 function addToCart($temp_carts, $product, $qtys, $varianids)
 {
     //1. Parsing data
     $errors = new MessageBag();
     //2. Check quantity of varian
     foreach ($varianids as $key => $value) {
         //2a. get valid quantity of varian
         if (isset($qtys[$value]) && $qtys[$value] != 0 && isset($temp_carts[$product['id']]['varians'][$value])) {
             $validqty = $qtys[$value];
         } elseif (isset($temp_carts[$product['id']]['varians'][$value]) && $qtys[$value] != 0) {
             $validqty = $temp_carts[$product['id']]['varians'][$value]['quantity'];
         } else {
             $validqty = $qtys[$value];
         }
         //2b. collect varian from product
         foreach ($product['varians'] as $key2 => $value2) {
             if ($value2['id'] == $value) {
                 $varianp = $value2;
             }
         }
         //2c. check varian stock
         if (isset($varianp)) {
             if ($varianp['current_stock'] < $validqty || $varianp['current_stock'] == 0) {
                 $errors->add('Stock', $product['name'] . ' tidak tersedia dalam ukuran ' . $varianp['size'] . '.');
             }
         }
         // else
         // {
         // 	$errors->add('Stock', $product['name']. ' tidak tersedia dalam ukuran yang dicari.');
         // }
         //2d. parsing detail
         if (!$errors->count() && $validqty != 0 && isset($varianp)) {
             if (!isset($temp_carts[$product['id']])) {
                 $temp_carts[$product['id']] = $product;
                 $temp_carts[$product['id']]['discount'] = $product['promo_price'] != 0 ? $product['price'] - $product['promo_price'] : 0;
                 unset($temp_carts[$product['id']]['varians']);
             }
             $temp_carts[$product['id']]['varians'][$varianp['id']] = ['varian_id' => $varianp['id'], 'sku' => $varianp['sku'], 'quantity' => $validqty, 'size' => $varianp['size'], 'current_stock' => $varianp['current_stock']];
         } elseif (!$errors->count() && $validqty == 0 && isset($temp_carts[$product['id']]) && isset($varianp)) {
             unset($temp_carts[$product['id']]['varians'][$varianp['id']]);
         }
     }
     // Check if temp carts is 0 to flash session carts
     if (count($temp_carts) == 0) {
         Session::flash('carts', 'remove carts');
     } elseif (count($temp_carts[$product['id']]['varians']) == 0) {
         unset($temp_carts[$product['id']]);
     }
     //3. Check logged user
     if (Session::has('whoami') && !$errors->count()) {
         //3a. Check cart
         $APIUser = new APIUser();
         $order_in_cart = $APIUser->getMeOrderInCart(['user_id' => Session::get('whoami')['id']]);
         if ($order_in_cart['status'] != 'success') {
             $order['id'] = '';
             $order['transactiondetails'] = [];
         } else {
             $order['id'] = $order_in_cart['data']['id'];
             $order['voucher_id'] = $order_in_cart['data']['voucher_id'];
             $order['transactiondetails'] = $order_in_cart['data']['transactiondetails'];
         }
         $order_detail = [];
         //3b. Check transactiondetail
         foreach ($temp_carts as $key => $value) {
             foreach ($value['varians'] as $key2 => $value2) {
                 $id = '';
                 foreach ($order['transactiondetails'] as $key3 => $value3) {
                     if ($value3['varian_id'] == $value2['varian_id']) {
                         $id = $value3['id'];
                     } else {
                         $id = '';
                     }
                 }
                 $varian = ['id' => $id, 'varian_id' => $value2['varian_id'], 'quantity' => $value2['quantity'], 'price' => $value['price'], 'discount' => $value['discount']];
                 $order_detail[] = $varian;
             }
         }
         if (empty($temp_carts)) {
             foreach ($order['transactiondetails'] as $keyx => $valuex) {
                 $valuex['quantity'] = 0;
                 $order_detail[] = $valuex;
             }
         }
         $order['transactiondetails'] = $order_detail;
         $order['status'] = 'cart';
         $order['user_id'] = Session::get('whoami')['id'];
         //3c. Store cart
         $result = $APIUser->postMeOrder($order);
         //3d. check result
         if (isset($result['message'])) {
             $errors->add('Cart', $result['message']);
         }
     }
     //4. return data
     if ($errors->count()) {
         return ['status' => false, 'data' => $temp_carts, 'message' => $errors];
     }
     return ['status' => true, 'data' => $temp_carts];
 }
示例#6
0
 /**
  * function to resend activation mail
  * 
  * @return redirect
  */
 public function activation()
 {
     //1. Get Me
     $APIUser = new APIUser();
     $whoami = $APIUser->getMeDetail(['user_id' => Session::get('whoami')['id']]);
     //2. Whoami
     if (!$whoami['data']['is_active'] && $whoami['data']['activation_link'] != '') {
         $infos = [];
         foreach ($this->balin['info'] as $key => $value) {
             $infos[$value['type']] = $value['value'];
         }
         $infos['action'] = route(env('ROUTE_BALIN_CLAIM_VOUCHER'), $whoami['data']['activation_link']);
         $mail = new APISendMail();
         $result = $mail->welcomemail($whoami['data'], $infos);
         if (isset($result['message'])) {
             $this->errors = $result['message'];
         }
     } else {
         $this->errors = 'Akun anda sudah di aktivasi.';
     }
     $this->page_attributes->success = "Email aktivasi sudah dikirim.";
     return $this->generateRedirectRoute('my.balin.profile');
 }
 /**
  * function to inform failed payment
  * 
  * @return redirect url
  */
 public function vtunfinish()
 {
     //1. Ambil data order detail dari API
     $APIUser = new APIUser();
     $order = $APIUser->getMeOrderRef(['user_id' => Session::get('whoami')['id'], 'ref_number' => Input::get('order_id')]);
     if ($order['status'] != 'success') {
         \App::abort(404);
     }
     Session::forget('carts');
     $this->errors = ["Pembayaran Anda sudah gagal tersimpan, Silahkan mencoba lagi atau membayar dengan opsi pembayaran lainnya."];
     return $this->generateRedirectRoute('my.balin.profile', ['order_id' => $order['data']['id']]);
 }
 /**
  * function to post reseted password
  *
  * @param new password
  */
 public function change()
 {
     /* set api token use token public */
     Session::set('API_token', Session::get('API_token_public'));
     $breadcrumb = ['Reset Password' => ''];
     if (Input::has('password')) {
         $rules = ['password' => 'min:8|confirmed'];
         $validator = Validator::make(Input::only('password', 'password_confirmation'), $rules);
         if (!$validator->passes()) {
             return Redirect::route('balin.home.index')->withErrors($validator->errors())->with('msg-type', 'danger');
         }
         $password = Input::get('password');
     } else {
         \App::abort(404);
     }
     $email = Session::get('reset_password_mail');
     $API_me = new APIUser();
     $result = $API_me->postChangePassword(['email' => $email, 'password' => $password]);
     if (isset($result['message'])) {
         return Redirect::route('balin.home.index')->withErrors($result['message'])->with('msg-type', 'danger');
     } else {
         $this->page_attributes->data = ['me' => $result['data']];
         $this->page_attributes->subtitle = 'Reset Password';
         $this->page_attributes->breadcrumb = array_merge($breadcrumb);
         $this->page_attributes->source = 'web_v2.pages.profile.password.changed';
         return $this->generateView();
     }
 }
示例#9
0
 /**
  * function to activate user account
  *
  * @param activation link
  */
 public function getActive($activation_link = null)
 {
     $breadcrumb = ['Aktivasi' => ''];
     /* set api token use token public */
     Session::set('API_token', Session::get('API_token_public'));
     $API_me = new APIUser();
     $result = $API_me->postActivationLink(['link' => $activation_link]);
     if (isset($result['message'])) {
         return Redirect::route('balin.home.index');
     } else {
         $this->page_attributes->data = ['me' => $result['data']];
         $this->page_attributes->subtitle = 'Aktivasi';
         $this->page_attributes->breadcrumb = array_merge($breadcrumb);
         $this->page_attributes->source = 'web_v2.pages.profile.activation.index';
         return $this->generateView();
     }
 }