/**
  * @param MailChimp $mailChimp
  * @param Request $request
  * @return array
  */
 public function index(MailChimp $mailChimp, Request $request)
 {
     try {
         $result = $mailChimp->call('lists/members', ['id' => env('MAILCHIMP_DEFAULT_LIST_ID'), 'opts' => ['start' => $request->get('page', 1) - 1, 'limit' => 25], 'status' => $request->get('filter', 'subscribed')]);
         return $result;
     } catch (\Exception $e) {
         dd($e->getMessage());
     }
 }
 /**
  * @param Request $request
  * @param MailChimp $mailChimp
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store(Request $request, MailChimp $mailChimp)
 {
     $this->validate($request, ['email' => 'required|email']);
     try {
         $mailChimp->call('lists/subscribe', ['id' => env('MAILCHIMP_DEFAULT_LIST_ID'), 'email' => ['email' => $request->get('email')], 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false]);
         return redirect()->back()->with('newsletter.subscription', 'success');
     } catch (\Exception $e) {
         app('log')->error('newsletter', ['route' => 'store.newsletter.store', 'message' => $e->getMessage(), 'line' => $e->getLine(), 'file' => $e->getFile()]);
     }
     return redirect()->back()->with('newsletter.subscription', 'failed');
 }
 /**
  * @param MailChimp $mailChimp
  * @param CampaignConfig $config
  * @param CampaignBuilder $builder
  * @return bool|null|void
  */
 public function handle(MailChimp $mailChimp, CampaignConfig $config, CampaignBuilder $builder)
 {
     $campaign = $this->campaign->translate($this->locale);
     try {
         $content = $builder->build($this->campaign, $this->locale);
     } catch (Exception $e) {
         throw new HttpException(400, 'There was a problem, check for any unfinished widgets', null, ['reason' => 'There was a problem, check for any unfinished widgets']);
     }
     try {
         $result = $mailChimp->call('campaigns/create', ['type' => 'regular', 'options' => ['list_id' => env('MAILCHIMP_DEFAULT_LIST_ID'), 'subject' => $campaign->subject, 'from_email' => $config->fromEmail(), 'from_name' => $config->fromName(), 'to_name' => $config->toName(), 'title' => $campaign->title], 'content' => ['html' => $content]]);
         if ($result && isset($result['id'])) {
             $campaign->mail_chimp_campaign_id = $result['id'];
             return $campaign->save() ? $campaign : false;
         }
     } catch (Exception $e) {
         throw new HttpException(400, 'Cannot contact mailservice, try again later', null, ['reason' => 'Cannot contact mailservice, try again later']);
     }
 }
 /**
  * Subscribe to Mailchimp BlueRidge Users list
  * @return Void
  */
 public function perform()
 {
     $blueridge = new Application();
     $postman = $blueridge['configs']['services']['mailchimp'];
     $userQr = $blueridge['documentManager']->getRepository('\\Blueridge\\Documents\\User');
     $user = $userQr->find($this->args['userid']);
     if (empty($user)) {
         return;
     }
     try {
         $mailChimpClient = new MailChimp($postman['api_key']);
         $args = ['id' => $postman['list_id'], 'email' => ['email' => $user->email], 'merge_vars' => ['FNAME' => $user->firstName, 'LNAME' => $user->lastName, 'groupings' => [['id' => $postman['groupings_id'], 'groups' => $this->args['groups']]]], 'double_optin' => false, 'update_existing' => true, 'replace_interests' => true];
         if ($user->status = 'new') {
             $args['send_welcome'] = true;
         }
         $result = $mailChimpClient->call('lists/subscribe', $args);
     } catch (\Exception $e) {
         error_log($e->getMessage());
     }
 }
Example #5
0
 /**
  * Get lists from mailchimp account
  *
  * @return mixed
  */
 public function getLists()
 {
     $params = array('filters' => array(), 'start' => 0, 'limit' => 25, 'sort_field' => 'created', 'sort_dir' => 'DESC');
     return $this->mailchimp->call('lists/list', $params);
 }
