コード例 #1
0
 public function __construct()
 {
     $this->registry = Registry::getInstance();
     $cache_files = glob(DIR_CACHE . '*/*', GLOB_NOSORT);
     if (!is_array($cache_files) || !is_writeable(DIR_CACHE)) {
         $log = $this->registry->get('log');
         if (!is_object($log) || !method_exists($log, 'write')) {
             $error_text = 'Error: Unable to access or write to cache directory ' . DIR_CACHE;
             $log = new ALog(DIR_SYSTEM . 'logs/error.txt');
             $this->registry->set('log', $log);
         }
         $log->write($error_text);
         //try to add message for admin (check if for install-process too)
         $db = $this->registry->get('db');
         if (is_object($db) && method_exists($db, 'query')) {
             $error_text .= ' Cache feature was disabled. Check permissions on directory and enable setting back.';
             $m = new AMessage();
             $m->saveError('AbanteCart Warning', $error_text);
             //also disable caching in config
             $sql = "UPDATE " . $db->table('settings') . "\n\t\t\t\t\t\tSET `value` = '0'\n\t\t\t\t\t\tWHERE `key` = 'config_cache_enable'";
             $db->query($sql);
         }
     } else {
         foreach ($cache_files as $file) {
             //first of all check if file expired. delete it if needed
             $file_time = filemtime($file);
             if (time() - $file_time > $this->expire) {
                 if (file_exists($file)) {
                     $this->_remove($file);
                     continue;
                 }
             }
             //build cache map as array {cache_file_name_without_timestamp=>expire_time}
             $ch_base = substr($file, 0, -11);
             $this->cache_map[$ch_base] = $file_time + $this->expire;
         }
     }
 }
