client = new KlaviyoV3Api(Configuration::get('KLAVIYO_PUBLIC_API'), Configuration::get('KLAVIYO_PRIVATE_API')); } /** * Get all lists for specific Klaviyo account. * * @return mixed */ public function getLists() { return $this->client->getLists(); } /** * Subscribe email to the Subscriber List selected on configuration page (if selected). * * @param string $email * @throws KlaviyoApiException */ public function subscribeCustomer($email) { $profile = array( 'type' => 'profile', 'attributes' => array( 'email' => $email, 'subscriptions' => array( 'email' => [ 'MARKETING' ] ) ) ); $listId = Configuration::get('KLAVIYO_SUBSCRIBER_LIST'); if ($listId) { $this->client->subscribeMembersToList($listId, array($profile)); } } /** * Subscribe email to the Subscriber List selected on configuration page (if selected). * * @param array $email * @throws KlaviyoApiException */ public function subscribeSMSCustomer($address) { $attributes = [ 'subscriptions' => [ 'sms' => [ 'MARKETING' ] ] ]; if (isset($address['mobile'])) { $attributes['phone_number'] = $address['mobile']; } if (isset($address['email'])) { $attributes['email'] = $address['email']; } $profile = array( 'type' => 'profile', 'attributes' => $attributes, ); $listId = Configuration::get('KLAVIYO_SMS_SUBSCRIBER_LIST'); if ($listId) { $this->client->subscribeMembersToList($listId, array($profile)); } } /** * @param string $email * @param array $properties * @return array * @throws KlaviyoApiException * @throws KlaviyoAuthenticationException * @throws KlaviyoRateLimitException */ public function updateProfileCustomProperties($email, $properties) { return $this->client->updateProfileCustomProperties($email, $properties); } /** * Send event to Klaviyo using the Track endpoint. * * @param array $event * @return bool * @throws KlaviyoApiException */ public function trackEvent(array $eventConfig) { $responseData = $this->client->createEvent($eventConfig); if (isset($responseData['errors']) && is_array($responseData['errors']) && !empty($responseData['errors'])) { return false; } return true; } }