/** * Check if the user access token connected to payout exists. If it does not exist, returns null. * * If it exist, check for its expiration. If the token has been expired, refresh it with new one. * * @param array $apiKeys * @param Payout $payout * @param int $expires * * @return Registry|AccessToken|null */ public static function getPayoutAccessToken($apiKeys, Payout $payout, $expires = 7) { try { $token = $payout->getStripe(); // Try to get an access token (using the authorization code grant) $alias = !$apiKeys['test'] ? 'production' : 'test'; if ($token === null or !$token->get('stripeconnect.' . $alias . '.access_token')) { return null; } $options = array('access_token' => $token->get('stripeconnect.' . $alias . '.access_token'), 'refresh_token' => $token->get('stripeconnect.' . $alias . '.refresh_token'), 'expires' => $token->get('stripeconnect.' . $alias . '.expires')); $accessToken = new AccessToken($options); if ($accessToken->hasExpired()) { $provider = new Stripe(['clientId' => $apiKeys['client_id'], 'clientSecret' => $apiKeys['secret_key']]); $accessToken = $provider->getAccessToken('refresh_token', ['refresh_token' => $token->get('stripeconnect.' . $alias . '.refresh_token')]); // Prepare expiration date. $date = new \JDate(); $date->add(new \DateInterval('P' . $expires . 'D')); $token->set('stripeconnect.' . $alias . '.access_token', $accessToken->getToken()); $token->set('stripeconnect.' . $alias . '.refresh_token', $accessToken->getRefreshToken()); $token->set('stripeconnect.' . $alias . '.expires', $date->getTimestamp()); $payout->setStripe($token); $payout->storeStripe(); } } catch (\Exception $e) { \JLog::add($e->getMessage()); return null; } return $accessToken; }
/** * Authorize user to payment gateway. * * @param string $context * @param Joomla\Registry\Registry $params * * @return null|array */ public function onPayoutsAuthorize($context, $params) { if (strcmp('com_crowdfundingfinance.payouts.authorize.stripeconnect', $context) !== 0) { return null; } if ($this->app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentHtml */ // Check document type $docType = $doc->getType(); if (strcmp('html', $docType) !== 0) { return null; } // Prepare output data. $output = array('redirect_url' => '', 'message' => ''); $errorOutput = array('redirect_url' => JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute()), 'message' => ''); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_GET_RESPONSE_AUTHORIZE'), $this->debugType, $_GET) : null; $userId = JFactory::getUser()->get('id'); if (!$userId) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_NOT_REGISTERED_USER'); return $errorOutput; } // Get token $code = $this->app->input->get('code'); $state = $this->app->input->get('state'); if (!$code or !$state) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_INVALID_AUTHORIZATION_DATA'); return $errorOutput; } // Get project ID and redirect URL from the session. $stateData = $this->app->getUserState($state); if (count($stateData) === 0 or (!$stateData['redirect_url'] or !$stateData['project_id'])) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_INVALID_AUTHORIZATION_DATA'); return $errorOutput; } $cfFinanceParams = JComponentHelper::getParams('com_crowdfundingfinance'); $apiKeys = Crowdfundingfinance\Stripe\Helper::getKeys($cfFinanceParams); if (!$apiKeys['client_id'] or !$apiKeys['secret_key']) { $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_CONFIGURATION'); return $errorOutput; } // Prepare expiration date. $date = new JDate(); $date->add(new DateInterval('P' . $cfFinanceParams->get('stripe_expiration_period', '7') . 'D')); // Prepare Stripe data. $provider = new AdamPaterson\OAuth2\Client\Provider\Stripe(['clientId' => $apiKeys['client_id'], 'clientSecret' => $apiKeys['secret_key']]); $token = $provider->getAccessToken('authorization_code', ['code' => $code]); // Get resource owner. $resourceOwner = $provider->getResourceOwner($token); $alias = !$apiKeys['test'] ? 'production' : 'test'; $stripe = new \Joomla\Registry\Registry(array('stripeconnect' => array($alias => array('access_token' => $token->getToken(), 'refresh_token' => $token->getRefreshToken(), 'expires' => $date->getTimestamp(), 'account_id' => $resourceOwner->getId())))); $payout = new Crowdfundingfinance\Payout(JFactory::getDbo()); $payout->setSecretKey($this->app->get('secret')); $payout->load(array('project_id' => (int) $stateData['project_id'])); // Create user record. if (!$payout->getId()) { $payout->setProjectId((int) $stateData['project_id']); } $payout->setStripe($stripe); $payout->store(); // Get next URL. $output['redirect_url'] = base64_decode($stateData['redirect_url']); return $output; }
/** * Method to get the calendar input markup. * * @param string $display The display to render ('static' or 'repeatable') * * @return string The field input markup. * * @since 2.1.rc4 */ protected function getCalendar($display) { // Initialize some field attributes. $format = $this->format ? $this->format : '%Y-%m-%d'; $class = $this->class ? $this->class : ''; $default = $this->element['default'] ? (string) $this->element['default'] : ''; // Get some system objects. $config = $this->form->getContainer()->platform->getConfig(); $user = $this->form->getContainer()->platform->getUser(); // Check for empty date values if (empty($this->value) || $this->value == $this->form->getContainer()->platform->getDbo()->getNullDate() || $this->value == '0000-00-00') { $this->value = $default; } // Handle the special case for "now". if (strtoupper($this->value) == 'NOW') { $this->value = strftime($format); } // If a known filter is given use it. switch (strtoupper($this->filter)) { case 'SERVER_UTC': // Convert a date to UTC based on the server timezone. if ((int) $this->value) { // Get a date object based on the correct timezone. $date = \JFactory::getDate($this->value, 'UTC'); $date->setTimezone(new \DateTimeZone($config->get('offset'))); // Transform the date string. $this->value = $date->format('Y-m-d H:i:s', true, false); } break; case 'USER_UTC': // Convert a date to UTC based on the user timezone. if ((int) $this->value) { // Get a date object based on the correct timezone. $date = \JFactory::getDate($this->value, 'UTC'); $date->setTimezone(new \DateTimeZone($user->getParam('timezone', $config->get('offset')))); // Transform the date string. $this->value = $date->format('Y-m-d H:i:s', true, false); } break; } if ($display == 'static') { // Build the attributes array. $attributes = array(); if ($this->size) { $attributes['size'] = $this->size; } if ($this->maxlength) { $attributes['maxlength'] = $this->maxlength; } if ($this->class) { $attributes['class'] = $this->class; } if ($this->readonly) { $attributes['readonly'] = 'readonly'; } if ($this->disabled) { $attributes['disabled'] = 'disabled'; } if ($this->onchange) { $attributes['onchange'] = $this->onchange; } if ($this->required) { $attributes['required'] = 'required'; $attributes['aria-required'] = 'true'; } // Including fallback code for HTML5 non supported browsers. JHtml::_('jquery.framework'); JHtml::_('script', 'system/html5fallback.js', false, true); return JHtml::_('calendar', $this->value, $this->name, $this->id, $format, $attributes); } else { if (!$this->value && (string) $this->element['empty_replacement']) { $value = $this->element['empty_replacement']; } else { $jDate = new \JDate($this->value); $value = strftime($format, $jDate->getTimestamp()); } return '<span class="' . $this->id . ' ' . $class . '">' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '</span>'; } }
<th rowspan="2"><?php echo JText::_('COM_AKEEBAEXAMPLE_LIST_FIELD_TYPE');?></th> <th rowspan="2"><?php echo JText::_('COM_AKEEBAEXAMPLE_LIST_FIELD_PROFILEID');?></th> <th rowspan="2"><?php echo JText::_('COM_AKEEBAEXAMPLE_LIST_FIELD_TOTALSIZE');?></th> </tr> <tr> <th><?php echo JText::_('COM_AKEEBAEXAMPLE_LIST_FIELD_START');?></th> <th><?php echo JText::_('COM_AKEEBAEXAMPLE_LIST_FIELD_DURATION');?></th> </tr> </thead> <tbody> <?php jimport('joomla.utilities.date'); ?> <?php foreach($this->items as $item): ?> <?php $dateFrom = new JDate($item->backupstart); $dateTo = new JDate($item->backupend); $duration = $dateTo->getTimestamp() - $dateFrom->getTimestamp(); ?> <tr> <td><?php echo $this->escape($item->id)?></td> <td><?php echo $this->escape($item->description)?></td> <td><?php echo $dateFrom->format('Y-m-d H:i:s');?></td> <td><?php echo $duration ?></td> <td><?php echo $item->status?></td> <td><?php echo $item->origin?></td> <td><?php echo $item->type?></td> <td><?php echo $item->profile_id?></td> <td><?php echo $item->total_size?></td> </tr> <?php endforeach; ?> </tbody> </table>