Advertisement
Guest User

Untitled

a guest
Apr 21st, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. require_once("/lib/Stripe.php");
  5.  
  6.  
  7. function grav_event_listener() {
  8.  
  9.  
  10. // set your secret key: remember to change this to your live secret key in production
  11. // see your keys here https://manage.stripe.com/account
  12. Stripe::setApiKey("sk_test_dfpsdijruhi3#$iufiuhdfg");
  13.  
  14. // retrieve the request's body and parse it as JSON
  15. $body = @file_get_contents('php://input');
  16. $event_json = json_decode($body);
  17.  
  18. // do something with $event_json
  19.  
  20. // this will be used to retrieve the event from Stripe
  21. $event_id = $event_json->id;
  22.  
  23. if(isset($event_json->id)) {
  24.  
  25. try {
  26.  
  27. // to verify this is a real event, we re-retrieve the event from Stripe
  28. $event = Stripe_Event::retrieve($event_id);
  29. $invoice = $event->data->object;
  30.  
  31. // successful payment
  32. if($event->type == 'charge.succeeded') {
  33. // turn off the sales page
  34.  
  35. global $cfs;
  36.  
  37. $field_data = array('gone' => '1');
  38. $post_data = array('ID' => get_the_ID()); // the ID is required
  39. $cfs->save($field_data, $post_data);
  40.  
  41. }
  42.  
  43. // failed payment
  44. if($event->type == 'charge.failed') {
  45.  
  46. }
  47.  
  48. } catch (Exception $e) {
  49. // something failed, perhaps log a notice or email the site admin
  50. }
  51. }
  52. }
  53. add_action('init', 'grav_event_listener');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement