public function payment($data, $order_data, $auto_submit = false)
 {
     $data['order_id'] = $order_data['order_id'];
     if ($order_data['currency_id'] != 'USD') {
         throw new waPaymentException(_w('Order currency is not USD but payment gateway provide only USD transactions'));
     }
     $type_trans = array_flip(self::$type_trans);
     if (!empty($data['type']) && !empty($type_trans[$data['type']])) {
         $type = $type_trans[$data['type']];
     } else {
         $type = self::OPERATION_AUTH_ONLY;
     }
     if (empty($order_data['description_en'])) {
         $order_data['description_en'] = 'Order #' . $order_data['order_id'] . ' (' . gmdate('F, d Y') . ')';
     }
     $c = new waContact($order_data['contact_id']);
     $locale = $c->getLocale();
     $form_fields = array('x_login' => $this->login, 'x_amount' => number_format($order_data['amount'], 2, '.', ''), 'x_description' => $order_data['description_en'], 'x_invoice_num' => $order_data['order_id'], 'x_fp_sequence' => rand(1, 1000), 'x_fp_timestamp' => time(), 'x_test_request' => 'false', 'x_show_form' => 'PAYMENT_FORM', 'x_type' => $type, 'x_version' => '3.1', 'x_method' => 'CC', 'x_cust_id' => $order_data['contact_id'], 'x_customer_ip' => wa()->getRequest()->server('REMOTE_ADDR'), 'x_duplicate_window' => '28800', 'x_first_name' => waLocale::transliterate($c->get('firstname'), $locale), 'x_last_name' => waLocale::transliterate($c->get('lastname'), $locale), 'x_company' => waLocale::transliterate($c->get('company'), $locale), 'x_address' => waLocale::transliterate($c->get('address:street', 'default'), $locale), 'x_city' => waLocale::transliterate($c->get('address:city', 'default'), $locale), 'x_state' => waLocale::transliterate($c->get('address:region', 'default'), $locale), 'x_zip' => waLocale::transliterate($c->get('address:zip', 'default'), $locale), 'x_country' => waLocale::transliterate($c->get('address:country', 'default'), $locale), 'x_phone' => $c->get('phone', 'default'), 'x_email' => $c->get('email', 'default'), 'x_relay_response' => isset($data['x_relay_response']) ? $data['x_relay_response'] : 'true', 'x_relay_url' => $this->getRelayUrl(), 'wa_success_url' => $this->getAdapter()->getBackUrl(waAppPayment::URL_SUCCESS, $data), 'wa_decline_url' => $this->getAdapter()->getBackUrl(waAppPayment::URL_DECLINE, $data), 'wa_cancel_url' => $this->getAdapter()->getBackUrl(waAppPayment::URL_FAIL, $data), 'wa_app_id' => $this->app_id, 'wa_merchant_id' => $this->merchant_id);
     $form_fields['x_fp_hash'] = '';
     // @TODO: get from common 'address' field
     if (phpversion() >= '5.1.2') {
         $form_fields['x_fp_hash'] = hash_hmac('md5', $this->login . "^" . $form_fields['x_fp_sequence'] . "^" . $form_fields['x_fp_timestamp'] . "^" . $form_fields['x_amount'] . "^", $this->trans_key);
     } else {
         $form_fields['x_fp_hash'] = bin2hex(mhash(MHASH_MD5, $this->login . "^" . $form_fields['x_fp_sequence'] . "^" . $form_fields['x_fp_timestamp'] . "^" . $form_fields['x_amount'] . "^", $this->trans_key));
     }
     if ($this->form_header) {
         $form_fields['x_header_html_payment_form'] = $this->form_header;
     }
     $view = wa()->getView();
     $view->assign('url', wa()->getRootUrl());
     $view->assign('form_fields', $form_fields);
     $view->assign('form_url', $this->getEndpointUrl());
     $view->assign('auto_submit', $auto_submit);
     return $view->fetch($this->path . '/templates/payment.html');
 }
 /**
  *
  * Correct address (e.g. transliterate)
  *
  * @param string $address
  * @return string
  */
 protected function correctAddress($address)
 {
     if ($address) {
         foreach (waLocale::getAll() as $lang) {
             $address = waLocale::transliterate($address, $lang);
         }
     }
     return $address;
 }
 public function execute()
 {
     $this->getResponse()->addHeader('Content-type', 'application/json');
     $t = waRequest::post('t', '', waRequest::TYPE_STRING_TRIM);
     $t = preg_replace('/\\s+/', '-', $t);
     if ($t) {
         foreach (waLocale::getAll() as $lang) {
             $t = waLocale::transliterate($t, $lang);
         }
         $t = preg_replace('/[^a-zA-Z0-9_-]+/', '', $t);
     }
     $this->response = array('t' => strtolower($t), 'placeholder' => date('Ymd'));
 }
 public static function getFilesFromPost()
 {
     if (waRequest::server('HTTP_X_FILE_NAME')) {
         $name = waRequest::server('HTTP_X_FILE_NAME');
         $size = waRequest::server('HTTP_X_FILE_SIZE');
         $safe_name = trim(preg_replace('~[^a-z\\.]~', '', waLocale::transliterate($name)), ". \n\t\r");
         $safe_name || ($safe_name = uniqid('p'));
         $file_path = wa()->getTempPath('photos/upload/') . $safe_name;
         $append_file = is_file($file_path) && $size > filesize($file_path);
         clearstatcache();
         file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0);
         $file = new waRequestFile(array('name' => $name, 'type' => waRequest::server('HTTP_X_FILE_TYPE'), 'size' => $size, 'tmp_name' => $file_path, 'error' => 0));
         return array($file);
     } else {
         return waRequest::file('files');
     }
 }
 private function stepImportImage()
 {
     /**
      * @var shopProductImagesModel $model
      */
     static $model;
     if (!is_array($this->data['map'][self::STAGE_IMAGE]) && $this->data['map'][self::STAGE_IMAGE]) {
         $this->data['map'][self::STAGE_IMAGE] = array($this->data['map'][self::STAGE_IMAGE]);
     }
     if ($file = reset($this->data['map'][self::STAGE_IMAGE])) {
         if (!$model) {
             $model = new shopProductImagesModel();
         }
         //TODO store image id & if repeated - skip it
         $target = 'new';
         $u = @parse_url($file);
         $_is_url = false;
         if (!$u || !(isset($u['scheme']) && isset($u['host']) && isset($u['path']))) {
         } elseif (in_array($u['scheme'], array('http', 'https', 'ftp', 'ftps'))) {
             $_is_url = true;
         } else {
             $target = 'skip';
             $file = null;
             $this->error(sprintf('Unsupported file source protocol', $u['scheme']));
         }
         $search = array('product_id' => $this->data['map'][self::STAGE_PRODUCT], 'ext' => pathinfo($file, PATHINFO_EXTENSION));
         try {
             $name = preg_replace('@[^a-zA-Zа-яА-Я0-9\\._\\-]+@', '', basename(urldecode($file)));
             if ($_is_url) {
                 $pattern = sprintf('@/(%d)/images/(\\d+)/\\2\\.(\\d+(x\\d+)?)\\.([^\\.]+)$@', $search['product_id']);
                 if (preg_match($pattern, $file, $matches)) {
                     $image = array('product_id' => $matches[1], 'id' => $matches[2], 'ext' => $matches[5]);
                     if (strpos($file, shopImage::getUrl($image, $matches[3])) !== false && $model->getByField($image)) {
                         #skip local file
                         $target = 'skip';
                         $file = null;
                     }
                 }
                 if ($file) {
                     waFiles::upload($file, $file = wa()->getTempPath('csv/upload/images/' . waLocale::transliterate($name, 'en_US')));
                 }
             } elseif ($file) {
                 $file = $this->data['upload_path'] . $file;
             }
             if ($file && file_exists($file)) {
                 if ($image = waImage::factory($file)) {
                     $search['original_filename'] = $name;
                     $data = array('product_id' => $this->data['map'][self::STAGE_PRODUCT], 'upload_datetime' => date('Y-m-d H:i:s'), 'width' => $image->width, 'height' => $image->height, 'size' => filesize($file), 'original_filename' => $name, 'ext' => pathinfo($file, PATHINFO_EXTENSION));
                     if ($exists = $model->getByField($search)) {
                         $data = array_merge($exists, $data);
                         $thumb_dir = shopImage::getThumbsPath($data);
                         $back_thumb_dir = preg_replace('@(/$|$)@', '.back$1', $thumb_dir, 1);
                         $paths[] = $back_thumb_dir;
                         waFiles::delete($back_thumb_dir);
                         // old backups
                         if (file_exists($thumb_dir)) {
                             if (!(waFiles::move($thumb_dir, $back_thumb_dir) || waFiles::delete($back_thumb_dir)) && !waFiles::delete($thumb_dir)) {
                                 throw new waException(_w("Error while rebuild thumbnails"));
                             }
                         }
                     }
                     $image_changed = false;
                     /**
                      * TODO move it code into product core method
                      */
                     /**
                      * Extend add/update product images
                      * Make extra workup
                      * @event image_upload
                      */
                     $event = wa()->event('image_upload', $image);
                     if ($event) {
                         foreach ($event as $result) {
                             if ($result) {
                                 $image_changed = true;
                                 break;
                             }
                         }
                     }
                     if (empty($data['id'])) {
                         $image_id = $data['id'] = $model->add($data);
                     } else {
                         $image_id = $data['id'];
                         $target = 'update';
                         $model->updateById($image_id, $data);
                     }
                     if (!$image_id) {
                         throw new waException("Database error");
                     }
                     $image_path = shopImage::getPath($data);
                     if (file_exists($image_path) && !is_writable($image_path) || !file_exists($image_path) && !waFiles::create($image_path)) {
                         $model->deleteById($image_id);
                         throw new waException(sprintf("The insufficient file write permissions for the %s folder.", substr($image_path, strlen($this->getConfig()->getRootPath()))));
                     }
                     if ($image_changed) {
                         $image->save($image_path);
                         /**
                          * @var shopConfig $config
                          */
                         $config = $this->getConfig();
                         if ($config->getOption('image_save_original') && ($original_file = shopImage::getOriginalPath($data))) {
                             waFiles::copy($file, $original_file);
                         }
                     } else {
                         waFiles::copy($file, $image_path);
                     }
                     $this->data['processed_count'][self::STAGE_IMAGE][$target]++;
                 } else {
                     $this->error(sprintf('Invalid image file', $file));
                 }
             } elseif ($file) {
                 $this->error(sprintf('File %s not found', $file));
                 $target = 'skip';
                 $this->data['processed_count'][self::STAGE_IMAGE][$target]++;
             } else {
                 $this->data['processed_count'][self::STAGE_IMAGE][$target]++;
             }
         } catch (Exception $e) {
             $this->error($e->getMessage());
             //TODO skip on repeated error
         }
         array_shift($this->data['map'][self::STAGE_IMAGE]);
         ++$this->data['current'][self::STAGE_IMAGE];
         if ($_is_url) {
             waFiles::delete($file);
         }
     }
     return true;
 }
