public function composeSubscriberSubmission($newSubscribers = [])
    {

        $composedSubscriberList = [];
        foreach ($newSubscribers as $newSubscriberCount => $newSubscriber) {
            if (isset($newSubscriber['birthdate']) && is_int($newSubscriber['birthdate'])) {
                $newSubscriber['birthdate_timestamp'] = $newSubscriber['birthdate'];
            }
            if (isset($newSubscriber['mobile']) && strlen($newSubscriber['mobile']) < 8) {
                unset($newSubscriber['mobile']);
            }

            // support different merge_vars for US vs UK
            if (isset($newSubscriber['application_id']) && $newSubscriber['application_id'] == 'UK') {
                $mergeVars = [
                    'FNAME' => isset($newSubscriber['fname']) ? $newSubscriber['fname'] : '',
                    'LNAME' => isset($newSubscriber['lname']) ? $newSubscriber['lname'] : '',
                    'MERGE3' => isset($newSubscriber['birthdate_timestamp']) ? date('d/m/Y',
                        $newSubscriber['birthdate_timestamp']) : '',
                ];
            } // Don't add Canadian users to MailChimp
            elseif (isset($newSubscriber['application_id']) && $newSubscriber['application_id'] == 'CA') {
                $this->channel->basic_ack($newSubscriber['mb_delivery_tag']);
                break;
            } else {
                $mergeVars = [
                    'UID' => isset($newSubscriber['uid']) ? $newSubscriber['uid'] : '',
                    'FNAME' => isset($newSubscriber['fname']) ? $newSubscriber['fname'] : '',
                    'MERGE3' => (isset($newSubscriber['fname']) && isset($newSubscriber['lname'])) ?
                        $newSubscriber['fname'] . $newSubscriber['lname'] : '',
                    'BDAY' => isset($newSubscriber['birthdate_timestamp']) ?
                        date('m/d', $newSubscriber['birthdate_timestamp']) : '',
                    'BDAYFULL' => isset($newSubscriber['birthdate_timestamp']) ?
                        date('m/d/Y', $newSubscriber['birthdate_timestamp']) : '',
                    'MOBILE' => isset($newSubscriber['mobile']) ? $newSubscriber['mobile'] : '',
                ];
            }

            // Assign source interest group. Only support on main DoSomething Members List
            // @todo: Support "id" as a variable. Perhaps a config setting keyed on countries / global.
            if (isset($newSubscriber['source']) &&
                isset($newSubscriber['user_country']) &&
                strtoupper($newSubscriber['user_country']) == 'US')
            {
                $mergeVars['groupings'] = [
                    0 => [
                      'id' => 10657,  // DoSomething Memebers -> Import Source
                      'groups' => [
                          $newSubscriber['source']
                      ]
                    ],
                ];
            }

            $composedSubscriberList[$newSubscriberCount] = [
                'email' => [
                  'email' => $newSubscriber['email']
                ],
                'merge_vars' => $mergeVars
            ];
        }

        return $composedSubscriberList;
    }
public function composeSubscriberSubmission($newSubscribers = [])
    {

        $composedSubscriberList = [];
        foreach ($newSubscribers as $newSubscriberCount => $newSubscriber) {
            if (isset($newSubscriber['birthdate']) && is_int($newSubscriber['birthdate'])) {
                $newSubscriber['birthdate_timestamp'] = $newSubscriber['birthdate'];
            }
            if (isset($newSubscriber['mobile']) && strlen($newSubscriber['mobile']) < 8) {
                unset($newSubscriber['mobile']);
            }

            // support different merge_vars for US vs UK
            if (isset($newSubscriber['application_id']) && $newSubscriber['application_id'] == 'UK') {
                $mergeVars = [
                    'FNAME' => isset($newSubscriber['fname']) ? $newSubscriber['fname'] : '',
                    'LNAME' => isset($newSubscriber['lname']) ? $newSubscriber['lname'] : '',
                    'MERGE3' => isset($newSubscriber['birthdate_timestamp']) ? date('d/m/Y',
                        $newSubscriber['birthdate_timestamp']) : '',
                ];
            } // Don't add Canadian users to MailChimp
            elseif (isset($newSubscriber['application_id']) && $newSubscriber['application_id'] == 'CA') {
                $this->channel->basic_ack($newSubscriber['mb_delivery_tag']);
                break;
            } else {
                $mergeVars = [
                    'UID' => isset($newSubscriber['uid']) ? $newSubscriber['uid'] : '',
                    'FNAME' => isset($newSubscriber['fname']) ? $newSubscriber['fname'] : '',
                    'MERGE3' => (isset($newSubscriber['fname']) && isset($newSubscriber['lname'])) ?
                        $newSubscriber['fname'] . $newSubscriber['lname'] : '',
                    'BDAY' => isset($newSubscriber['birthdate_timestamp']) ?
                        date('m/d', $newSubscriber['birthdate_timestamp']) : '',
                    'BDAYFULL' => isset($newSubscriber['birthdate_timestamp']) ?
                        date('m/d/Y', $newSubscriber['birthdate_timestamp']) : '',
                    'MOBILE' => isset($newSubscriber['mobile']) ? $newSubscriber['mobile'] : '',
                ];
            }

            // Assign source interest group. Only support on main DoSomething Members List
            // @todo: Support "id" as a variable. Perhaps a config setting keyed on countries / global.
            if (isset($newSubscriber['source']) &&
                isset($newSubscriber['user_country']) &&
                strtoupper($newSubscriber['user_country']) == 'US')
            {
                $mergeVars['groupings'] = [
                    0 => [
                      'id' => 10657,  // DoSomething Memebers -> Import Source
                      'groups' => [
                          $newSubscriber['source']
                      ]
                    ],
                ];
            }

            $composedSubscriberList[$newSubscriberCount] = [
                'email' => [
                  'email' => $newSubscriber['email']
                ],
                'merge_vars' => $mergeVars
            ];
        }

        return $composedSubscriberList;
    }
