public function compress() { $compressed = $this->minify($this->_contents); if (CssMin::hasErrors()) { $errors = CssMin::getErrors(); Ajde_Log::log(var_export($errors, true)); } return $compressed; }
protected function ping($url, $port = 80, $timeout = 6) { $host = parse_url($url, PHP_URL_HOST); $fsock = fsockopen($host, $port, $errno, $errstr, $timeout); if (!$fsock) { Ajde_Log::log('Ping for ' . $host . ':' . $port . ' (timeout=' . $timeout . ') failed'); return false; } else { return true; } }
public function publish() { $tweet = $this->getTitle(); if ($url = $this->getUrl()) { $tweet = substr($tweet, 0, 140 - strlen($url) - 5) . '... ' . $url; } while ($curlength = iconv_strlen(htmlspecialchars($tweet, ENT_QUOTES, 'UTF-8'), 'UTF-8') >= 140) { $tweet = substr($tweet, 0, -1); } try { $response = $this->_twitter->post('statuses/update', ['status' => $tweet]); } catch (Exception $e) { Ajde_Log::log($response); Ajde_Exception_Log::logException($e); return false; } if ($response->user && $response->user->id && $response->id_str) { return sprintf('http://twitter.com/%s/status/%s', $response->user->id, $response->id_str); } else { return false; } }
public function updatePayment() { // PHP 4.1 // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; $post = Ajde_Http_Request::globalPost(); foreach ($post as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&{$key}={$value}"; } // post back to PayPal system to validate $header = ''; $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= 'Content-Length: ' . strlen($req) . "\r\n\r\n"; $fp = fsockopen($this->isSandbox() ? 'ssl://www.sandbox.paypal.com' : 'ssl://www.paypal.com', 443, $errno, $errstr, 30); // assign posted variables to local variables $item_name = issetor($post['item_name']); $item_number = issetor($post['item_number']); $payment_status = issetor($post['payment_status']); $payment_amount = issetor($post['mc_gross']); $payment_currency = issetor($post['mc_currency']); $txn_id = issetor($post['txn_id']); $receiver_email = issetor($post['receiver_email']); $payer_email = issetor($post['payer_email']); $secret = issetor($post['custom']); $transaction = new TransactionModel(); $changed = false; if (!$fp) { // HTTP ERROR } else { fwrite($fp, $header . $req); while (!feof($fp)) { $res = fgets($fp, 1024); if (strcmp($res, 'VERIFIED') == 0) { if (!$transaction->loadByField('secret', $secret)) { Ajde_Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); return ['success' => false, 'transaction' => null]; } // check the payment_status is Completed // accept Pending from PayPal (eChecks?) $acceptPending = true; if ($payment_status == 'Completed' || $acceptPending && $payment_status == 'Pending') { $details = 'AMOUNT: ' . $payment_amount . PHP_EOL . 'CURRENCY: ' . $payment_currency . PHP_EOL . 'PAYER_EMAIL: ' . $payer_email . PHP_EOL . 'RECEIVER_EMAIL: ' . $receiver_email . PHP_EOL . 'TXN_ID: ' . $txn_id . PHP_EOL; // update transaction only once if ($transaction->payment_status != 'completed') { $transaction->payment_details = $details; $transaction->payment_status = 'completed'; $transaction->save(); $changed = true; } // Write pending to Log if ($payment_status == 'Pending') { Ajde_Log::log('Status is Pending but accepting now. PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } return ['success' => true, 'changed' => $changed, 'transaction' => $transaction]; } else { if ($transaction->payment_status != 'refused') { $transaction->payment_status = 'refused'; $transaction->save(); $changed = true; } Ajde_Log::log('Status is not Completed but ' . $payment_status . ' for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email // check that payment_amount/payment_currency are correct // process payment } else { if (strcmp($res, 'INVALID') == 0) { if (!$transaction->loadByField('secret', $secret)) { // secret not found anyway $transaction = null; Ajde_Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } else { // log for manual investigation if ($transaction->payment_status != 'refused') { $transaction->payment_status = 'refused'; $transaction->save(); $changed = true; } Ajde_Log::log('Validation failed for PayPal payment with txn id ' . $txn_id); } } } } fclose($fp); } return ['success' => false, 'changed' => $changed, 'transaction' => $transaction]; }
public function updatePayment() { // PHP 4.1 // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&{$key}={$value}"; } // post back to PayPal system to validate $header = ''; $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen($this->isSandbox() ? 'ssl://www.sandbox.paypal.com' : 'ssl://www.paypal.com', 443, $errno, $errstr, 30); // assign posted variables to local variables $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; $payment_status = $_POST['payment_status']; $payment_amount = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; $txn_id = $_POST['txn_id']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; Ajde_Model::register('shop'); $secret = $_POST['custom']; $transaction = new TransactionModel(); if (!$transaction->loadByField('secret', $secret)) { Ajde_Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } if (!$fp) { // HTTP ERROR } else { fputs($fp, $header . $req); while (!feof($fp)) { $res = fgets($fp, 1024); if (strcmp($res, "VERIFIED") == 0) { // check the payment_status is Completed if ($payment_status == 'Completed') { $details = 'AMOUNT: ' . $payment_amount . PHP_EOL . 'CURRENCY: ' . $payment_currency . PHP_EOL . 'PAYER_EMAIL: ' . $payer_email . PHP_EOL . 'RECEIVER_EMAIL: ' . $receiver_email . PHP_EOL . 'TXN_ID: ' . $txn_id . PHP_EOL; $transaction->payment_details = $details; $transaction->payment_status = 'completed'; $transaction->save(); } else { $transaction->payment_status = 'refused'; $transaction->save(); Ajde_Log::log('Status is not Completed but ' . $payment_status . ' for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email // check that payment_amount/payment_currency are correct // process payment } else { if (strcmp($res, "INVALID") == 0) { // log for manual investigation $transaction->payment_status = 'refused'; $transaction->save(); Ajde_Log::log('Validation failed for PayPal payment with txn id ' . $txn_id); } } } fclose($fp); } }
public static function logException(Exception $exception) { $trace = strip_tags(Ajde_Exception_Handler::trace($exception, Ajde_Exception_Handler::EXCEPTION_TRACE_LOG)); Ajde_Log::log($trace); }
/** * @param TransactionItemModel $transaction * * @deprecated use mailUser * * @throws Ajde_Core_Exception_Deprecated * @throws Ajde_Exception * @throws Exception * @throws phpmailerException */ public function mailUserDeprecated(TransactionItemModel $transaction) { throw new Ajde_Core_Exception_Deprecated(); $mailer = new Ajde_Mailer(); $mailer->IsMail(); // use php mail() $mailer->AddAddress($transaction->email, $transaction->name); $mailer->From = config('app.email'); $mailer->FromName = config('app.title'); $mailer->Subject = 'Your order'; $mailer->Body = '<h2>Your order on ' . config('app.title') . '</h2>' . '<p>Thank you for shopping with us. We will ship your items as soon as possible if you chose for delivery.<br/>' . 'To view the status of your order, please click this link:</p>' . '<p><a href=\'' . config('app.rootUrl') . 'shop/transaction:view/' . $transaction->secret . '.html\'>View your order status</a></p>' . '<p>Hope to welcome you again soon on <a href=\'' . config('app.rootUrl') . '\'>' . config('app.title') . '</a></p>'; $mailer->IsHTML(true); if (!$mailer->Send()) { Ajde_Log::log('Mail to ' . $transaction->email . ' failed'); } }
private function sendRequest($request, $asRaw = false) { if (self::$_debug) { Ajde_Log::log('INPUT DATA: ' . var_export($request, true)); } $xml = self::buildXML($request); $url = fsockopen('ssl://' . self::$_api_url, 443); if ($url === false) { return ['success' => false, 'response' => 'iDeal foutmelding: Kan niet verbinden']; } $data = $xml->saveXML(); $length = strlen($data); if (self::$_debug) { Ajde_Log::log('REQUEST XML: ' . var_export($data, true)); } $post = 'GET ' . self::$_api_path . " HTTP/1.0\n"; $post .= "Content-Length: {$length}\n"; $post .= "Content-Type: text/xml\n"; $post .= "Connection: Close\n\n"; $post .= "{$data}\n\n"; fwrite($url, $post); $response = ''; while (!feof($url)) { $response .= fgets($url, 1024); } fclose($url); if (self::$_debug) { Ajde_Log::log('RESPONSE DATA: ' . var_export($response, true)); } if ($asRaw) { $contentLenght = strpos($response, PHP_EOL . 'Content-Length:') + 1; $nextLine = strpos($response, PHP_EOL, $contentLenght); $result = trim(substr($response, $nextLine)); } else { if (strpos($response, '<?xml') === false) { return ['success' => false, 'response' => 'iDeal foutmelding: Ongeldig antwoord']; } $start = strpos($response, '<?xml'); $response = substr($response, $start); $xml = new DOMDocument(); $xml->loadXML($response); $result = simplexml_import_dom($xml); if (self::$_debug) { Ajde_Log::log('OUTPUT XML: ' . var_export($result, true)); } if ($result->error) { return ['success' => false, 'response' => "iDeal foutmelding ({$result->error}): " . self::getError($result->error)]; } } return ['success' => true, 'response' => $result]; }
public function updatePayment() { $payment = false; $mollie = new Mollie_API_Client(); $mollie->setApiKey($this->getApiKey()); $transaction = new TransactionModel(); $changed = false; // see if we are here for the webhook or user return url $mollie_id = Ajde::app()->getRequest()->getPostParam('id', false); // from webhook $order_id = Ajde::app()->getRequest()->getParam('order_id', false); // from user request if (!$mollie_id && $order_id) { // load from order_id $transaction->loadByField('secret', $order_id); $mollie_id = $transaction->payment_providerid; try { $payment = $mollie->payments->get($mollie_id); } catch (Mollie_API_Exception $e) { Ajde_Exception_Log::logException($e); $payment = false; } } else { if ($mollie_id) { // laod from mollie transaction id try { $payment = $mollie->payments->get($mollie_id); $order_id = $payment->metadata->order_id; $transaction->loadByField('secret', $order_id); } catch (Mollie_API_Exception $e) { Ajde_Exception_Log::logException($e); $payment = false; } } } if (!$payment || !$mollie_id || !$order_id || !$transaction->hasLoaded()) { Ajde_Log::log('Could not find transaction for Mollie payment for mollie id ' . $mollie_id . ' and transaction secret ' . $order_id); return ['success' => false, 'changed' => $changed, 'transaction' => $transaction]; } // what to return? $paid = false; $payment_details = $payment->details; if (is_object($payment_details) || is_array($payment_details)) { $payment_details = json_encode($payment_details); } // save details $details = 'PAYMENT STATUS: ' . (string) $payment->status . PHP_EOL . 'PAYMENT AMOUNT: ' . (string) $payment->amount . PHP_EOL . 'PAYMENT AT: ' . (string) $payment->paidDatetime . PHP_EOL . 'CANCELLED AT: ' . (string) $payment->cancelledDatetime . PHP_EOL . 'EXPIRED AT: ' . (string) $payment->expiredDatetime . PHP_EOL . 'PAYER DETAILS: ' . (string) $payment_details; $transaction->payment_details = $details; switch ($payment->status) { case 'open': if ($transaction->payment_status != 'requested') { $transaction->payment_status = 'requested'; $transaction->save(); $changed = true; } break; case 'paidout': case 'paid': $paid = true; // update transaction only once if ($transaction->payment_status != 'completed') { $transaction->paid(); $changed = true; } break; case 'cancelled': // update transaction only once if ($transaction->payment_status != 'cancelled') { $transaction->payment_status = 'cancelled'; $transaction->save(); $changed = true; } break; case 'expired': // update transaction only once if ($transaction->payment_status != 'refused') { $transaction->payment_status = 'refused'; $transaction->save(); $changed = true; } break; } return ['success' => $paid, 'changed' => $changed, 'transaction' => $transaction]; }