You are here

function mailchimp_process_webhook in Mailchimp 2.x

Same name and namespace in other branches
  1. 8 mailchimp.module \mailchimp_process_webhook()
  2. 7.5 mailchimp.module \mailchimp_process_webhook()
  3. 7.2 mailchimp.module \mailchimp_process_webhook()
  4. 7.3 mailchimp.module \mailchimp_process_webhook()
  5. 7.4 mailchimp.module \mailchimp_process_webhook()

Processes a webhook post from Mailchimp.

File

./mailchimp.module, line 1054
Mailchimp module.

Code

function mailchimp_process_webhook() {
  if (!isset($_POST)) {
    return "Mailchimp Webhook Endpoint.";
  }
  $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', [
    $type,
    $data,
  ]);

  // Log event:
  \Drupal::logger('mailchimp')
    ->info('Webhook type {type} has been processed.', [
    'type' => $type,
  ]);
  return NULL;
}