public function composeSubscriberSubmission ( $ newSubscribers = [ ] ) { $ composedSubscriberList = [ ] ; foreach ( $ newSubscribers as $ newSubscriberCount => $ newSubscriber ) { if ( isset ( $ newSubscriber [ 'birthdate' ] ) && is_int ( $ newSubscriber [ 'birthdate' ] ) ) { $ newSubscriber [ 'birthdate_timestamp' ] = $ newSubscriber [ 'birthdate' ] ; } if ( isset ( $ newSubscriber [ 'mobile' ] ) && strlen ( $ newSubscriber [ 'mobile' ] ) < 8 ) { unset ( $ newSubscriber [ 'mobile' ] ) ; } // support different merge_vars for US vs UK if ( isset ( $ newSubscriber [ 'application_id' ] ) && $ newSubscriber [ 'application_id' ] == 'UK' ) { $ mergeVars = [ 'FNAME' => isset ( $ newSubscriber [ 'fname' ] ) ? $ newSubscriber [ 'fname' ] : '' , 'LNAME' => isset ( $ newSubscriber [ 'lname' ] ) ? $ newSubscriber [ 'lname' ] : '' , 'MERGE3' => isset ( $ newSubscriber [ 'birthdate_timestamp' ] ) ? date ( 'd/m/Y' , $ newSubscriber [ 'birthdate_timestamp' ] ) : '' , ] ; } // Don't add Canadian users to MailChimp elseif ( isset ( $ newSubscriber [ 'application_id' ] ) && $ newSubscriber [ 'application_id' ] == 'CA' ) { $ this -> channel -> basic_ack ( $ newSubscriber [ 'mb_delivery_tag' ] ) ; break ; } else { $ mergeVars = [ 'UID' => isset ( $ newSubscriber [ 'uid' ] ) ? $ newSubscriber [ 'uid' ] : '' , 'FNAME' => isset ( $ newSubscriber [ 'fname' ] ) ? $ newSubscriber [ 'fname' ] : '' , 'MERGE3' => ( isset ( $ newSubscriber [ 'fname' ] ) && isset ( $ newSubscriber [ 'lname' ] ) ) ? $ newSubscriber [ 'fname' ] . $ newSubscriber [ 'lname' ] : '' , 'BDAY' => isset ( $ newSubscriber [ 'birthdate_timestamp' ] ) ? date ( 'm/d' , $ newSubscriber [ 'birthdate_timestamp' ] ) : '' , 'BDAYFULL' => isset ( $ newSubscriber [ 'birthdate_timestamp' ] ) ? date ( 'm/d/Y' , $ newSubscriber [ 'birthdate_timestamp' ] ) : '' , 'MOBILE' => isset ( $ newSubscriber [ 'mobile' ] ) ? $ newSubscriber [ 'mobile' ] : '' , ] ; } // Assign source interest group. Only support on main DoSomething Members List // @todo: Support "id" as a variable. Perhaps a config setting keyed on countries / global. if ( isset ( $ newSubscriber [ 'source' ] ) && isset ( $ newSubscriber [ 'user_country' ] ) && strtoupper ( $ newSubscriber [ 'user_country' ] ) == 'US' ) { $ mergeVars [ 'groupings' ] = [ 0 => [ 'id' => 10657 , // DoSomething Memebers -> Import Source 'groups' => [ $ newSubscriber [ 'source' ] ] ] , ] ; } $ composedSubscriberList [ $ newSubscriberCount ] = [ 'email' => [ 'email' => $ newSubscriber [ 'email' ] ] , 'merge_vars' => $ mergeVars ] ; } return $ composedSubscriberList ; }
Format email list to meet MailChimp API requirements for batchSubscribe

@param array $newSubscribers
The list of email address to be formatted

@return array
Array of email addresses formatted to meet MailChimp API requirements.
Format email list to meet MailChimp API requirements for batchSubscribe