Esempio n. 6
0
 public static function transliterate($slug)
 {
     $slug = preg_replace('/\\s+/', '-', $slug);
     if ($slug) {
         foreach (waLocale::getAll() as $lang) {
             $slug = waLocale::transliterate($slug, $lang);
         }
     }
     $slug = preg_replace('/[^a-zA-Z0-9_-]+/', '', $slug);
     if (!$slug) {
         $slug = date('Ymd');
     }
     return strtolower($slug);
 }
Esempio n. 7
0
    public function getUniqueCode($code, $id = null)
    {
        if ($code = preg_replace('/[^a-zA-Z0-9_]+/', '_', trim(waLocale::transliterate($code)))) {
            if ($code == '_') {
                $code = 'f_';
            }
            $sql = <<<SQL
            SELECT `id`, LOWER(`code`) AS `code`
            FROM `{$this->table}`
            WHERE (`id` != i:id) AND (`code` LIKE s:c)
SQL;
            $params = array('c' => $this->escape($code, 'like') . '%', 'id' => $id);
            $codes = $this->query($sql, $params)->fetchAll('id', true);
            if ($codes) {
                $count = 0;
                $unique_code = $code;
                while (in_array(strtolower($unique_code), $codes)) {
                    $unique_code = $code . ++$count;
                }
            } else {
                $unique_code = $code;
            }
        } else {
            $unique_code = time();
        }
        return $unique_code;
    }