コード例 #2
0
 public function send()
 {
     if (defined('IS_DEMO') && IS_DEMO) {
         return null;
     }
     if (!$this->to) {
         $error = 'Error: E-Mail to required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (!$this->from) {
         $error = 'Error: E-Mail from required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (!$this->sender) {
         $error = 'Error: E-Mail sender required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (!$this->subject) {
         $error = 'Error: E-Mail subject required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (!$this->text && !$this->html) {
         $error = 'Error: E-Mail message required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (is_array($this->to)) {
         $to = implode(',', $this->to);
     } else {
         $to = $this->to;
     }
     $boundary = '----=_NextPart_' . md5(rand());
     $header = '';
     if ($this->protocol != 'mail') {
         $header .= 'To: ' . $to . $this->newline;
         $header .= 'Subject: ' . '=?UTF-8?B?' . base64_encode($this->subject) . '?=' . $this->newline;
     }
     $header .= 'Date: ' . date('D, d M Y H:i:s O') . $this->newline;
     $header .= 'From: ' . '=?UTF-8?B?' . base64_encode($this->sender) . '?=' . '<' . $this->from . '>' . $this->newline;
     $header .= 'Reply-To: ' . '=?UTF-8?B?' . base64_encode($this->sender) . '?=' . '<' . $this->from . '>' . $this->newline;
     $header .= 'Return-Path: ' . $this->from . $this->newline;
     $header .= 'X-Mailer: PHP/' . phpversion() . $this->newline;
     $header .= 'MIME-Version: 1.0' . $this->newline;
     $header .= 'Content-Type: multipart/related; boundary="' . $boundary . '"' . $this->newline . $this->newline;
     if (!$this->html) {
         $message = '--' . $boundary . $this->newline;
         $message .= 'Content-Type: text/plain; charset="utf-8"' . $this->newline;
         $message .= 'Content-Transfer-Encoding: 8bit' . $this->newline . $this->newline;
         $message .= $this->text . $this->newline;
     } else {
         $message = '--' . $boundary . $this->newline;
         $message .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '_alt"' . $this->newline . $this->newline;
         $message .= '--' . $boundary . '_alt' . $this->newline;
         $message .= 'Content-Type: text/plain; charset="utf-8"' . $this->newline;
         $message .= 'Content-Transfer-Encoding: 8bit' . $this->newline . $this->newline;
         if ($this->text) {
             $message .= $this->text . $this->newline;
         } else {
             $message .= 'This is a HTML email and your email client software does not support HTML email!' . $this->newline;
         }
         $message .= '--' . $boundary . '_alt' . $this->newline;
         $message .= 'Content-Type: text/html; charset="utf-8"' . $this->newline;
         $message .= 'Content-Transfer-Encoding: base64' . $this->newline . $this->newline;
         $message .= chunk_split(base64_encode($this->html)) . $this->newline;
         $message .= '--' . $boundary . '_alt--' . $this->newline;
     }
     foreach ($this->attachments as $attachment) {
         if (file_exists($attachment['file'])) {
             $handle = fopen($attachment['file'], 'r');
             $content = fread($handle, filesize($attachment['file']));
             fclose($handle);
             $message .= '--' . $boundary . $this->newline;
             $message .= 'Content-Type: application/octet-stream' . $this->newline;
             $message .= 'Content-Transfer-Encoding: base64' . $this->newline;
             $message .= 'Content-Disposition: attachment; filename="' . $attachment['filename'] . '"' . $this->newline;
             $message .= 'Content-ID: <' . basename(urlencode($attachment['filename'])) . '>' . $this->newline;
             $message .= 'X-Attachment-Id: ' . basename(urlencode($attachment['filename'])) . $this->newline . $this->newline;
             $message .= chunk_split(base64_encode($content));
         }
     }
     $message .= '--' . $boundary . '--' . $this->newline;
     if ($this->protocol == 'mail') {
         ini_set('sendmail_from', $this->from);
         if ($this->parameter) {
             mail($to, '=?UTF-8?B?' . base64_encode($this->subject) . '?=', $message, $header, $this->parameter);
         } else {
             mail($to, '=?UTF-8?B?' . base64_encode($this->subject) . '?=', $message, $header);
         }
     } elseif ($this->protocol == 'smtp') {
         $handle = fsockopen($this->hostname, (int) $this->port, $errno, $errstr, (int) $this->timeout);
         if (!$handle) {
             $error = 'Error: ' . $errstr . ' (' . $errno . ')';
             $this->log->write($error);
             $this->error[] = $error;
         } else {
             if (substr(PHP_OS, 0, 3) != 'WIN') {
                 socket_set_timeout($handle, $this->timeout, 0);
             }
             while ($line = fgets($handle, 515)) {
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($this->hostname, 0, 3) == 'tls') {
                 fputs($handle, 'STARTTLS' . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 220) {
                     $error = 'Error: STARTTLS not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
             }
             if (!empty($this->username) && !empty($this->password)) {
                 fputs($handle, 'EHLO ' . getenv('SERVER_NAME') . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 250) {
                     $error = 'Error: EHLO not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
                 fputs($handle, 'AUTH LOGIN' . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 334) {
                     $error = 'Error: AUTH LOGIN not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
                 fputs($handle, base64_encode($this->username) . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 334) {
                     $error = 'Error: Username not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
                 fputs($handle, base64_encode($this->password) . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 235) {
                     $error = 'Error: Password not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
             } else {
                 fputs($handle, 'HELO ' . getenv('SERVER_NAME') . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 250) {
                     $error = 'Error: HELO not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
             }
             if ($this->verp) {
                 fputs($handle, 'MAIL FROM: <' . $this->from . '>XVERP' . $this->crlf);
             } else {
                 fputs($handle, 'MAIL FROM: <' . $this->from . '>' . $this->crlf);
             }
             $reply = '';
             while ($line = fgets($handle, 515)) {
                 $reply .= $line;
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($reply, 0, 3) != 250) {
                 $error = 'Error: MAIL FROM not accepted from server!';
                 $this->log->write($error);
                 $this->error[] = $error;
             }
             if (!is_array($this->to)) {
                 fputs($handle, 'RCPT TO: <' . $this->to . '>' . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 250 && substr($reply, 0, 3) != 251) {
                     $error = 'Error: RCPT TO not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
             } else {
                 foreach ($this->to as $recipient) {
                     fputs($handle, 'RCPT TO: <' . $recipient . '>' . $this->crlf);
                     $reply = '';
                     while ($line = fgets($handle, 515)) {
                         $reply .= $line;
                         if (substr($line, 3, 1) == ' ') {
                             break;
                         }
                     }
                     if (substr($reply, 0, 3) != 250 && substr($reply, 0, 3) != 251) {
                         $error = 'Error: RCPT TO not accepted from server!';
                         $this->log->write($error);
                         $this->error[] = $error;
                     }
                 }
             }
             fputs($handle, 'DATA' . $this->crlf);
             $reply = '';
             while ($line = fgets($handle, 515)) {
                 $reply .= $line;
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($reply, 0, 3) != 354) {
                 $error = 'Error: DATA not accepted from server!';
                 $this->log->write($error);
                 $this->error[] = $error;
             }
             fputs($handle, $header . $message . $this->crlf);
             fputs($handle, '.' . $this->crlf);
             $reply = '';
             while ($line = fgets($handle, 515)) {
                 $reply .= $line;
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($reply, 0, 3) != 250) {
                 $error = 'Error: DATA not accepted from server!';
                 $this->log->write($error);
                 $this->error[] = $error;
             }
             fputs($handle, 'QUIT' . $this->crlf);
             $reply = '';
             while ($line = fgets($handle, 515)) {
                 $reply .= $line;
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($reply, 0, 3) != 221) {
                 $error = 'Error: QUIT not accepted from server!';
                 $this->log->write($error);
                 $this->error[] = $error;
             }
             fclose($handle);
         }
     }
     if ($this->error) {
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
     }
 }
コード例 #3
0
 public function processPayment($pd, $customer_stripe_id = '')
 {
     $response = '';
     $this->load->model('checkout/order');
     $this->load->language('default_stripe/default_stripe');
     $order_info = $this->model_checkout_order->getOrder($pd['order_id']);
     try {
         require_once DIR_EXT . 'default_stripe/core/stripe_modules.php';
         grantStripeAccess($this->config);
         //build charge data array
         $charge_data = array();
         $charge_data['amount'] = $pd['amount'];
         $charge_data['currency'] = $pd['currency'];
         $charge_data['description'] = $this->config->get('store_name') . ' Order #' . $pd['order_id'];
         $charge_data['statement_descriptor'] = 'Order #' . $pd['order_id'];
         $charge_data['receipt_email'] = $order_info['email'];
         if ($this->config->get('default_stripe_settlement') == 'delayed') {
             $charge_data['capture'] = false;
         } else {
             $charge_data['capture'] = true;
         }
         //build cc details
         $cc_details = array('number' => $pd['cc_number'], 'exp_month' => $pd['cc_expire_month'], 'exp_year' => $pd['cc_expire_year'], 'cvc' => $pd['cc_cvv2'], 'name' => $pd['cc_owner']);
         $cc_details = array_merge($cc_details, array('address_line1' => $order_info['payment_address_1'], 'address_line2' => $order_info['payment_address_2'], 'address_city' => $order_info['payment_city'], 'address_zip' => $order_info['payment_postcode'], 'address_state' => $order_info['payment_zone'], 'address_country' => $order_info['payment_iso_code_2']));
         //we need get the token for the card first
         $token = array();
         $token = Stripe_Token::create(array('card' => $cc_details));
         if (!$token || !$token['id']) {
             $msg = new AMessage();
             $msg->saveError('Stripe failed to get card token for order_id ' . $pd['order_id'], 'Unable to use card for customer' . $customer_stripe_id);
             $response['error'] = $this->language->get('error_system');
             return $response;
         }
         $charge_data['card'] = $token['id'];
         if ($order_info['shipping_method']) {
             $charge_data['shipping'] = array('name' => $order_info['firstname'] . ' ' . $order_info['lastname'], 'phone' => $order_info['telephone'], 'address' => array('line1' => $order_info['shipping_address_1'], 'line2' => $order_info['shipping_address_2'], 'city' => $order_info['shipping_city'], 'postal_code' => $order_info['shipping_postcode'], 'state' => $order_info['shipping_zone'], 'country' => $order_info['shipping_iso_code_2']));
         }
         $charge_data['metadata'] = array();
         $charge_data['metadata']['order_id'] = $pd['order_id'];
         if ($this->customer->getId() > 0) {
             $charge_data['metadata']['customer_id'] = (int) $this->customer->getId();
         }
         ADebug::variable('Processing stripe payment request: ', $charge_data);
         $response = Stripe_Charge::create($charge_data);
     } catch (Stripe_CardError $e) {
         // card errors
         $body = $e->getJsonBody();
         $response['error'] = $body['error']['message'];
         $response['code'] = $body['error']['code'];
         return $response;
     } catch (Stripe_InvalidRequestError $e) {
         // Invalid parameters were supplied to Stripe's API
         $body = $e->getJsonBody();
         $msg = new AMessage();
         $msg->saveError('Stripe payment failed with invalid parameters!', 'Stripe payment failed. ' . $body['error']['message']);
         $response['error'] = $this->language->get('error_system');
         return $response;
     } catch (Stripe_AuthenticationError $e) {
         // Authentication with Stripe's API failed
         $body = $e->getJsonBody();
         $msg = new AMessage();
         $msg->saveError('Stripe payment failed to authenticate!', 'Stripe payment failed to authenticate to the server. ' . $body['error']['message']);
         $response['error'] = $this->language->get('error_system');
         return $response;
     } catch (Stripe_ApiConnectionError $e) {
         // Network communication with Stripe failed
         $body = $e->getJsonBody();
         $msg = new AMessage();
         $msg->saveError('Stripe payment connection has failed!', 'Stripe payment failed connecting to the server. ' . $body['error']['message']);
         $response['error'] = $this->language->get('error_system');
         return $response;
     } catch (Stripe_Error $e) {
         // Display a very generic error to the user, and maybe send
         $body = $e->getJsonBody();
         $msg = new AMessage();
         $msg->saveError('Stripe payment has failed!', 'Stripe processing failed. ' . $body['error']['message']);
         $response['error'] = $this->language->get('error_system');
         return $response;
     } catch (Exception $e) {
         // Something else happened, completely unrelated to Stripe
         $msg = new AMessage();
         $msg->saveError('Unexpected error in stripe payment!', 'Stripe processing failed. ' . $e->getMessage() . "(" . $e->getCode() . ")");
         $response['error'] = $this->language->get('error_system');
         //log in AException
         $ae = new AException($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
         ac_exception_handler($ae);
         return $response;
     }
     //we still have no result. something unexpected happend
     if (empty($response)) {
         $response['error'] = $this->language->get('error_system');
         return $response;
     }
     ADebug::variable('Processing stripe payment response: ', $response);
     //Do we have an error? exit with no records
     if ($response['failure_message'] || $response['failure_code']) {
         $response['error'] = $response['failure_message'];
         $response['code'] = $response['failure_code'];
         return $response;
     }
     $message .= 'Order id: ' . (string) $pd['order_id'] . "\n";
     $message .= 'Charge id: ' . (string) $response['id'] . "\n";
     $message .= 'Transaction Timestamp: ' . (string) date('m/d/Y H:i:s', $response['created']);
     if ($response['paid']) {
         //finalize order only if payment is a success
         $this->model_checkout_order->addHistory($pd['order_id'], $this->config->get('config_order_status_id'), $message);
         if ($this->config->get('default_stripe_settlement') == 'auto') {
             //auto complete the order in sattled mode
             $this->model_checkout_order->confirm($pd['order_id'], $this->config->get('default_stripe_status_success_settled'));
         } else {
             //complete the order in unsattled mode
             $this->model_checkout_order->confirm($pd['order_id'], $this->config->get('default_stripe_status_success_unsettled'));
         }
     } else {
         // Some other error, assume payment declined
         $this->model_checkout_order->addHistory($pd['order_id'], $this->config->get('default_stripe_status_decline'), $message);
         $response['error'] = "Payment has failed! " . $response['failure_message'];
         $response['code'] = $response['failure_code'];
     }
     return $response;
 }