Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once("/lib/Stripe.php");
- function grav_event_listener() {
- // set your secret key: remember to change this to your live secret key in production
- // see your keys here https://manage.stripe.com/account
- Stripe::setApiKey("sk_test_dfpsdijruhi3#$iufiuhdfg");
- // retrieve the request's body and parse it as JSON
- $body = @file_get_contents('php://input');
- $event_json = json_decode($body);
- // do something with $event_json
- // this will be used to retrieve the event from Stripe
- $event_id = $event_json->id;
- if(isset($event_json->id)) {
- try {
- // to verify this is a real event, we re-retrieve the event from Stripe
- $event = Stripe_Event::retrieve($event_id);
- $invoice = $event->data->object;
- // successful payment
- if($event->type == 'charge.succeeded') {
- // turn off the sales page
- global $cfs;
- $field_data = array('gone' => '1');
- $post_data = array('ID' => get_the_ID()); // the ID is required
- $cfs->save($field_data, $post_data);
- }
- // failed payment
- if($event->type == 'charge.failed') {
- }
- } catch (Exception $e) {
- // something failed, perhaps log a notice or email the site admin
- }
- }
- }
- add_action('init', 'grav_event_listener');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement