add stripe library hook

This commit is contained in:
Nathan Coad
2016-07-21 09:13:59 +10:00
parent 9567f9c105
commit 2d5e7eb23c

View File

@@ -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,14 +151,6 @@ 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',
@@ -166,11 +160,8 @@ function booking_menu() {
'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',
@@ -239,6 +226,7 @@ function booking_menu() {
'type' => MENU_CALLBACK,
);
/*
$items['admin/booking/createview'] = array(
'title' => 'Booking Test mysql view creation',
'description' => 'Booking Test mysql view creation',
@@ -248,6 +236,7 @@ function booking_menu() {
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
*/
//pages for attendees to fill out information
$items['booking'] = array(
@@ -728,17 +717,22 @@ function booking_menu() {
//the paypal IPN
$items[BOOKING_PAYPAL_IPN_PATH] = array(
'type' => MENU_CALLBACK,
'access callback' => TRUE,
'page callback' => 'booking_paypal_ipn',
'access callback' => TRUE
);
//stripe webhook
$items['system/booking/stripe/webhook'] = array(
'type' => MENU_CALLBACK,
'access callback' => TRUE,
'page callback' => 'booking_stripe_webhook',
);
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.