Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// ConvertKit API Key:
$convertkitApiKey = 'your-convertkit-api-key';
// Map each of your Clickbank products to a ConvertKit tag ID, or leave this array empty to
// use the default tag for all products:
$convertkitTags = array(
'clickbankproduct1' => 'cktag1',
'clickbankproduct2' => 'cktag2',
'clickbankproduct3' => 'cktag3',
$defaultConvertKitTag = 'tag-to-use-if-product-is-not-in-list';
// Clickbank username:
$vendor = 'your-clickbank-username';
// Clickbank INS secret key:
$secretKey = 'your-clickbank-INS-key';
// get JSON from raw body...
$message = json_decode(file_get_contents('php://input'), true);
// Pull out the encrypted notification and the initialization vector for
// AES/CBC/PKCS5Padding decryption
$encrypted = $message['notification'];
$iv = $message['iv'];
// decrypt the body...
$decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128,
substr(sha1($secretKey), 0, 32),
base64_decode($iv)), "\0..\32");
// convert the decrypted string to a JSON object...
$order = json_decode($decrypted, true);
$email = $order['customer']['billing']['email'];
$fname = $order['customer']['billing']['firstName'];
$item = $order['lineItems'][0]['itemNo'];
$convertkitTagId = isset($convertkitTags[$item]) ? $convertkitTags[$item] : $defaultConvertKitTag;
// Send the API request to ConvertKit to add the customer to the tag:
$data = array('api_key' => $convertkitApiKey, 'email' => $email);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, sprintf('', $convertkitTagId));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$jsonresult = curl_exec($ch);
$result = json_decode($jsonresult, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment