public function shoppingcart()
 {
     if (isset($_POST['first_name'])) {
         $app = new \iSDK();
         if ($app->cfgCon("connectionName")) {
             $qry = array('Email' => $_POST['emailAddress']);
             $ret = array("Id");
             $dups = $app->dsQuery("Contact", 1, 0, $qry, $ret);
             if (empty($dups)) {
                 $contact = array("FirstName" => $_POST['first_name'], "LastName" => $_POST['last_name'], "State" => $_POST['state'], "Phone1" => $_POST['phoneNumber'], "City" => $_POST['city'], "Email" => $_POST['emailAddress'], "Address1Type" => $_POST['addressLine1'], "ZipFour1" => $_POST['last_name'], "Country" => $_POST['last_name'], "Company" => $_POST['company']);
                 $date = date('d/m/y');
                 $cid = $app->addCon($contact);
             } else {
                 $cid = $dups[0]['Id'];
                 $contact = array("FirstName" => $_POST['first_name'], "LastName" => $_POST['last_name'], "State" => $_POST['state'], "Phone1" => $_POST['phoneNumber'], "City" => $_POST['city'], "Email" => $_POST['emailAddress'], "Address1Type" => $_POST['addressLine1'], "ZipFour1" => $_POST['last_name'], "Country" => $_POST['last_name'], "Company" => $_POST['company']);
                 $contact_ID = $app->updateCon($cid, $contact);
             }
             $fullname = explode(" ", $_POST['nameoncard']);
             $card['FirstName'] = $fullname[0];
             $card['LastName'] = $fullname[1];
             $card['CardNumber'] = $_POST['cnumber'];
             $card['ExpirationMonth'] = $_POST['cardmonth'];
             $card['ExpirationYear'] = $_POST['cardyear'];
             $card['CVV2'] = $_POST['CVV'];
             $result = $app->validateCard($card);
             if ($result['Valid'] == 'false') {
                 $msg = "Order cancel due to credit card";
                 return view('licenses.shoppingcart', compact('msg'));
             } else {
                 $ccid = $app->dsAdd("CreditCard", $card);
                 //$timezone = new DateTimeZone( "America/New_York" );
                 //$date = new DateTime();
                 //$date->setTimezone( $timezone );
                 $currentDate = date('Y-m-d H:i:s');
                 $oDate = $app->infuDate($currentDate);
                 try {
                     $invID = $app->blankOrder($cid, "Order for Licenses" . $cid, $oDate, 0, 0);
                 } catch (Exception $e) {
                     echo 'Caught exception: ', $e->getMessage(), "\n";
                 }
                 $ord = $app->getOrderId($invID);
                 $Quantity = $_POST['Quantity'];
                 $subID = array();
                 for ($i = 1; $i <= $Quantity; $i++) {
                     $app->addOrderItem((int) $invID, (int) 50, (int) 4, (double) 0.1, (int) 1, 'Licenses Item' . $i, '');
                     $_intproductid = $app->addRecurringAdv((int) $cid, true, (int) 34, (int) 1, (double) 0.1, false, (int) 2, (int) $ccid, (int) 0, (int) 30);
                     $_nextBillDate = date("d-m-Y", strtotime("1 Months + 1 day"));
                     $subID[$i] = $_intproductid;
                     $thedate = $app->infuDate($_nextBillDate);
                     $app->updateSubscriptionNextBillDate($_intproductid, $thedate);
                     $service["Frequency"] = 1;
                     $service["BillingCycle"] = 2;
                     $app->dsUpdate("RecurringOrder", $_intproductid, $service);
                 }
                 $payStat = $app->chargeInvoice((int) $invID, "Payment Via API", (int) $ccid, (int) 2, false);
                 if (substr($payStat['Message'], 0, 2) == "91") {
                     $payStat = $app->chargeInvoice((int) $invID, "Payment Via API", (int) $ccid, (int) 2, false);
                 }
                 if ($payStat['RefNum'] != "E" && $payStat['Code'] == "APPROVED") {
                     $msg = "Thanks For Order";
                     $user_id = Auth::user()->id;
                     $users = User::findOrFail($user_id);
                     for ($i = 1; $i <= $Quantity; $i++) {
                         $date = new \DateTime();
                         $license = new License();
                         $license->life = 1;
                         $license->license_key = $subID[$i];
                         $license->company_id = $users->company_id;
                         $license->user_id = 0;
                         $license->status = 'ACTIVE';
                         $license->created_by = Auth::user()->id;
                         $license->created_at = $date;
                         $license->updated_at = $date;
                         $license->save();
                     }
                     return view('licenses.shoppingcart', compact('msg'));
                 } else {
                     $msg = "Order cancel due payment";
                     return view('licenses.shoppingcart', compact('msg'));
                 }
             }
         }
     }
     $msg = "";
     return view('licenses.shoppingcart', compact('msg'));
 }
 public function save()
 {
     if (Auth::check()) {
         $title = Request::input('title');
         $body = Request::input('body');
         $public = Request::input('public');
         $type = Request::input('type');
         $teams = Request::input('teams');
         $license = Request::input('license');
         $identifier_dict = Request::input('identifier');
         $anchor = Request::input('anchor');
         $entry_id = Request::input('entry_id');
         $user = Auth::user();
         if ($title !== '' && $body !== '' && $type !== '' && !empty($identifier_dict) && $anchor !== '') {
             $db_license = NULL;
             if ($public) {
                 if (isset($_ENV['AUTH_LICENSES']) && $_ENV['AUTH_LICENSES']) {
                     if (empty($license)) {
                         return json_encode(['status' => 'error', 'message' => 'Only paid users can create public annotations']);
                     }
                     $json_license = json_encode($license);
                     $db_license = License::where('license', '=', $json_license)->first();
                     if ($db_license) {
                         if ($db_license->banned_from_public) {
                             if (isset($license['is_beta']) && $license['is_beta']) {
                                 return json_encode(['status' => 'error', 'message' => "Beta users can't make public annotations"]);
                             }
                             return json_encode(['status' => 'error', 'message' => 'You are banned from making public annotations']);
                         }
                     } else {
                         if (isset($license['is_beta']) && $license['is_beta']) {
                             // skip check for beta users
                         } else {
                             if (isset($license['is_app_store']) && $license['is_app_store']) {
                                 if (!DashLicenseUtil::check_itunes_receipt($license)) {
                                     return json_encode(['status' => 'error', 'message' => 'Invalid license. Public annotation not allowed']);
                                 }
                             } else {
                                 if (!DashLicenseUtil::check_license($license)) {
                                     return json_encode(['status' => 'error', 'message' => 'Invalid license. Public annotation not allowed']);
                                 }
                             }
                         }
                         $db_license = new License();
                         $db_license->license = $json_license;
                         $db_license->save();
                     }
                 }
             }
             $identifier = Identifier::IdentifierFromDictionary($identifier_dict);
             $db_identifier = $identifier->find_in_db();
             if (!$db_identifier) {
                 $identifier->save();
                 $db_identifier = $identifier;
             }
             if ($public && $db_identifier->banned_from_public) {
                 return json_encode(['status' => 'error', 'message' => 'Public annotations are not allowed on this page']);
             }
             $entry = $entry_id ? Entry::where('id', '=', $entry_id)->first() : new Entry();
             if ($entry_id && (!$entry || $entry->user_id != $user->id)) {
                 return json_encode(['status' => 'error', 'message' => 'Error. Logout and try again']);
             }
             $entry->title = $title;
             $entry->body = $body;
             try {
                 $body = MarkdownExtra::defaultTransform($body);
             } catch (\RuntimeException $e) {
                 $message = $e->getMessage();
                 $start = strpos($message, 'no lexer for alias \'');
                 if ($start !== FALSE) {
                     $start += 20;
                     $end = strpos($message, '\'', $start);
                     if ($end !== FALSE) {
                         $lexer = substr($message, $start, $end - $start);
                         return json_encode(['status' => 'error', 'message' => 'Unknown syntax highlighting: ' . $lexer]);
                     }
                 }
                 throw $e;
             }
             $html_safe = new HTML_Safe();
             $html_safe->protocolFiltering = 'black';
             $body = $html_safe->parse($body);
             $body = str_replace('#dashInternal', '#', $body);
             $entry->body_rendered = $body;
             $entry->public = $public;
             $entry->type = $type;
             $entry->anchor = $anchor;
             $entry->user_id = $user->id;
             $entry->identifier_id = $db_identifier->id;
             if ($db_license) {
                 $entry->license_id = $db_license->id;
             }
             if (!$entry_id) {
                 $entry->score = 1;
             }
             $entry->save();
             if (!$entry_id) {
                 $vote = new Vote();
                 $vote->type = 1;
                 $vote->user_id = $user->id;
                 $vote->entry_id = $entry->id;
                 $vote->save();
             }
             $db_teams = $entry->teams();
             $already_assigned = array();
             foreach ($db_teams->get() as $team) {
                 if (!in_arrayi($team->name, $teams)) {
                     $db_teams->detach($team->id);
                 } else {
                     $already_assigned[] = $team->name;
                 }
             }
             foreach ($teams as $team) {
                 if (!in_arrayi($team, $already_assigned)) {
                     $db_team = Team::where('name', '=', $team)->first();
                     if ($db_team && $db_team->users()->where('user_id', '=', $user->id)->first()) {
                         $db_team->entries()->attach($entry->id);
                     }
                 }
             }
             return json_encode(['status' => 'success', 'entry' => $entry]);
         }
         return json_encode(['status' => 'error', 'message' => 'Oops. Unknown error']);
     }
     return json_encode(['status' => 'error', 'message' => 'Error. Logout and try again']);
 }