-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
325dde2
commit 6899d85
Showing
9 changed files
with
773 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use Configuration; | ||
use KlaviyoV3Sdk\Exception\KlaviyoApiException; | ||
use KlaviyoV3Sdk\Klaviyo; | ||
use KlaviyoV3Sdk\KlaviyoV3Api; | ||
use KlaviyoV3Sdk\Exception; | ||
|
||
class KlaviyoApiWrapper | ||
{ | ||
/** @var Klaviyo Client for Klaviyo's Api. */ | ||
protected $client; | ||
|
||
public function __construct() | ||
{ | ||
$this->client = new KlaviyoV3Api(Configuration::get('KLAVIYO_PRIVATE_API'), Configuration::get('KLAVIYO_PUBLIC_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, $customProperties = []) | ||
{ | ||
$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)); | ||
} | ||
} | ||
|
||
/** | ||
* Send event to Klaviyo using the Track endpoint. | ||
* | ||
* @param array $event | ||
* @return bool | ||
* @throws KlaviyoApiException | ||
*/ | ||
public function trackEvent(array $eventConfig) | ||
{ | ||
return (bool) $this->client->track($eventConfig); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace KlaviyoV3Sdk\Exception; | ||
|
||
class KlaviyoApiException extends KlaviyoException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace KlaviyoV3Sdk\Exception; | ||
|
||
class KlaviyoAuthenticationException extends KlaviyoApiException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace KlaviyoV3Sdk\Exception; | ||
|
||
class KlaviyoResourceNotFoundException extends KlaviyoApiException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace KlaviyoV3Sdk\Exception; | ||
|
||
class KlaviyoRateLimitException extends KlaviyoApiException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace KlaviyoV3Sdk\Exception; | ||
|
||
class KlaviyoResourceNotFoundException extends KlaviyoApiException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace KlaviyoV3Sdk; | ||
|
||
class Klaviyo | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $private_key; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $public_key; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
const VERSION = '1.0.0'; | ||
|
||
/** | ||
* Constructor for Klaviyo V3 SDK wrapper | ||
* | ||
* @param string $private_key Private Key for Klaviyo account | ||
* @param string $public_key Public Key for Klaviyo Account | ||
*/ | ||
public function __construct($private_key, $public_key) | ||
{ | ||
$this->private_key = $private_key; | ||
$this->public_key = $public_key; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getPrivateKey(): string | ||
{ | ||
return $this->private_key; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getPublicKey(): string | ||
{ | ||
return $this->public_key; | ||
} | ||
} |
Oops, something went wrong.