Esempio n. 8
0
 public static function suggestUrl($str)
 {
     $str = preg_replace('/\\s+/', '-', $str);
     if ($str) {
         foreach (waLocale::getAll() as $lang) {
             $str = waLocale::transliterate($str, $lang);
         }
     }
     $str = preg_replace('/[^a-zA-Z0-9_-]+/', '', $str);
     if (!strlen($str)) {
         $str = date('Ymd');
     }
     return strtolower($str);
 }
 private function translit($str)
 {
     $str = preg_replace('/\\s+/', '-', $str);
     if ($str) {
         foreach (waLocale::getAll() as $locale_id => $locale) {
             if ($locale_id != 'en_US') {
                 $str = waLocale::transliterate($str, $locale);
             }
         }
     }
     $str = preg_replace('/[^a-zA-Z0-9_-]+/', '', $str);
     return strtolower($str);
 }
Esempio n. 10
0
 private function init()
 {
     $this->init_address($this->data['billing_address']);
     $this->init_address($this->data['shipping_address']);
     if (empty($this->data['description_en'])) {
         $this->data['description_en'] = waLocale::transliterate(ifset($this->data['description'], ''));
     }
 }
Esempio n. 11
0
 private function open()
 {
     if ($this->file && file_exists($this->file)) {
         $this->files();
         $extension = pathinfo($this->file, PATHINFO_EXTENSION);
         $file = basename($this->file, '.' . $extension);
         if (pathinfo($file, PATHINFO_EXTENSION) != 'csv') {
             $file .= '.csv';
         }
         $path = pathinfo($this->file, PATHINFO_DIRNAME) . '/';
         $file = $path . $file;
         switch ($extension) {
             case 'gz':
                 if (extension_loaded('zlib')) {
                     if (function_exists('gzopen')) {
                         if (($src = gzopen($this->file, 'rb')) && ($dst = fopen($file, 'wb'))) {
                             stream_copy_to_stream($src, $dst);
                             gzclose($src);
                             fclose($dst);
                             $this->file = $file;
                         } else {
                             throw new waException("Error while read gz file");
                         }
                         $this->open();
                         break;
                     } elseif (in_array('compress.zlib', stream_get_wrappers())) {
                         $this->fp = fopen('compress.zlib://' . $this->file, 'rb');
                     } else {
                         throw new waException("Unsupported file extension");
                     }
                 } else {
                     throw new waException("Unsupported file extension");
                 }
                 $this->fsize = filesize($this->file);
                 break;
             case 'zip':
                 if (function_exists('zip_open') && ($zip = zip_open($this->file)) && is_resource($zip) && ($zip_entry = zip_read($zip))) {
                     //dummy read first file;
                     $file = $path . waLocale::transliterate(basename(zip_entry_name($zip_entry)));
                     $zip_fs = zip_entry_filesize($zip_entry);
                     if ($z = fopen($file, "w")) {
                         $size = 0;
                         while ($zz = zip_entry_read($zip_entry, max(0, min(4096, $zip_fs - $size)))) {
                             fwrite($z, $zz);
                             $size += 1024;
                         }
                         fclose($z);
                         zip_entry_close($zip_entry);
                         zip_close($zip);
                         $this->file = $file;
                         $this->files();
                     } else {
                         zip_entry_close($zip_entry);
                         zip_close($zip);
                         throw new waException("Error while read zip file");
                     }
                     $this->open();
                 } else {
                     throw new waException("Error while read zip file");
                 }
                 break;
             default:
                 if (is_array($this->encoding) || $this->encoding == 'auto') {
                     $this->fp = fopen($this->file, "rb");
                     if (!$this->fp) {
                         throw new waException("error while open CSV file");
                     }
                     $chunk = fread($this->fp, 4096);
                     if (is_array($this->encoding)) {
                         $this->encoding = mb_detect_encoding($chunk, $this->encoding);
                     } else {
                         $this->encoding = mb_detect_encoding($chunk);
                     }
                     if (strtolower($this->encoding) == 'utf-8') {
                         fseek($this->fp, 0);
                     }
                 }
                 if (strtolower($this->encoding) != 'utf-8') {
                     if ($this->fp) {
                         fclose($this->fp);
                         unset($this->fp);
                     }
                     if ($file = waFiles::convert($this->file, $this->encoding)) {
                         $this->encoding = 'utf-8';
                         $this->file = $file;
                         $this->files();
                         $this->fp = fopen($this->file, "rb");
                     } else {
                         throw new waException("Error while convert file encoding");
                     }
                 } elseif (!$this->fp) {
                     $this->fp = fopen($this->file, "rb");
                 }
                 $this->fsize = filesize($this->file);
                 break;
         }
     }
 }