33 * Checkfront Sample Code: Browse inventory & create booking.
44 *
55 * This is sample code is for demonstration only and should not be used in production
6- * without modifcation. It does not adequtly secure your OAuth tokens.
6+ * without modifcation. It does not adequtly secure your OAuth tokens.
77 *
8- * see:
9- *
10- * API Documenation: http://www.checkfront.com/developers/api/
11- * API Error Codes: http://www.checkfront.com/developers/api-error
12- * PHP SDK - https://github.com/Checkfront/PHP-SDK
13- * CQL Documenation: http://www.checkfront.com/developers/api-cql/
8+ * see:
9+ *
10+ * API Documenation: http://api.checkfront.com/
11+ * PHP SDK - https://github.com/htmlgraphic/Checkfront-PHP-SDK
1412 *
1513 */
1614
1715/*
1816 * @access public
1917 * @package Checkfront
2018 */
21-
2219ini_set ('session.hash_bits_per_character ' , 5 );
2320include ('../../lib/Checkfront.php ' );
2421
@@ -30,12 +27,12 @@ public function __construct($data) {
3027 parent ::__construct ($ data ,session_id ());
3128 }
3229
33- /* DUMMY Data store. This sample stores oauth tokens in a text file...
34- * This is NOT reccomened in production. Ideally, this would be in an encryped
35- * database or other secure source. Never expose the client_secret or access / refresh
30+ /* DUMMY Data store. This sample stores oauth tokens in a text file...
31+ * This is NOT reccomened in production. Ideally, this would be in an encryped
32+ * database or other secure source. Never expose the client_secret or access / refresh
3633 * tokens.
3734 *
38- * store() is called from the parent::CheckfrontAPI when fetching or setting access tokens.
35+ * store() is called from the parent::Checkfront when fetching or setting access tokens.
3936 *
4037 * When an array is passed, the store should save and return the access tokens.
4138 * When no array is passed, it should fetch and return the stored access tokens.
@@ -54,44 +51,40 @@ final protected function store($data=array()) {
5451 }
5552
5653 public function session ($ session_id ,$ data =array ()) {
57- session_id ($ session_id );
58- if (!empty ($ data )) $ _SESSION = $ data ;
54+ session_id ($ session_id );
55+ if (!empty ($ data )) $ _SESSION = $ data ;
5956 }
6057}
6158
62- /*
63- * You need to create a new application in your Checkfront Account under
64- Manage / Extend / Api and supply the details below.
59+ /*
60+ You need to create a new application in your Checkfront Account under
61+ Manage / Developer / Api and supply the details below.
6562
66- This example bybasses the oauth authorization redirect by supplying "oob"
67- (Out Of Bounds) as the redirect_uri, and by generating the access and
68- refresh tokens from within Checkfront.
63+ This example bybasses the oauth authorization redirect by supplying "oob"
64+ (Out Of Bounds) as the redirect_uri, and by generating the access and
65+ refresh tokens from within Checkfront.
6966
70- For more infomration on your endpoints see:
71- http://www .checkfront.com/developers/api/#endpoints
67+ For more infomration on your endpoints see:
68+ http://api .checkfront.com/ref/index.html
7269*/
7370
7471// a general class that wraps the api along with some custom calls
7572class Booking {
76-
7773 public $ cart = array ();
78- public $ session = array ();
7974
8075 function __construct () {
8176 // apply a session_id to the request if one is specified
82- if (!empty ($ _GET ['cart_id ' ])) session_id ($ _GET ['cart_id ' ]);
77+ if (!empty ($ _GET ['cart_id ' ])) { session_id ($ _GET ['cart_id ' ]); }
8378 session_start ();
79+
8480 // create api connection to Checkfront
85- // you can generate a token pair under Manage / Developer in your account
86- $ this ->Checkfront = new Checkfront (
81+ $ this ->Checkfront = new CheckfrontAPI (
8782 array (
88- 'host ' => 'your-company.checkfront.com ' ,
89- 'auth_type ' => 'token ' ,
90- 'api_key ' => '' ,
91- 'api_secret ' => '' ,
92- 'account_id ' => 'off ' ,
93- )
94- );
83+ 'host ' => getenv ('HOST ' ),
84+ 'api_key ' => getenv ('CONSUMER_KEY ' ),
85+ 'api_secret ' => getenv ('CONSUMER_SECRET ' ),
86+ 'auth_type ' => 'token '
87+ ));
9588
9689 // init shopping cart
9790 $ this ->cart ();
@@ -118,16 +111,14 @@ public function form() {
118111
119112 // get cart session
120113 public function cart () {
121- if (!empty ($ _SESSION )) {
122- $ response = $ this ->Checkfront ->get ('booking/session ' );
123- if (!empty ($ response ['booking ' ]['session ' ]['item ' ])) {
124- foreach ($ response ['booking ' ]['session ' ]['item ' ] as $ line_id => $ data ) {
125- // store for later
126- $ this ->cart [$ line_id ] = $ data ;
127- }
114+ $ response = $ this ->Checkfront ->get ('booking/session ' );
115+ if (!empty ($ response ['booking ' ]['session ' ]['item ' ])) {
116+ foreach ($ response ['booking ' ]['session ' ]['item ' ] as $ line_id => $ data ) {
117+ // store for later
118+ $ this ->cart [$ line_id ] = $ data ;
128119 }
129- $ this ->Checkfront ->set_session ($ response ['booking ' ]['session ' ]['id ' ], $ response ['booking ' ]['session ' ]);
130120 }
121+ $ this ->Checkfront ->set_session ($ response ['booking ' ]['session ' ]['id ' ], $ response ['booking ' ]['session ' ]);
131122 }
132123
133124 // create a booking using the session and the posted form fields
@@ -142,5 +133,5 @@ public function create($form) {
142133 public function clear () {
143134 $ response = $ this ->Checkfront ->get ('booking/session/clear ' );
144135 session_destroy ();
145- }
136+ }
146137}
0 commit comments