To begin this tutorial, select a class session to book. You can identify a class session by combining the session’s class period key (k_class_period) with the date and time provided in UTC.
// Retrieve the class list. $o_classlist_model = new \WellnessLiving\Wl\Schedule\ClassList\ClassListModel($o_config); $o_classlist_model->is_tab_all=true; // Return classes from all class tabs. $o_classlist_model->k_business='3'; $o_classlist_model->dt_date = '2023-03-27'; $o_classlist_model->dt_end = '2023-03-31'; $o_classlist_model->get(); foreach($o_classlist_model->a_session as $a_session) { echo $a_session['k_class_period']; echo ' '.$a_session['dt_date']; echo ' '.$a_session['k_location']; echo ' '.$a_session['s_title']."\n"; }
Not all class sessions will require the client to make a purchase. For example, a class session could be free of charge, or the client may have an existing Purchase Option that can be used to pay for the session. In this tutorial, you’ll check to see if the client has an existing Purchase Option during the booking process. Even if the client doesn’t have an existing Purchase Option, you’ll still be able to progress to the class booking process.
// Retrieve a list of next steps for booking the session. $o_process_model = new \WellnessLiving\Wl\Book\Process\Process54Model($o_config); $o_process_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session. $o_process_model->dt_date_gmt='2023-04-04 14:00:00'; $o_process_model->id_mode = ModeSid::SPA_BACKEND; $o_process_model->k_business='3'; $o_process_model->k_class_period='139'; $o_process_model->uid='4'; $o_process_model->get(); $is_free = true; foreach($o_process_model->a_path as $a_path) { if($a_path['id_book_process'] == \WellnessLiving\Wl\Book\Process\ProcessSpaSid::PAYMENT) $is_free = false; } echo 'Is a purchase required? '.($is_free?'true':'false')."\n";
If the client doesn’t need to make a purchase, you can use the Info54Model endpoint to complete the booking. If successful, this endpoint will return the visit key (k_visit) for the upcoming session.
// Attempt to book the session. $o_process_model = new \WellnessLiving\Wl\Book\Process\Info\Info54Model($o_config); $o_process_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session. $o_process_model->dt_date_gmt='2023-03-30 14:00:00'; $o_process_model->id_mode = ModeSid::SPA_BACKEND; $o_process_model->k_business='3'; $o_process_model->k_class_period='140'; $o_process_model->uid='4'; $o_process_model->post(); echo 'Is a purchase required? '.($o_process_model->is_next?'true':'false')."\n"; // Print visit keys of booked session(s). foreach($o_process_model->a_visit as $k_visit) { echo $k_visit."\n"; }
If the client needs a Purchase Option to book the session, you’ll need to generate a list of all the Purchase Options available for the client to purchase. You’ll need the id_purchase_item and k_id to identify the item. Both values are needed to identify the Purchase Option, with the id_purchase_item acting as the category and k_id as the key in that category. Additionally, you’ll need to know the price of the Purchase Option.
// Retrieve Purchase Option information applicable to a session. $o_purchase_model = new \WellnessLiving\Wl\Book\Process\Purchase\PurchaseModel($o_config); $o_purchase_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session. $o_purchase_model->dt_date_gmt='2023-04-01 20:00:00'; $o_purchase_model->k_business='3'; $o_purchase_model->k_class_period='134'; $o_purchase_model->id_mode= ModeSid::SPA_BACKEND; $o_purchase_model->uid = '131'; // Perform the request. $o_purchase_model->get(); // Print the names, identifiers, and prices of Purchase Options the client can buy. foreach($o_purchase_model->a_purchase as $a_purchase) { echo $a_purchase['s_title'].' '; echo $a_purchase['id_purchase_item'].'::'.$a_purchase['k_id'].' '; echo $a_purchase['f_price']."\n"; }
It’s possible to purchase a Purchase Option with the same call used to make the booking. Below is an example that involves buying a Purchase Option with a new credit card while booking a class session.
The id_purchase_item and k_id values are used in the a_item property. The dt_date value from the class list is used in the dt_date_gmt field, and k_class_period is also used.
// Complete a booking for a client. $o_payment_model = new \WellnessLiving\Wl\Book\Process\Payment\PaymentModel($o_config); $o_payment_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session. $o_payment_model->a_pay_form=[ \WellnessLiving\WlPayMethodSid::ECOMMERCE => [ 'a_pay_card' => [ 'a_pay_address' => [ 'is_new' => 0, 'k_geo_country' => 1, 'k_geo_region' => 11, 'k_pay_address' => 14, 's_city' => 'New-York', 's_name' => 'John', 's_postal' => '12345', 's_street1' => 'Baker str.', 's_street2' => '' ], 'i_csc' => 999, 'i_month' => 10, 'i_year' => 25, 's_name' => 'Visa', 's_number' => '4111111111111111' ], 'f_amount' => '55.00', 's_test' => 'q', 'sid_pay_method' => 'ecommerce' ] ]; $o_payment_model->a_item = [ [ 'i_count' => 1, // The number of items purchased. 'id_purchase_item' => 1, 'k_id' => '1', ] ]; $o_payment_model->dt_date_gmt='2023-04-01 20:00:00'; $o_payment_model->id_mode=\WellnessLiving\Wl\Mode\ModeSid::SPA_BACKEND; $o_payment_model->k_class_period='134'; $o_payment_model->uid = '4'; // Perform the request. $o_payment_model->post(); // Display the number of sessions successfully booked. if(count($o_payment_model->a_login_activity_book)>0) echo count($o_payment_model->a_login_activity_book)." session(s) booked\n"; }