From 2d5e7eb23c9d70bd558915bc79adbad4b2b3e9ae Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Thu, 21 Jul 2016 09:13:59 +1000 Subject: [PATCH] add stripe library hook --- booking.module | 103 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 36 deletions(-) diff --git a/booking.module b/booking.module index 2404fc0..4ec3b10 100644 --- a/booking.module +++ b/booking.module @@ -16,6 +16,7 @@ define('BOOKING_PAYPAL_SUBMIT_URL', 'https://www.paypal.com/cgi-bin/webscr'); define('BOOKING_PAYPAL_SUBMIT_URL_SANDBOX', 'https://www.sandbox.paypal.com/cgi-bin/webscr'); +//@todo should really change this to system/booking/paypal define('BOOKING_PAYPAL_IPN_PATH', 'system/booking_paypal/ipn'); // Load the include for various constants @@ -67,12 +68,14 @@ module_load_include('inc', 'booking', 'booking.rooms'); module_load_include('inc', 'booking', 'booking.rooms_allocate'); // Load the include for room layout definitions module_load_include('inc', 'booking', 'booking.rooms_admin'); +// Load the include for stripe payments +module_load_include('inc', 'booking', 'booking.stripe'); function booking_init() { date_default_timezone_set(date_default_timezone(FALSE)); global $event; - //reference - http://www.devdaily.com/drupal/drupal-7-sql-cheat-sheet-function-examples + //@see http://www.devdaily.com/drupal/drupal-7-sql-cheat-sheet-function-examples $event = db_query("SELECT * from {booking_event} where booking_event_active=1") ->fetchObject(); @@ -82,7 +85,6 @@ function booking_init() { /** * Implementation of hook_permission(). - * D7 done. */ function booking_permission() { return array( @@ -149,28 +151,17 @@ function booking_menu() { $items = array(); $items['admin/config/booking'] = array( - /* - 'title' => 'Booking module configuration', - 'description' => 'Configure the Booking module', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('booking_admin'), - 'access arguments' => array('access administration pages'), - */ - - 'title' => 'Booking module configuration', - 'description' => 'Configure the Booking module', - 'position' => 'left', - 'weight' => -100, - 'page callback' => 'system_admin_menu_block_page', - 'access arguments' => array('administer site configuration'), - 'file' => 'system.admin.inc', - 'file path' => drupal_get_path('module', 'system'), + 'title' => 'Booking module configuration', + 'description' => 'Configure the Booking module', + 'position' => 'left', + 'weight' => -100, + 'page callback' => 'system_admin_menu_block_page', + 'access arguments' => array('administer site configuration'), + 'file' => 'system.admin.inc', + 'file path' => drupal_get_path('module', 'system'), //'type' => MENU_DEFAULT_LOCAL_TASK, - - ); - + ); $items['admin/config/booking/general'] = array( - 'title' => 'Booking module general configuration', 'description' => 'Configure general settings for Booking module', 'page callback' => 'drupal_get_form', @@ -180,8 +171,6 @@ function booking_menu() { //'position' => 'left', 'weight' => -100, ); - - //http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form/ $items['admin/config/booking/text'] = array( 'title' => 'Booking module text definitions', @@ -191,7 +180,6 @@ function booking_menu() { 'access arguments' => array('administer site configuration'), 'weight' => -99, //'type' => MENU_LOCAL_TASK, - ); $items['admin/config/booking/emails'] = array( 'title' => 'Booking module email definitions', @@ -220,7 +208,6 @@ function booking_menu() { 'weight' => -96, //'type' => MENU_LOCAL_TASK, ); - $items['admin/config/booking/variety'] = array( 'title' => 'Booking module variety sessions', 'description' => 'Configure variety sessions for the Booking module', @@ -238,7 +225,8 @@ function booking_menu() { 'access arguments' => array('edit bookings'), 'type' => MENU_CALLBACK, ); - + + /* $items['admin/booking/createview'] = array( 'title' => 'Booking Test mysql view creation', 'description' => 'Booking Test mysql view creation', @@ -247,7 +235,8 @@ function booking_menu() { //always allow access to this page - security risk! 'access callback' => TRUE, 'type' => MENU_CALLBACK, - ); + ); + */ //pages for attendees to fill out information $items['booking'] = array( @@ -726,19 +715,24 @@ function booking_menu() { ); //the paypal IPN - $items[BOOKING_PAYPAL_IPN_PATH] = array( - 'type' => MENU_CALLBACK, - 'page callback' => 'booking_paypal_ipn', - 'access callback' => TRUE - ); + $items[BOOKING_PAYPAL_IPN_PATH] = array( + 'type' => MENU_CALLBACK, + 'access callback' => TRUE, + 'page callback' => 'booking_paypal_ipn', + ); + + //stripe webhook + $items['system/booking/stripe/webhook'] = array( + 'type' => MENU_CALLBACK, + 'access callback' => TRUE, + 'page callback' => 'booking_stripe_webhook', + ); - return $items; - + return $items; } /** * Describe the nodes we are going to define to model content specific to the booking module - * D7 done */ function booking_node_info() { return array( @@ -755,6 +749,43 @@ function booking_node_info() { ); } +/** + * Implements hook_libraries_info(). + */ +function bookings_libraries_info() { + $libraries['stripe'] = array( + 'name' => 'Stripe Payment API PHP Library', + 'vendor url' => 'https://github.com/stripe/stripe-php', + 'download url' => 'https://github.com/stripe/stripe-php/archive/master.zip', + 'version arguments' => array( + 'file' => 'VERSION', + 'pattern' => '/([0-9a-zA-Z\.-]+)/', + 'lines' => 1, + ), + 'files' => array('php' => array('init.php')), + 'callbacks' => array('post-load' => array('bookings_libraries_postload_callback')), + ); + return $libraries; +} + +/** + * Post-load callback for the Stripe PHP Library. + * + * @param array $library + * An array of library information. + * @param string $version + * If the $library array belongs to a certain version, a string containing the + * version. + * @param string $variant + * If the $library array belongs to a certain variant, a string containing the + * variant name. + */ +function bookings_libraries_postload_callback($library, $version = NULL, $variant = NULL) { + if (!empty($library['loaded'])) { + \Stripe\Stripe::setApiKey(_booking_get_stripe_private_key()); + } +} + /** * Implementation of access related hooks for booking_registration node type.