Get and cache the token used for a transaction.
336473
public function getToken() {
    $cid = 'acm_payment:braintree_token';
    $token = NULL;

    if ($cache = \Drupal::cache()->get($cid)) {
      $token = $cache->data;
    }
    else {
      $token = \Drupal::service('acm.api')->getPaymentToken('braintree');
      \Drupal::cache()->set($cid, $token);
    }

    return $token;
  }
990365
def _cached_request(self, base_url, client_id, client_secret,
                        parameters, **kwargs):
        """"""
        key = (base_url, client_id, tuple(parameters.items()))
        cached = self._cache.get(key, {})

        if not cached.get('access_token') or self._expired(cached):
            cached = yield self._request(base_url, client_id, client_secret,
                                         parameters, **kwargs)
            self._cache[key] = cached
            # Purge cache when adding a new item so it doesn't grow too large
            # It's assumed the cache size is small enough that it's OK to loop
            # over the whole cache regularly. If not, could change this to
            # just pop off the oldest one
            self.purge_cache()

        logging.debug('Using a cached token: %s', cached.get('access_token'))
        raise Return(cached)
1046502
def mk_token(self, load):
        '''
        
        '''
        if not self.authenticate_eauth(load):
            return {}

        if self._allow_custom_expire(load):
            token_expire = load.pop('token_expire', self.opts['token_expire'])
        else:
            _ = load.pop('token_expire', None)
            token_expire = self.opts['token_expire']

        tdata = {'start': time.time(),
                 'expire': time.time() + token_expire,
                 'name': self.load_name(load),
                 'eauth': load['eauth']}

        if self.opts['keep_acl_in_token']:
            acl_ret = self.__get_acl(load)
            tdata['auth_list'] = acl_ret

        groups = self.get_groups(load)
        if groups:
            tdata['groups'] = groups

        return self.tokens["{0}.mk_token".format(self.opts['eauth_tokens'])](self.opts, tdata)
169694
def get_transaction(self, account_id, transaction_id, **params):
        """"""
        response = self._get(
            'v2', 'accounts', account_id, 'transactions', transaction_id, params=params)
        return self._make_api_object(response, Transaction)
849769
def get_transaction(cls, txid):
        

        for api_call in cls.GET_TX_MAIN:
            try:
                return api_call(txid)
            except cls.IGNORED_ERRORS:
                pass

        raise ConnectionError('All APIs are unreachable.')
7708
def _get_token(self, oauth_request, token_type='access'):
        """"""
        token_field = oauth_request.get_parameter('oauth_token')
        token = self.data_store.lookup_token(token_type, token_field)
        if not token:
            raise OAuthError('Invalid %s token: %s' % (token_type, token_field))
        return token
710493
def receive_request(self, transaction):
        

        transaction.cached_element = self.cache.search_response(transaction.request)
        if transaction.cached_element is None:
            transaction.cacheHit = False
        else:
            transaction.response = transaction.cached_element.cached_response
            transaction.response.mid = transaction.request.mid
            transaction.cacheHit = True

            age = transaction.cached_element.creation_time + transaction.cached_element.max_age - time.time()
            if transaction.cached_element.freshness is True:
                if age <= 0:
                    logger.debug("resource not fresh")
                    """
                    if the resource is not fresh, its Etag must be added to the request so that the server might validate it instead of sending a new one
                    """
                    transaction.cached_element.freshness = False
                    """
                    ensuring that the request goes to the server
                    """
                    transaction.cacheHit = False
                    logger.debug("requesting etag %s", transaction.response.etag)
                    transaction.request.etag = transaction.response.etag
                else:
                    transaction.response.max_age = age
            else:
                transaction.cacheHit = False
        return transaction
1117516
function getStoredToken (storageLocation) {
	var token = readCookie(storageLocation);
	if (!token && (window && window.localStorage || window.sessionStorage)) {
		token = window.sessionStorage.getItem(storageLocation) || window.localStorage.getItem(storageLocation);
	}
	return token;
}
29242
def fetch_token(self, **kwargs):
        
        if 'client_secret' not in kwargs:
            kwargs.update(client_secret=self.client_secret)
        return self.session.fetch_token(token_url, **kwargs)
324330
private Transaction getAndValidateWrappedTransaction() throws IllegalStateException {
		final Transaction wrappedTransaction = getWrappedTransaction();
		if (wrappedTransaction == null) {
			throw new IllegalStateException();
		}
		else { 
			return wrappedTransaction;
		}
	}
540019
def token(self):
        
        if not self._token:
            self._token = self.fetch_token()
            logger.payment(self)
        return self._token
1332475
def clean_expired_tokens(opts):
    '''
    
    '''
    loadauth = salt.auth.LoadAuth(opts)
    for tok in loadauth.list_tokens():
        token_data = loadauth.get_tok(tok)
        if 'expire' not in token_data or token_data.get('expire', 0) < time.time():
            loadauth.rm_token(tok)
244256
def get_token(self, request):
        
        return stripe.Token.create(
            card={
                "number": request.data["number"],
                "exp_month": request.data["exp_month"],
                "exp_year": request.data["exp_year"],
                "cvc": request.data["cvc"]

            }
        )
212988
def is_active(cache, token):
    
    profile = cache.get(token)
    if not profile:
        raise exceptions.NotAuthenticatedException(
            'The token is good, but you are not logged in. Please '
            'try logging in again.')
    return profile
256417
def get_transactions(self, account_id, **params):
        """"""
        response = self._get('v2', 'accounts', account_id, 'transactions', params=params)
        return self._make_api_object(response, Transaction)
48449
private function saveToken()
	{
		$fd = fopen($this->cacheFolder."/token.txt", 'w');
		fwrite($fd, $this->token);
		fclose($fd);
	}
401199
def ledger(self):
        """"""
        self.balance()  # make sure the transaction balances

        s = "{0}/{1:02}/{2:02}  {3}\n".format(
            self.date.year,
            self.date.month,
            self.date.day,
            self.desc.replace('\n', ' ')
        )
        for src in self.src:
            s += "  {0.account}  ${0.amount}\n".format(src)
        for dst in self.dst:
            s += "  {0.account}  ${0.amount}\n".format(dst)
        return s