Example #6
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     /**
      * If scope/code not set, go home.
      */
     if (!isset($_GET['code'])) {
         $this->go_home();
     }
     /**
      * This method is used to get the access token from stripe,
      * by passing in the Auth returned code.
      */
     $client = new Client();
     $response = $client->post('https://login.uber.com/oauth/token', ['body' => ['client_id' => env('UBER_CLIENT_ID'), 'client_secret' => env('UBER_CLIENT_SECRET'), 'redirect_uri' => env('UBER_REDIRECT_URI'), 'code' => $_GET['code'], 'grant_type' => 'authorization_code']])->json();
     $client = new UberClient(array('access_token' => $response['access_token'], 'server_token' => env('UBER_SERVER_TOKEN'), 'use_sandbox' => false, 'version' => 'v1', 'locale' => 'en_US'));
     $uber_profile = $client->getProfile();
     $client_new = new UberClient(array('access_token' => $response['access_token'], 'server_token' => env('UBER_SERVER_TOKEN'), 'use_sandbox' => false, 'version' => 'v1.1', 'locale' => 'en_US'));
     $history = $client_new->getHistory(array('limit' => 50, 'offset' => 0));
     if ($history->count == 0) {
         $queryString = http_build_query(array('failed' => '2'));
         header("Location: " . action('PagesController@home', $queryString));
     }
     /**
      * We're not using users or accounts here, so we're going to
      * save the data inside a Session. We will use a common key
      * naming system that prevents multiple sessions being
      * created for the same user / data.
      * @todo encrypt sessions (http://laravel.com/docs/5.0/session)
      * @todo and SAVE profile data in cache, DB, if successful
      */
     $utid = substr($uber_profile->uuid, -8);
     $data = ['utid' => $utid, 'uuid' => $uber_profile->uuid, 'access_token' => $response['access_token'], 'refresh_token' => $response['refresh_token']];
     /**
      * Handle DB adding, updating stuff.
      * @var DB $uber
      */
     $uber = Uber::firstOrCreate(['uuid' => $uber_profile->uuid]);
     $uber->utid = $utid;
     $uber->access_token = $response['access_token'];
     $uber->refresh_token = $response['refresh_token'];
     $uber->save();
     /**
      * Save to session.
      */
     Session::put('uber_profile', $data);
     if ($response['access_token']) {
         $params = array('utid' => $utid);
     } else {
         $params = array('uber' => 'failed', 'error' => 1);
     }
     /**
      * Add them to MailChimp List
      */
     $MailChimp = new MailChimp(env('MAILCHIMP_ID'));
     $MailChimp->call('lists/subscribe', array('id' => env('MAILCHIMP_LIST'), 'email' => array('email' => $uber_profile->email), 'merge_vars' => array('FNAME' => $uber_profile->first_name, 'LNAME' => $uber_profile->last_name), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false));
     /**
      * Redirect as needed.
      */
     $queryString = http_build_query($params);
     header("Location: " . action('PagesController@home', $queryString));
     // Cannot die(); as this breaks the session storage
 }
<?php

include 'MailChimp.php';
use DrewM\MailChimp;
date_default_timezone_set('UTC');
$json_file = $argv[1];
$api_key = $argv[2];
$newsletter = $argv[3];
$date = date('d-M-Y');
$html = file_get_contents($newsletter);
$json = json_decode(file_get_contents($json_file));
$args['type'] = 'regular';
$args['options'] = array('list_id' => '47b5e51c86', 'subject' => $json->subject_line, 'from_email' => '*****@*****.**', 'from_name' => 'The Food Rush', 'tracking' => array('opens' => true, 'html_clicks' => true, 'text_clicks' => false), 'authenticate' => false, 'analytics' => array('google' => 'atphga'), 'title' => 'Food Rush Newsletter - ' . $date, 'auto_footer' => false, 'generate_text' => true);
$args['content'] = array('html' => $html);
$MailChimp = new MailChimp($api_key);
$result = $MailChimp->call('campaigns/create', $args);
if (!empty($result)) {
    echo "Successfully created new campaign!";
} else {
    echo "Error creating new campaign.";
    echo $MailChimp->getLastError();
}
<?php

include 'MailChimp.php';
use DrewM\MailChimp;
date_default_timezone_set('UTC');
$json_file = $argv[1];
$api_key = $argv[2];
$newsletter = $argv[3];
$date = date('d-M-Y');
$html = file_get_contents($newsletter);
$thefoodrush = json_decode(file_get_contents($json_file));
$args['type'] = 'regular';
$args['options'] = array('list_id' => '47b5e51c86', 'subject' => $thefoodrush->subject_line, 'from_email' => '*****@*****.**', 'from_name' => 'The Food Rush', 'tracking' => array('opens' => true, 'html_clicks' => true, 'text_clicks' => false), 'authenticate' => false, 'analytics' => array('google' => 'atphga'), 'title' => 'Food Rush Magazine - ' . $date, 'auto_footer' => false, 'generate_text' => true);
$args['content'] = array('html' => $html);
$MailChimp = new MailChimp($api_key);
$campaign_id = $MailChimp->call('campaigns/create', $args);
if (isset($result->status) && $result->status == 'error') {
    echo "Error creating new campaign.";
} else {
    echo "Successfully created new campaign!";
}
 public function getValueFromData($data)
 {
     $data = Session::get("FormInfo.Form_Form.data");
     $map = $this->getNewsLetterFieldNames();
     $value = isset($data[$this->Name]) ? $data[$this->Name] : false;
     $list = $this->getMC('lists');
     if ($value) {
         $MailChimp = new MailChimp($this->get_api_key());
         $result = $MailChimp->call('lists/subscribe', array('id' => $list['id'], 'email' => array('email' => $data[$map['EMAIL']['name']]), 'merge_vars' => array('FNAME' => $data[$map['FNAME']['name']], 'LNAME' => $data[$map['LNAME']['name']]), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => true));
         return $value ? $value : _t('EditableFormField.NO', 'No');
     }
 }
 /**
  * @param MailChimp $mailChimp
  * @param $translation
  * @return Collection
  */
 protected function getReportSummary(MailChimp $mailChimp, $translation)
 {
     $result = $mailChimp->call('reports/summary', ['cid' => $translation->mail_chimp_campaign_id]);
     $reportFormatter = new ReportFormatter();
     return $reportFormatter->format($result);
 }