/**
  * Checks if a node's type requires a redirect.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  *   The event to process.
  */
 public function purlCheckNodeContext(GetResponseEvent $event, $eventName, EventDispatcherInterface $dispatcher_interface)
 {
     $route_options = $this->routeMatch->getRouteObject()->getOptions();
     $isAdminRoute = array_key_exists('_admin_route', $route_options) && $route_options['_admin_route'];
     if (!$isAdminRoute && ($matched = $this->matchedModifiers->getMatched() && ($entity = $this->routeMatch->getParameter('node')))) {
         $node_type = $this->entityStorage->load($entity->bundle());
         $purl_settings = $node_type->getThirdPartySettings('purl');
         if (!isset($purl_settings['keep_context']) || !$purl_settings['keep_context']) {
             $url = \Drupal\Core\Url::fromRoute($this->routeMatch->getRouteName(), $this->routeMatch->getRawParameters()->all(), ['host' => Settings::get('purl_base_domain'), 'absolute' => TRUE]);
             try {
                 $redirect_response = new TrustedRedirectResponse($url->toString());
                 $redirect_response->getCacheableMetadata()->setCacheMaxAge(0);
                 $modifiers = $event->getRequest()->attributes->get('purl.matched_modifiers', []);
                 $new_event = new ExitedContextEvent($event->getRequest(), $redirect_response, $this->routeMatch, $modifiers);
                 $dispatcher_interface->dispatch(PurlEvents::EXITED_CONTEXT, $new_event);
                 $event->setResponse($new_event->getResponse());
                 return;
             } catch (RedirectLoopException $e) {
                 \Drupal::logger('redirect')->warning($e->getMessage());
                 $response = new Response();
                 $response->setStatusCode(503);
                 $response->setContent('Service unavailable');
                 $event->setResponse($response);
                 return;
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function assignPackages($force = FALSE)
 {
     $current_bundle = $this->assigner->getBundle();
     $settings = $current_bundle->getAssignmentSettings($this->getPluginId());
     $config_base_types = $settings['types']['config'];
     $config_types = $this->featuresManager->listConfigTypes();
     $config_collection = $this->featuresManager->getConfigCollection();
     foreach ($config_collection as $item_name => $item) {
         if (in_array($item->getType(), $config_base_types)) {
             if (is_null($this->featuresManager->findPackage($item->getShortName())) && !$item->getPackage()) {
                 $description = $this->t('Provides @label @type and related configuration.', array('@label' => $item->getLabel(), '@type' => Unicode::strtolower($config_types[$item->getType()])));
                 if (isset($item->getData()['description'])) {
                     $description .= ' ' . $item->getData()['description'];
                 }
                 $this->featuresManager->initPackage($item->getShortName(), $item->getLabel(), $description, 'module', $current_bundle);
                 // Update list with the package we just added.
                 try {
                     $this->featuresManager->assignConfigPackage($item->getShortName(), [$item_name]);
                 } catch (\Exception $exception) {
                     \Drupal::logger('features')->error($exception->getMessage());
                 }
                 $this->featuresManager->assignConfigDependents([$item_name]);
             }
         }
     }
     $entity_types = $this->entityManager->getDefinitions();
     $content_base_types = $settings['types']['content'];
     foreach ($content_base_types as $entity_type_id) {
         if (!isset($packages[$entity_type_id]) && isset($entity_types[$entity_type_id])) {
             $label = $entity_types[$entity_type_id]->getLabel();
             $description = $this->t('Provide @label related configuration.', array('@label' => $label));
             $this->featuresManager->initPackage($entity_type_id, $label, $description, 'module', $current_bundle);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function chargeCard($order, $amount, $txn_type, $reference = NULL)
 {
     $user = \Drupal::currentUser();
     // cc_exp_month and cc_exp_year are also validated by
     // _uc_credit_valid_card_expiration() on the checkout form.
     $month = $order->payment_details['cc_exp_month'];
     $year = $order->payment_details['cc_exp_year'];
     if ($year < 100) {
         $year = $year + 2000;
     }
     // Card is expired at 0:00 on the first day of the next month.
     $expiration_date = mktime(0, 0, 0, $month + 1, 1, $year);
     // Conditions for failure are described in file documentation block above.
     // All other transactions will succeed.
     if ($order->payment_details['cc_number'] == '0000000000000000' || isset($order->payment_details['cc_cvv']) && $order->payment_details['cc_cvv'] == '000' || $expiration_date - REQUEST_TIME <= 0 || $amount == 12.34 || $order->billing_first_name == 'Fictitious' || $order->billing_phone == '8675309') {
         $success = FALSE;
     } else {
         $success = TRUE;
     }
     // The information for the payment is in the $order->payment_details array.
     if ($this->configuration['debug']) {
         \Drupal::logger('uc_credit')->notice('Test gateway payment details @details.', ['@details' => print_r($order->payment_details, TRUE)]);
     }
     if ($success) {
         $message = $this->t('Credit card charged: @amount', ['@amount' => uc_currency_format($amount)]);
         uc_order_comment_save($order->id(), $user->id(), $message, 'admin');
     } else {
         $message = $this->t('Credit card charge failed.');
         uc_order_comment_save($order->id(), $user->id(), $message, 'admin');
     }
     $result = array('success' => $success, 'comment' => $this->t('Card charged, resolution code: 0022548315'), 'message' => $success ? $this->t('Credit card payment processed successfully.') : $this->t('Credit card charge failed.'), 'uid' => $user->id());
     return $result;
 }
Example #4
0
/**
 * @file
 * Saves a parsable inc file with the full color info array for the active theme.
 *
 * If a custom color scheme has been created in the UI it is injected into the
 * schemes array and saved. You must rename the Custom scheme and give it a
 * unique array key before using the generated file in your theme.
 *
 * Note that color module validates the input of the color form and this is not
 * run if there is a problem, e.g. the user inputting non hexadecimal CSS color
 * strings, which color module validates to avoid XSS.
 */
function at_core_submit_color(&$form, &$form_state) {

  $build_info = $form_state->getBuildInfo();
  $values = $form_state->getValues();
  $theme = $build_info['args'][0];

  $palette = $values['palette'];

  $indent = str_pad(' ', 6);
  $lines = explode("\n", var_export($palette, TRUE));

  array_shift($lines);

  $message  = "    'PaletteName' => array(\n";
  $message .= $indent . "'title' => t('PaletteName'),\n";
  $message .= $indent . "'colors' => array(\n";
  $last_line = $indent . array_pop($lines) . ',';

  foreach ($lines as $line) {
    if (strpos($line, ' => ') !== FALSE) {
      $parts = explode(' => ', $line);
      $message .= $indent . $parts[0] . str_pad(' ', (46 - strlen($line))) . '=> ' . $parts[1];
    } else {
      $message .=  "$indent  $line";
    }
    $message .=  "\n";
  }

  $message .= "$last_line\n";
  $message .= "    ),\n";
  $message = '<pre>' . $message . '</pre>';

  //watchdog('Custom color palette', $message);
  \Drupal::logger($theme)->notice($message);
}
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Pass the file to the parser.
     $fid = $form_state->getValue('mtg_import_json_file');
     $fid = reset($fid);
     if ($fid == 0) {
         return FALSE;
     }
     $file = File::load($fid);
     if (!$file) {
         drupal_set_message('Unable to load file.');
         \Drupal::logger('mtg_import')->error(t('Unable to load the file.'));
         return FALSE;
     }
     $uri = $file->uri->value;
     $file_contents_raw = file_get_contents($uri);
     $file_contents = json_decode($file_contents_raw);
     if (!empty($file_contents->cards)) {
         $operations = [['mtg_import_parse_set_data', [$file_contents]]];
         $chunks = array_chunk($file_contents->cards, 20);
         foreach ($chunks as $chunk) {
             $operations[] = ['mtg_import_parse_card_data', [$chunk]];
         }
         $batch = ['title' => t('Importing'), 'operations' => $operations, 'finished' => 'mtg_import_completed', 'progress_message' => t('Completed part @current of @total.')];
         batch_set($batch);
     } else {
         drupal_set_message(t('There are no cards in the file, so no import will take place.'), 'warning');
     }
 }
 /**
  * Simple reporter log and display information about the queue.
  *
  * @param int $worker
  *   Worker number.
  * @param object $item
  *   The $item which was stored in the cron queue.
  */
 protected function reportWork($worker, $item)
 {
     if (\Drupal::state()->get('cron_example_show_status_message')) {
         drupal_set_message($this->t('Queue @worker worker processed item with sequence @sequence created at @time', ['@worker' => $worker, '@sequence' => $item->sequence, '@time' => date_iso8601($item->created)]));
     }
     \Drupal::logger('cron_example')->info('Queue @worker worker processed item with sequence @sequence created at @time', ['@worker' => $worker, '@sequence' => $item->sequence, '@time' => date_iso8601($item->created)]);
 }
 /**
  * Determines the status of all user-contributed tests and logs any failures to
  * a tracking table.
  *
  * @param boolean $log
  *  (Optional) If TRUE, log all failures.
  *
  * @return array $custom_data
  *  An associative array containing any tests which failed validation.
  */
 public function testStatus($log = FALSE)
 {
     $custom_data = array();
     // Iterate through modules which contain hook_acquia_spi_test().
     foreach (\Drupal::moduleHandler()->getImplementations('acquia_connector_spi_test') as $module) {
         $function = $module . '_acquia_connector_spi_test';
         if (function_exists($function)) {
             $result = $this->testValidate($function());
             if (!$result['result']) {
                 $custom_data[$module] = $result;
                 foreach ($result['failure'] as $test_name => $test_failures) {
                     foreach ($test_failures as $test_param => $test_value) {
                         $variables = array('@module' => $module, '@message' => $test_value['message'], '@param_name' => $test_param, '@test' => $test_name, '@value' => $test_value['value']);
                         // Only log if we're performing a full validation check.
                         if ($log) {
                             drupal_set_message($this->t("Custom test validation failed for @test in @module and has been logged: @message for parameter '@param_name'; current value '@value'.", $variables), 'error');
                             \Drupal::logger('acquia spi test')->notice("<em>Custom test validation failed</em>: @message for parameter '@param_name'; current value '@value'. (<em>Test '@test_name' in module '@module_name'</em>)", $variables);
                         }
                     }
                 }
             }
         }
     }
     // If a full validation check is being performed, go to the status page to
     // show the results.
     if ($log) {
         $this->redirect('system.status');
     }
     return $custom_data;
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $entity = $this->getEntity();
     $entity->delete();
     \Drupal::logger('eck')->notice('@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label()));
     $form_state->setRedirectUrl(new Url('eck.entity.' . $this->entity->getEntityTypeId() . '.list'));
 }
 public function __construct($publication)
 {
     $this->publication = $this->convert_smart_quotes($publication);
     $this->remainingData = $this->publication;
     $this->logger = \Drupal::logger('import_publication');
     //$this->logger->notice(t("New Publication String:" . $this->publication));
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function query($group_by = FALSE) {
   try {
     $server = $this->query->getIndex()->getServer();
     if (!$server->supportsFeature('search_api_mlt')) {
       $backend_id = $server->getBackendId();
       \Drupal::logger('search_api')->error('The search backend "@backend_id" does not offer "More like this" functionality.',
         array('@backend_id' => $backend_id));
       $this->query->abort();
       return;
     }
     $fields = isset($this->options['fields']) ? $this->options['fields'] : array();
     if (!$fields) {
       foreach ($this->query->getIndex()->getOption('fields', array()) as $key => $field) {
         $fields[] = $key;
       }
     }
     $mlt = array(
       'id' => $this->argument,
       'fields' => $fields,
     );
     $this->query->getSearchApiQuery()->setOption('search_api_mlt', $mlt);
   }
   catch (SearchApiException $e) {
     $this->query->abort($e->getMessage());
   }
 }
 /**
  * {@inheritdoc}
  *
  * Delete the entity and log the event. log() replaces the watchdog.
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $entity = $this->getEntity();
     $entity->delete();
     \Drupal::logger('reservations')->notice('@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label()));
     $form_state->setRedirect('entity.reservation.list');
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->entity->delete();
     drupal_set_message($this->t('Domain %label has been deleted.', array('%label' => $this->entity->label())));
     \Drupal::logger('domain')->notice('Domain %label has been deleted.', array('%label' => $this->entity->label()));
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
 /**
  * Purges cache tags on CloudFlare.
  *
  * @todo Once https://github.com/d8-contrib-modules/cloudflare/issues/16 is
  *   done, this should disappear.
  *
  * @param string[] $tags
  *   The list of tags for which to invalidate cache items.
  */
 public function purgeTags(array $tags)
 {
     $config = \Drupal::config('cloudflare.settings');
     $api_key = $config->get('apikey');
     $email = $config->get('email');
     $zone = $config->get('zone');
     // If the module is not yet configured, don't attempt to purge.
     // @todo Improve the rest of the architecture of this module so this check
     //   is not necessary anymore.
     if (!isset($api_key)) {
         return;
     }
     try {
         $this->zoneApi = new ZoneApi($api_key, $email);
         // @todo rethink how to handle cloudflare zones in Drupal.
         if (is_null($zone)) {
             $zones = $this->zoneApi->listZones();
             $zone = $zones[0]->getZoneId();
         }
         $this->zoneApi->purgeTags($zone, $tags);
     } catch (CloudFlareHttpException $e) {
         drupal_set_message("Unable to clear zone cache. " . $e->getMessage(), 'error');
         \Drupal::logger('cloudflare')->error($e->getMessage());
         return;
     } catch (CloudFlareApiException $e) {
         drupal_set_message("Unable to clear zone cache. " . $e->getMessage(), 'error');
         \Drupal::logger('cloudflare')->error($e->getMessage());
         return;
     }
     // If no exceptions have been thrown then the request has been successful.
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->entity->delete();
     drupal_set_message(t('Newsletter %label has been deleted.', array('%label' => $this->entity->label())));
     \Drupal::logger('simplenews')->notice('Newsletter %label has been deleted.', array('%label' => $this->entity->label()));
     $form_state->setRedirect('simplenews.newsletter_list');
 }
Example #15
0
 /**
  * {@inheritdoc}
  *
  * Delete the entity and log the event. log() replaces the watchdog.
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $entity = $this->getEntity();
     $entity->delete();
     \Drupal::logger('content_entity_example')->notice('@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label()));
     $form_state->setRedirect('entity.content_entity_example_contact.collection');
 }
 /**
  * Access callback for json() callback.
  */
 public function access()
 {
     $request = \Drupal::request();
     $nonce = $request->get('nonce', FALSE);
     $connector_config = $this->config('acquia_connector.settings');
     // If we don't have all the query params, leave now.
     if (!$nonce) {
         return AccessResultForbidden::forbidden();
     }
     $sub_data = $connector_config->get('subscription_data');
     $sub_uuid = $this->getIdFromSub($sub_data);
     if (!empty($sub_uuid)) {
         $expected_hash = hash('sha1', "{$sub_uuid}:{$nonce}");
         // If the generated hash matches the hash from $_GET['key'], we're good.
         if ($request->get('key', FALSE) === $expected_hash) {
             return AccessResultAllowed::allowed();
         }
     }
     // Log the request if validation failed and debug is enabled.
     if ($connector_config->get('debug')) {
         $info = array('sub_data' => $sub_data, 'sub_uuid_from_data' => $sub_uuid, 'expected_hash' => $expected_hash, 'get' => $request->query->all(), 'server' => $request->server->all(), 'request' => $request->request->all());
         \Drupal::logger('acquia_agent')->notice('Site status request: @data', array('@data' => var_export($info, TRUE)));
     }
     return AccessResultForbidden::forbidden();
 }
 /**
  * {@inheritdoc}
  */
 public function endpoint($hash)
 {
     $return = 0;
     if (!empty($_POST)) {
         $data = $_POST['data'];
         $type = $_POST['type'];
         switch ($type) {
             case 'unsubscribe':
             case 'profile':
             case 'cleaned':
                 mailchimp_get_memberinfo($data['list_id'], $data['email'], TRUE);
                 break;
             case 'upemail':
                 mailchimp_cache_clear_member($data['list_id'], $data['old_email']);
                 mailchimp_get_memberinfo($data['list_id'], $data['new_email'], TRUE);
                 break;
             case 'campaign':
                 mailchimp_cache_clear_list_activity($data['list_id']);
                 mailchimp_cache_clear_campaign($data['id']);
                 break;
         }
         // Allow other modules to act on a webhook.
         \Drupal::moduleHandler()->invokeAll('mailchimp_process_webhook', array($type, $data));
         // Log event.
         \Drupal::logger('mailchimp')->info('Webhook type {type} has been processed.', array('type' => $type));
         $return = 1;
     }
     // TODO: There should be a better way of doing this.
     // D8 routing doesn't seem to allow us to return a single character
     // or string from a controller.
     echo $return;
     exit;
 }
 /**
  * {@inheritdoc}
  */
 public function assignPackages($force = FALSE)
 {
     $current_bundle = $this->assigner->getBundle();
     $settings = $current_bundle->getAssignmentSettings(self::METHOD_ID);
     $config_base_types = $settings['types']['config'];
     $config_types = $this->featuresManager->listConfigTypes();
     $config_collection = $this->featuresManager->getConfigCollection();
     foreach ($config_collection as $item_name => $item) {
         if (in_array($item['type'], $config_base_types)) {
             if (!isset($packages[$item['name_short']]) && !isset($item['package'])) {
                 $description = $this->t('Provide @label @type and related configuration.', array('@label' => $item['label'], '@type' => Unicode::strtolower($config_types[$item['type']])));
                 if (isset($item['data']['description'])) {
                     $description .= ' ' . $item['data']['description'];
                 }
                 $this->featuresManager->initPackage($item['name_short'], $item['label'], $description);
                 try {
                     $this->featuresManager->assignConfigPackage($item['name_short'], [$item_name]);
                 } catch (\Exception $exception) {
                     \Drupal::logger('features')->error($exception->getMessage());
                 }
                 $this->featuresManager->assignConfigDependents([$item_name]);
             }
         }
     }
     $entity_types = $this->entityManager->getDefinitions();
     $content_base_types = $settings['types']['content'];
     foreach ($content_base_types as $entity_type_id) {
         if (!isset($packages[$entity_type_id]) && isset($entity_types[$entity_type_id])) {
             $label = $entity_types[$entity_type_id]->getLabel();
             $description = $this->t('Provide @label related configuration.', array('@label' => $label));
             $this->featuresManager->initPackage($entity_type_id, $label, $description);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->entity->delete();
     $t_args = array('%name' => $this->entity->label());
     drupal_set_message($this->t('The contact type %name has been deleted.', $t_args));
     \Drupal::logger('node')->notice('Deleted contact type %name.', $t_args);
     $form_state->setRedirect('entity.crm_core_contact_type.collection');
 }
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $meetupPull = new MeetupPull();
     $message = $this->t($meetupPull->meetupPull());
     $message .= $this->t('<br>(run manually)');
     \Drupal::logger('meetup_pull')->notice($message);
     drupal_set_message($message);
 }
Example #21
0
 function __construct()
 {
     $this->config['transport'] = \Drupal::config('swiftmailer.transport')->getRawData();
     $this->config['message'] = \Drupal::config('swiftmailer.message')->getRawData();
     $this->logger = \Drupal::logger('swiftmailer');
     $this->renderer = \Drupal::service('renderer');
     $this->moduleHandler = \Drupal::moduleHandler();
 }
Example #22
0
 /**
  * {@inheritdoc}
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition)
 {
     // Once per filter, log that a filter plugin was missing.
     if (!$this->logged) {
         $this->logged = TRUE;
         \Drupal::logger('filter')->alert('Missing filter plugin: %filter.', array('%filter' => $plugin_id));
     }
     parent::__construct($configuration, $plugin_id, $plugin_definition);
 }
Example #23
0
 /**
  * {@inheritdoc}
  *
  * Delete the entity and log the event. log() replaces the watchdog.
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $entity = $this->getEntity();
     $entity->delete();
     $type = $entity->getEntityType()->id();
     $title = empty($this->entity->label()) ? $this->entity->id() : $this->entity->label();
     \Drupal::logger($type)->notice('@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $title));
     $form_state->setRedirect('entity.' . $type . '.collection');
 }
Example #24
0
 public function createForm(&$bundle_info)
 {
     if (!\Drupal::entityQuery('contact_form')->condition('id', $bundle_info['id'])->execute()) {
         $form_type = ContactForm::create(array('id' => $bundle_info['id'], 'label' => ucwords(str_replace('_', ' ', $bundle_info['id'])), 'type' => "contact_form"))->save();
         \Drupal::logger('clutch:workflow')->notice('Create bundle @bundle', array('@bundle' => $bundle_info, 'form' => $form_type));
         $this->createFields($bundle_info);
         $this->removeDefaultFormFields($bundle_info);
     }
 }
 /**
  * Calls assignConfigPackage without allowing exceptions to abort us.
  *
  * @param string $machine_name
  *   Machine name of package.
  * @param \Drupal\Core\Extension\Extension $extension
  *   An Extension object.
  */
 protected function safeAssignConfig($machine_name, $extension)
 {
     $config = $this->featuresManager->listExtensionConfig($extension);
     try {
         $this->featuresManager->assignConfigPackage($machine_name, $config);
     } catch (\Exception $exception) {
         \Drupal::logger('features')->error($exception->getMessage());
     }
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 protected function execute(array $arguments)
 {
     // PHP installations using non-bundled GD do not have imagefilter.
     if (!function_exists('imagefilter')) {
         \Drupal::logger('image')->notice("The image '@file' could not be desaturated because the imagefilter() function is not available in this PHP installation.", array('@file' => $this->getToolkit()->getImage()->getSource()));
         return FALSE;
     }
     return imagefilter($this->getToolkit()->getResource(), IMG_FILTER_GRAYSCALE);
 }
Example #27
0
/**
 * Respond to a file that has been moved.
 *
 * @param \Drupal\file\FileInterface $file
 *   The updated file entity after the move.
 * @param \Drupal\file\FileInterface $source
 *   The original file entity before the move.
 *
 * @see file_move()
 */
function hook_file_move(Drupal\file\FileInterface $file, Drupal\file\FileInterface $source)
{
    // Make sure that the file name starts with the owner's user name.
    if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) {
        $file->setFilename($file->getOwner()->name . '_' . $file->getFilename());
        $file->save();
        \Drupal::logger('file')->notice('Moved file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename()));
    }
}
Example #28
0
 /**
  * Processes a payment POST from the CyberSource Hosted Order Page API.
  */
 public static function post()
 {
     if (!uc_cybersource_hop_include()) {
         \Drupal::logger('uc_cybersource_hop')->error('Unable to receive HOP POST due to missing or unreadable HOP.php file.');
         drupal_add_http_header('Status', '503 Service unavailable');
         print $this->t('The site was unable to receive a HOP post because of a missing or unreadble HOP.php');
         exit;
     }
     $verify = VerifyTransactionSignature($_POST);
     \Drupal::logger('uc_cybersource_hop')->notice('Receiving payment notification at URL for order @orderNumber', array('@orderNumber' => $_POST['orderNumber']));
     if (!isset($_POST['orderNumber'])) {
         \Drupal::logger('uc_cybersource_hop')->error('CS HOP attempted with invalid order number.');
         return;
     }
     if (!$verify) {
         \Drupal::logger('uc_cybersource_hop')->notice('Receiving invalid payment notification at URL for order @orderNumber. <pre>@debug</pre>', array('@orderNumber' => $_POST['orderNumber'], '@debug' => print_r($_POST, TRUE)));
         return;
     }
     // Assign posted variables to local variables.
     $decision = SafeMarkup::checkPlain($_POST['decision']);
     $reason_code = SafeMarkup::checkPlain($_POST['reasonCode']);
     $reason = _parse_cs_reason_code($reason_code);
     $payment_amount = SafeMarkup::checkPlain($_POST['orderAmount']);
     $payment_currency = SafeMarkup::checkPlain($_POST['paymentCurrency']);
     $request_id = SafeMarkup::checkPlain($_POST['requestID']);
     $request_token = SafeMarkup::checkPlain($_POST['orderPage_requestToken']);
     $reconciliation_id = SafeMarkup::checkPlain($_POST['reconciliationID']);
     $order_id = SafeMarkup::checkPlain($_POST['orderNumber']);
     $payer_email = SafeMarkup::checkPlain($_POST['billTo_email']);
     $order = Order::load($_POST['orderNumber']);
     switch ($decision) {
         case 'ACCEPT':
             \Drupal::logger('uc_cybersource_hop')->notice('CyberSource verified successful payment.');
             $duplicate = (bool) db_query_range('SELECT 1 FROM {uc_payment_cybersource_hop_post} WHERE order_id = :order_id AND decision = :decision', 0, 1, array(':order_id' => $order_id, ':decision' => 'ACCEPT'))->fetchField();
             if ($duplicate) {
                 \Drupal::logger('uc_cybersource_hop')->notice('CS HOP transaction for order @order-id has been processed before.', array('@order_id' => $order_id));
                 return;
             }
             db_insert('uc_payment_cybersource_hop_post')->fields(array('order_id' => $order_id, 'request_id' => $request_id, 'request_token' => $request_token, 'reconciliation_id' => $reconciliation_id, 'gross' => $payment_amount, 'decision' => $decision, 'reason_code' => $reason_code, 'payer_email' => $payer_email, 'received' => REQUEST_TIME))->execute();
             $comment = $this->t('CyberSource request ID: @txn_id', array('@txn_id' => $request_id));
             uc_payment_enter($order_id, 'cybersource_hop', $payment_amount, $order->getUserId(), NULL, $comment);
             uc_cart_complete_sale($order);
             uc_order_comment_save($order_id, 0, $this->t('Payment of @amount @currency submitted through CyberSource with request ID @rid.', array('@amount' => $payment_amount, '@currency' => $payment_currency, '@rid' => $request_id)), 'order', 'payment_received');
             break;
         case 'ERROR':
             uc_order_comment_save($order_id, 0, $this->t("Payment error:@reason with request ID @rid", array('@reason' => $reason, '@rid' => '@request_id')), 'admin');
             break;
         case 'REJECT':
             uc_order_comment_save($order_id, 0, $this->t("Payment is rejected:@reason with request ID @rid", array('@reason' => $reason, '@rid' => '@request_id')), 'admin');
             break;
         case 'REVIEW':
             $order->setStatusId('review')->save();
             uc_order_comment_save($order_id, 0, $this->t('Payment is in review & not complete: @reason. Request ID @rid', array('@reason' => $reason, '@rid' => '@request_id')), 'admin');
             break;
     }
 }
Example #29
0
 /**
  * Submit the POST request with the specified parameters.
  *
  * @param RequestParameters $params
  *   Request parameters
  *
  * @return string
  *   Body of the reCAPTCHA response
  */
 public function submit(RequestParameters $params)
 {
     try {
         $options = ['headers' => ['Content-type' => 'application/x-www-form-urlencoded'], 'body' => $params->toQueryString()];
         $response = \Drupal::httpClient()->post(self::SITE_VERIFY_URL, $options);
     } catch (RequestException $exception) {
         \Drupal::logger('reCAPTCHA web service')->error($exception);
     }
     return (string) $response->getBody();
 }
Example #30
0
 /**
  * SEND MESSAGE to logger and message status bar
  *
  * @param string $severity
  *   info, error
  *
  * @param string $type
  *   message type (create, update, delete)
  *
  * @param array $entry
  *   An array containing all the fields used
  */
 public static function logAndDsm($severity = 'info', $type = 'Oups', $entry = array())
 {
     if ($severity == 'info') {
         \Drupal::logger('BB')->info('%type --- %entry', array('%type' => $type, '%entry' => urldecode(http_build_query($entry, '', ', '))));
         drupal_set_message(t('%type --- %entry', array('%type' => $type, '%entry' => http_build_query($entry, '', ', '))));
     } elseif ($severity = 'error') {
         \Drupal::logger('BB')->error('%type --- %entry', array('%type' => $type, '%entry' => http_build_query($entry, '', ', ')));
         drupal_set_message(t('%type --- %entry', array('%type' => $type, '%entry' => http_build_query($entry, '', ', '))), 'error');
     }
 }