Skip to content

Instantly share code, notes, and snippets.

@Mte90
Last active May 31, 2019 01:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mte90/f1936c6568c925dec98bacd4a88d53ba to your computer and use it in GitHub Desktop.
Save Mte90/f1936c6568c925dec98bacd4a88d53ba to your computer and use it in GitHub Desktop.
Freemius to slack notification
<?php
// Get Freemius data
$json = file_get_contents('php://input');
$data = json_decode($json, true);
if( isset( $data['objects'] ) ) {
slack($data);
}
function slack($data) {
$ch = curl_init();
$headers = array(
'Accept: application/json',
'Content-Type: application/json'
);
$link = 'https://dashboard.freemius.com/#!/live/plugins/' . $data['objects']['payment']['plugin_id'] . '/users/'. $data['objects']['user_id'] . '/';
$data = array(
'text' => 'Sold license :tada: for ' . $data['objects']['payment']['gross'] . '$ to ' . $link,
'channel' => 'plugin', //channel
'username' => 'freemius-bot',
'as_user' => 'true',
'link_names' => 'true',
'icon_emoji' => ':codeat:' // an emoji as logo
);
curl_setopt($ch, CURLOPT_URL, 'you slack webhhok url');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
error_log( 'Error:' . curl_error($ch) );
}
curl_close ($ch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment