Example #1
0
 public function order($oID)
 {
     $order = StoreOrder::getByID($oID);
     $this->set("order", $order);
     $this->set('orderStatuses', StoreOrderStatus::getList());
     $this->requireAsset('javascript', 'vividStoreFunctions');
 }
 private static function recordStatusChange(StoreOrder $order, $statusHandle)
 {
     $db = Database::get();
     $newOrderStatus = StoreOrderStatus::getByHandle($statusHandle);
     $user = new user();
     $statusHistorySql = "INSERT INTO " . self::$table . " SET oID=?, oshStatus=?, uID=?";
     $statusHistoryValues = array($order->getOrderID(), $newOrderStatus->getHandle(), $user->uID);
     $db->Execute($statusHistorySql, $statusHistoryValues);
     $updateOrderSql = "UPDATE VividStoreOrders SET oStatus = ? WHERE oID = ?";
     $updateOrderValues = array($newOrderStatus->getHandle(), $order->getOrderID());
     $db->Execute($updateOrderSql, $updateOrderValues);
     return $newOrderStatus->getHandle();
 }
Example #3
0
 public static function installOrderStatuses(Package $package)
 {
     $table = StoreOrderStatus::getTableName();
     $db = Database::get();
     $statuses = array(array('osHandle' => 'incomplete', 'osName' => t('Incomplete'), 'osInformSite' => 1, 'osInformCustomer' => 0, 'osIsStartingStatus' => 0), array('osHandle' => 'pending', 'osName' => t('Pending'), 'osInformSite' => 1, 'osInformCustomer' => 1, 'osIsStartingStatus' => 1), array('osHandle' => 'processing', 'osName' => t('Processing'), 'osInformSite' => 1, 'osInformCustomer' => 1, 'osIsStartingStatus' => 0), array('osHandle' => 'shipped', 'osName' => t('Shipped'), 'osInformSite' => 1, 'osInformCustomer' => 1, 'osIsStartingStatus' => 0), array('osHandle' => 'complete', 'osName' => t('Complete'), 'osInformSite' => 1, 'osInformCustomer' => 1, 'osIsStartingStatus' => 0));
     foreach ($statuses as $status) {
         $row = $db->GetRow("SELECT * FROM " . $table . " WHERE osHandle=?", array($status['osHandle']));
         if (!isset($row['osHandle'])) {
             StoreOrderStatus::add($status['osHandle'], $status['osName'], $status['osInformSite'], $status['osInformCustomer'], $status['osIsStartingStatus']);
         } else {
             $orderStatus = StoreOrderStatus::getByID($row['osID']);
             $orderStatus->update($status, true);
         }
     }
 }
 public static function validateCompletion()
 {
     // Read POST data
     // reading posted data directly from $_POST causes serialization
     // issues with array data in POST. Reading raw POST data from input stream instead.
     $raw_post_data = file_get_contents('php://input');
     $raw_post_array = explode('&', $raw_post_data);
     $myPost = array();
     foreach ($raw_post_array as $keyval) {
         $keyval = explode('=', $keyval);
         if (count($keyval) == 2) {
             $myPost[$keyval[0]] = urldecode($keyval[1]);
         }
     }
     // read the post from PayPal system and add 'cmd'
     $req = 'cmd=_notify-validate';
     if (function_exists('get_magic_quotes_gpc')) {
         $get_magic_quotes_exists = true;
     }
     foreach ($myPost as $key => $value) {
         if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
             $value = urlencode(stripslashes($value));
         } else {
             $value = urlencode($value);
         }
         $req .= "&{$key}={$value}";
     }
     // Post IPN data back to PayPal to validate the IPN data is genuine
     // Without this step anyone can fake IPN data
     if (Config::get('vividstore.paypalTestMode') == true) {
         $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
     } else {
         $paypal_url = "https://www.paypal.com/cgi-bin/webscr";
     }
     $ch = curl_init($paypal_url);
     if ($ch == false) {
         return false;
     }
     curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
     if (DEBUG == true) {
         curl_setopt($ch, CURLOPT_HEADER, 1);
         curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
     }
     // CONFIG: Optional proxy configuration
     //curl_setopt($ch, CURLOPT_PROXY, $proxy);
     //curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
     // Set TCP timeout to 30 seconds
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
     // CONFIG: Please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
     // of the certificate as shown below. Ensure the file is readable by the webserver.
     // This is mandatory for some environments.
     //$cert = __DIR__ . "./cacert.pem";
     //curl_setopt($ch, CURLOPT_CAINFO, $cert);
     $res = curl_exec($ch);
     if (curl_errno($ch) != 0) {
         // cURL error
         Log::addEntry("Can't connect to PayPal to validate IPN message: " . curl_error($ch));
         curl_close($ch);
         exit;
     } else {
         //if we want to log more stuff
         //Log::addEntry("HTTP request of validation request:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." for IPN payload: $req");
         //Log::addEntry("HTTP response of validation request: $res");
         curl_close($ch);
     }
     // Inspect IPN validation result and act accordingly
     // Split response headers and payload, a better way for strcmp
     $tokens = explode("\r\n\r\n", trim($res));
     $res = trim(end($tokens));
     if (strcmp($res, "VERIFIED") == 0) {
         $order = StoreOrder::getByID($_POST['invoice']);
         $order->completeOrder($_POST['txn_id']);
         $order->updateStatus(StoreOrderStatus::getStartingStatus()->getHandle());
     } elseif (strcmp($res, "INVALID") == 0) {
         // log for manual investigation
         // Add business logic here which deals with invalid IPN messages
         Log::addEntry("Invalid IPN: {$req}");
     }
 }
Example #5
0
 public static function installOrderStatuses(Package $package)
 {
     $statuses = array(array('osHandle' => 'incomplete', 'osName' => t('Incomplete'), 'osInformSite' => 1, 'osInformCustomer' => 0, 'osIsStartingStatus' => 0), array('osHandle' => 'pending', 'osName' => t('Pending'), 'osInformSite' => 1, 'osInformCustomer' => 1, 'osIsStartingStatus' => 1), array('osHandle' => 'processing', 'osName' => t('Processing'), 'osInformSite' => 1, 'osInformCustomer' => 1, 'osIsStartingStatus' => 0), array('osHandle' => 'shipped', 'osName' => t('Shipped'), 'osInformSite' => 1, 'osInformCustomer' => 1, 'osIsStartingStatus' => 0), array('osHandle' => 'complete', 'osName' => t('Complete'), 'osInformSite' => 1, 'osInformCustomer' => 1, 'osIsStartingStatus' => 0));
     foreach ($statuses as $status) {
         $orderStatus = StoreOrderStatus::getByHandle($status['osHandle']);
         if (!is_object($orderStatus)) {
             StoreOrderStatus::add($status['osHandle'], $status['osName'], $status['osInformSite'], $status['osInformCustomer'], $status['osIsStartingStatus']);
         }
     }
 }
Example #6
0
 private function saveOrderStatuses($data)
 {
     if (isset($data['osID'])) {
         foreach ($data['osID'] as $key => $id) {
             $orderStatus = StoreOrderStatus::getByID($id);
             $orderStatusSettings = array('osName' => isset($data['osName'][$key]) && $data['osName'][$key] != '' ? $data['osName'][$key] : $orderStatus->getReadableHandle(), 'osInformSite' => isset($data['osInformSite'][$key]) ? 1 : 0, 'osInformCustomer' => isset($data['osInformCustomer'][$key]) ? 1 : 0, 'osSortOrder' => $key);
             $orderStatus->update($orderStatusSettings);
         }
         if (isset($data['osIsStartingStatus'])) {
             StoreOrderStatus::setNewStartingStatus(StoreOrderStatus::getByID($data['osIsStartingStatus'])->getHandle());
         } else {
             $orderStatuses = StoreOrderStatus::getAll();
             StoreOrderStatus::setNewStartingStatus($orderStatuses[0]->getHandle());
         }
     }
 }
Example #7
0
 public function update($data = array(), $ignoreFilledColumns = false)
 {
     $orderStatusArray = array('osHandle' => $this->osHandle, 'osName' => $this->osName, 'osInformSite' => $this->osInformSite, 'osInformCustomer' => $this->osInformCustomer, 'osSortOrder' => $this->osSortOrder);
     $startingStatusHandle = null;
     if (isset($data['osIsStartingStatus'])) {
         $startingStatusHandle = $this->osHandle;
     }
     $orderStatusUpdateColumns = $ignoreFilledColumns ? array_diff($orderStatusArray, $data) : array_merge($orderStatusArray, $data);
     unset($orderStatusUpdateColumns['osID']);
     if (count($orderStatusUpdateColumns) > 0) {
         $columnPhrase = implode('=?, ', array_keys($orderStatusUpdateColumns)) . "=?";
         $values = array_values($orderStatusUpdateColumns);
         $values[] = $this->osID;
         Database::get()->Execute("UPDATE " . self::getTableName() . " SET " . $columnPhrase . " WHERE osID=?", $values);
         if ($startingStatusHandle) {
             OrderStatus::setNewStartingStatus($startingStatusHandle);
         }
         return true;
     }
     return false;
 }
Example #8
0
 public function updateStatus($status = null)
 {
     if ($status) {
         StoreOrderStatusHistory::updateOrderStatusHistory($this, $status);
     } else {
         StoreOrderStatusHistory::updateOrderStatusHistory($this, StoreOrderStatus::getStartingStatus()->getHandle());
     }
 }
 public function getOrderStatus()
 {
     return StoreOrderStatus::getByHandle($this->getOrderStatusHandle());
 }
Example #10
0
 private function saveOrderStatuses($data)
 {
     if (isset($data['osID'])) {
         if ($data['osIsStartingStatus']) {
             $existingStartingStatus = StoreOrderStatus::getStartingStatus();
             if (is_object($existingStartingStatus)) {
                 $existingStartingStatus->setIsStartingStatus(false);
                 $existingStartingStatus->save();
             }
         }
         foreach ($data['osID'] as $key => $id) {
             $orderStatus = StoreOrderStatus::getByID($id);
             if (isset($data['osName'][$key]) && $data['osName'][$key] != '') {
                 $orderStatus->setName($data['osName'][$key]);
             } else {
                 $orderStatus->setName($orderStatus->getReadableHandle());
             }
             $orderStatus->setInformSite(isset($data['osInformSite'][$key]) ? 1 : 0);
             $orderStatus->setInformCustomer(isset($data['osInformCustomer'][$key]) ? 1 : 0);
             $orderStatus->setSortOrder($key);
             if ($data['osIsStartingStatus'] == $id) {
                 $orderStatus->setIsStartingStatus(true);
             }
             $orderStatus->save();
         }
     }
 }