/** * Handle annoying environment issues like magic quotes, constants and * auto-loaders before firing up the CASH platform and whatnot * * @return array */ public static function startUp() { // remove magic quotes, never call them "magic" in front of your friends if (get_magic_quotes_gpc()) { function stripslashes_from_gpc(&$value) { $value = stripslashes($value); } $gpc = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); array_walk_recursive($gpc, 'stripslashes_from_gpc'); unset($gpc); } // define constants (use sparingly!) $root = realpath(dirname(__FILE__) . '/../..'); define('CASH_PLATFORM_ROOT', $root); $cash_settings = CASHSystem::getSystemSettings(); define('CASH_API_URL', $cash_settings['apilocation']); define('CASH_PUBLIC_URL', str_replace('api/', 'public/', $cash_settings['apilocation'])); // set up auto-load spl_autoload_register('CASHSystem::autoloadClasses'); // set timezone date_default_timezone_set($cash_settings['timezone']); // fire off new CASHRequest to cover any immediate-need things like GET // asset requests, etc... $cash_page_request = new CASHRequest(); if (!empty($cash_page_request->response)) { $cash_page_request->sessionSet('initial_page_request', array('request' => $cash_page_request->request, 'response' => $cash_page_request->response, 'status_uid' => $cash_page_request->response['status_uid']), 'script'); } unset($cash_page_request); }
public static function getAuthorizationUrl($redirect_uri) { $auth_client = DropboxSeed::getWebAuthClient($redirect_uri); if (!$auth_client) { return false; } $url = $auth_client->start(); $csrf_token = $auth_client->getCsrfTokenStore()->get(); $cash_page_request = new CASHRequest(null); $cash_page_request->sessionSet('dropbox_csrf_token', $csrf_token); return $url; }
function testWhatever() { $request = new CASHRequest(); // test script-scope sesstion values: $value = $request->sessionGet('foobar', 'script'); $this->assertFalse($value); $request->sessionSet('foobar', 'baz', 'script'); $value = $request->sessionGet('foobar', 'script'); $this->assertEqual($value, 'baz'); $request->sessionClear('foobar', 'script'); $value = $request->sessionGet('foobar', 'script'); $this->assertFalse($value); $request->sessionSet('foobar', 'baz', 'script'); $request->sessionClearAll(); $value = $request->sessionGet('foobar', 'script'); $this->assertFalse($value); // test persistent-scope sesstion values: $value = $request->sessionGet('foobar'); $this->assertFalse($value); $request->sessionSet('foobar', 'baz'); $value = $request->sessionGet('foobar'); $this->assertFalse($value); // fail without startSession() $session = CASHSystem::startSession(); $this->assertTrue($session); echo 'Session started: ' . json_encode($session) . "\n"; $request->sessionSet('foobar', 'baz'); $value = $request->sessionGet('foobar'); $this->assertEqual($value, 'baz'); $request->sessionClear('foobar'); $value = $request->sessionGet('foobar'); $this->assertFalse($value); $request->sessionSet('foobar', 'baz'); $request->sessionClearAll(); $value = $request->sessionGet('foobar'); $this->assertFalse($value); }
public static function getRedirectMarkup($data = false) { $connections = CASHSystem::getSystemSettings('system_connections'); if (isset($connections['com.twitter'])) { require_once CASH_PLATFORM_ROOT . '/lib/twitter/OAuth.php'; require_once CASH_PLATFORM_ROOT . '/lib/twitter/twitteroauth.php'; $twitter = new TwitterOAuth($connections['com.twitter']['client_id'], $connections['com.twitter']['client_secret']); $temporary_credentials = $twitter->getRequestToken($connections['com.twitter']['redirect_uri']); // store temporary credentials in the session for return $session_request = new CASHRequest(); $session_request->sessionSet('twitter_temporary_credentials', $temporary_credentials); $login_url = $twitter->getAuthorizeURL($temporary_credentials, FALSE); $return_markup = '<h4>Twitter</h4>' . '<p>This will redirect you to a secure login on twitter.com and bring you right back.</p>' . '<a href="' . $login_url . '" class="button">Connect your Twitter account</a>'; return $return_markup; } else { return 'Please add default twitter app credentials.'; } }
} } else { define('BASE_PAGENAME', ''); $include_filename = 'error.php'; } } } else { define('BASE_PAGENAME', 'mainpage'); $include_filename = 'mainpage.php'; } // if a login needs doing, do it $login_message = "Log In"; if (isset($_POST['login'])) { $login_details = AdminHelper::doLogin($_POST['address'], $_POST['password']); if ($login_details !== false) { $admin_primary_cash_request->sessionSet('cash_actual_user', $login_details); $admin_primary_cash_request->sessionSet('cash_effective_user', $login_details); $admin_primary_cash_request->sessionSet('cash_effective_user_email', $_POST['address']); if ($include_filename == 'logout.php') { header('Location: ' . ADMIN_WWW_BASE_PATH); exit; } } else { $admin_primary_cash_request->sessionClearAll(); $login_message = "Try Again"; } } // make a few objects to use throughout the pages $cash_admin = new AdminCore($admin_primary_cash_request->sessionGet('cash_effective_user')); if (isset($_GET['hidebanner'])) { $current_settings = $cash_admin->getUserSettings();
protected function initiatePaymentRedirect($order_id, $element_id = false, $price_addition = 0, $url_only = false, $finalize_url = false, $session_id = false) { $order_details = $this->getOrder($order_id); $transaction_details = $this->getTransaction($order_details['transaction_id']); $order_totals = $this->getOrderTotals($order_details['order_contents']); $connection_type = $this->getConnectionType($transaction_details['connection_id']); $currency = $this->getCurrencyForUser($order_details['user_id']); if ($finalize_url) { $r = new CASHRequest(); $r->startSession(false, $session_id); $r->sessionSet('payment_finalize_url', $finalize_url); } if ($order_totals['price'] + $price_addition < 0.35) { // basically a zero dollar transaction. hard-coding a 35¢ minimum for now // we can add a system minimum later, or a per-connection minimum, etc... return 'force_success'; } switch ($connection_type) { case 'com.paypal': $pp = new PaypalSeed($order_details['user_id'], $transaction_details['connection_id']); if (!$finalize_url) { $finalize_url = CASHSystem::getCurrentURL(); } $return_url = $finalize_url . '?cash_request_type=commerce&cash_action=finalizepayment&order_id=' . $order_id . '&creation_date=' . $order_details['creation_date']; if ($element_id) { $return_url .= '&element_id=' . $element_id; } $require_shipping = false; $allow_note = false; if ($order_details['physical']) { $require_shipping = true; $allow_note = true; } $redirect_url = $pp->setExpressCheckout($order_totals['price'] + $price_addition, 'order-' . $order_id, $order_totals['description'], $return_url, $return_url, $require_shipping, $allow_note, $currency, 'Sale', false, $price_addition); if (!$url_only) { $redirect = CASHSystem::redirectToUrl($redirect_url); // the return will only happen if headers have already been sent // if they haven't redirectToUrl() will handle it and call exit return $redirect; } else { return $redirect_url; } break; default: return false; } return false; }