├── .gitignore ├── LICENSE ├── README.md ├── config.sample.php └── webhook.php /.gitignore: -------------------------------------------------------------------------------- 1 | config.php 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Trevor Fitzgerald 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Make It Rain 2 | 3 | Get a random "make it rain" gif every time you get paid through Stripe. 4 | 5 | Works with HipChat + Slack. 6 | 7 | ![screenshot](https://i.imgur.com/gU7gFBW.gif) 8 | 9 | Current selection of gifs: https://fitztrev.github.io/make-it-rain/ 10 | 11 | Send pull requests to the `gh-pages` branch to add more. 12 | 13 | ## How to use 14 | 15 | 1) Copy `config.sample.php` to `config.php` 16 | 17 | 2) Update it with either your Hipchat or Slack API info (see below) 18 | 19 | 3) Add a webhook to [your Stripe account](https://dashboard.stripe.com/account/webhooks) 20 | 21 | https://YOUR_SITE_HERE.com/make-it-rain/webhook.php?secret=abc123 22 | 23 | * Your `secret` is set in `config.php` and known only to Stripe so nobody can ping that URL and give you a false notification. 24 | 25 | #### For Hipchat 26 | 27 | 1. Go to 28 | 2. Click your room and copy "API ID" to the channel setting in `config.php` 29 | 3. In "Tokens" for that room, create a token with label "Just got paid" and copy it to `config.php` 30 | 31 | #### For Slack 32 | 33 | 1. Go to 34 | 2. Create a webhook for your desired channel 35 | 3. Copy the webhook URL to `config.php` 36 | 37 | ## Contributing gifs 38 | 39 | New gifs are welcomed and encouraged. Check the [existing ones](https://github.com/fitztrev/make-it-rain/tree/gh-pages), grab the [`gh-pages`](https://github.com/fitztrev/make-it-rain/tree/gh-pages) branch of this repo, and submit a pull request to add one. 40 | -------------------------------------------------------------------------------- /config.sample.php: -------------------------------------------------------------------------------- 1 | '', // leave blank to disable Hipchat 7 | 'room_id' => 654321, 8 | ); 9 | 10 | // Your Slack API info 11 | // Setup instructions at https://github.com/fitztrev/make-it-rain 12 | $slack = array( 13 | 'webhook_url' => '', // leave blank to disable Slack 14 | ); 15 | 16 | // Secret identifier known only to Stripe so nobody can ping your webhook 17 | // and give you a false notification. Change this to something random. 18 | // Be sure to update the webhook in your Stripe account 19 | $secret = 'abc123'; 20 | 21 | // Add your own custom gifs that will be randomly added to the rotation 22 | $custom_gifs = array( 23 | // 'http://example.com/image.gif', 24 | ); 25 | -------------------------------------------------------------------------------- /webhook.php: -------------------------------------------------------------------------------- 1 | type != 'charge.succeeded') { 17 | die('Not a charge notification. Quitting.'); 18 | }; 19 | 20 | // grab a random gif 21 | $url = 'https://fitztrev.github.io/make-it-rain/gifs.json'; 22 | $gifs = json_decode(file_get_contents($url)); 23 | $gifs = array_merge($gifs, $custom_gifs); 24 | $gif = $gifs[array_rand($gifs)]; 25 | 26 | // get currency sign to use (right now, just USD and INR supported. More to follow? **cough**pullrequest**cough**) 27 | $dollar_sign = ($event_json->data->object->currency == 'inr') ? '₹' : '$'; 28 | $amount = $dollar_sign . number_format($event_json->data->object->amount / 100, 2); 29 | 30 | // send the notification to our chat room 31 | // hipchat 32 | if ($hipchat['auth_token']) { 33 | $url = sprintf( 34 | 'https://api.hipchat.com/v2/room/%s/notification?auth_token=%s', 35 | $hipchat['room_id'], 36 | $hipchat['auth_token'] 37 | ); 38 | $data = array( 39 | 'message' => sprintf('%s
', $amount, $gif), 40 | 'color' => 'green', 41 | 'notify' => true, 42 | ); 43 | sendNotification($url, $data); 44 | } 45 | 46 | // slack 47 | if ($slack['webhook_url']) { 48 | $data = array( 49 | 'text' => sprintf('%s - <%s>', $amount, $gif), 50 | 'username' => 'Just got paid', 51 | 'icon_emoji' => ':heavy_dollar_sign:', 52 | 'unfurl_links' => true, 53 | ); 54 | sendNotification($slack['webhook_url'], $data); 55 | } 56 | 57 | function sendNotification($url, $data) 58 | { 59 | $data_string = json_encode($data); 60 | 61 | $ch = curl_init(); 62 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 63 | curl_setopt($ch, CURLOPT_URL, $url); 64 | curl_setopt($ch, CURLOPT_POST, true); 65 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 66 | curl_setopt($ch, CURLOPT_HTTPHEADER, array( 67 | 'Content-Type: application/json', 68 | 'Content-Length: '.strlen($data_string), 69 | ) 70 | ); 71 | 72 | // send the request and close the handle 73 | $body = curl_exec($ch); 74 | curl_close($ch); 75 | } 76 | --------------------------------------------------------------------------------