{"id":72,"date":"2022-08-01T06:44:20","date_gmt":"2022-08-01T06:44:20","guid":{"rendered":"https:\/\/www.wellnessliving.com\/developer-portal\/?p=72"},"modified":"2024-10-29T19:16:49","modified_gmt":"2024-10-29T19:16:49","slug":"booking-a-class","status":"publish","type":"post","link":"https:\/\/www.wellnessliving.com\/developer-portal\/tutorials\/booking-a-class\/","title":{"rendered":"Booking a class"},"content":{"rendered":"\n<p>To begin this tutorial, select a class session to book. You can identify a class session by combining the session\u2019s class period key (<span class=\"coding_type\">k_class_period<\/span>) with the date and time provided in UTC.<\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Retrieve the class list.\n$o_classlist_model = new \\WellnessLiving\\Wl\\Schedule\\ClassList\\ClassListModel($o_config);\n\n$o_classlist_model->is_tab_all=true; \/\/ Return classes from all class tabs.\n$o_classlist_model->k_business='3';\n$o_classlist_model->dt_date = '2023-03-27';\n$o_classlist_model->dt_end = '2023-03-31';\n\n$o_classlist_model->get();\n\nforeach($o_classlist_model->a_session as $a_session)\n{\n echo $a_session['k_class_period'];\n echo '    '.$a_session['dt_date'];\n echo '    '.$a_session['k_location'];\n echo '    '.$a_session['s_title'].\"\\n\";\n}<\/pre>\n<\/div>\n<\/div>\n\n\n\n<p>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\u2019ll check to see if the client has an existing Purchase Option during the booking process. Even if the client doesn\u2019t have an existing Purchase Option, you\u2019ll still be able to progress to the class booking process.<\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Retrieve a list of next steps for booking the session.\n$o_process_model = new \\WellnessLiving\\Wl\\Book\\Process\\Process54Model($o_config);\n$o_process_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n\n$o_process_model->dt_date_gmt='2023-04-04 14:00:00';\n$o_process_model->id_mode = ModeSid::SPA_BACKEND;\n$o_process_model->k_business='3';\n$o_process_model->k_class_period='139';\n$o_process_model->uid='4';\n\n$o_process_model->get();\n\n$is_free = true;\nforeach($o_process_model->a_path as $a_path)\n{\n if($a_path['id_book_process'] == \\WellnessLiving\\Wl\\Book\\Process\\ProcessSpaSid::PAYMENT)\n   $is_free = false;\n}\n\necho 'Is a purchase required? '.($is_free?'true':'false').\"\\n\";<\/pre>\n\n\n\n<p>If the client doesn\u2019t need to make a purchase, you can use the <a href=\"https:\/\/github.com\/wellnessliving\/wl-sdk\/blob\/4a919efe7d18e8403639c4c94600205719f9805b\/WellnessLiving\/Wl\/Book\/Process\/Info\/Info54Model.php\">Info54Model<\/a> endpoint to complete the booking. If successful, this endpoint will return the visit key (<span class=\"coding_type\">k_visit<\/span>) for the upcoming session.<\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Attempt to book the session.\n$o_process_model = new \\WellnessLiving\\Wl\\Book\\Process\\Info\\Info54Model($o_config);\n$o_process_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n\n$o_process_model->dt_date_gmt='2023-03-30 14:00:00';\n$o_process_model->id_mode = ModeSid::SPA_BACKEND;\n$o_process_model->k_business='3';\n$o_process_model->k_class_period='140';\n$o_process_model->uid='4';\n\n$o_process_model->post();\n\necho 'Is a purchase required? '.($o_process_model->is_next?'true':'false').\"\\n\";\n\n\/\/ Print visit keys of booked session(s).\nforeach($o_process_model->a_visit as $k_visit)\n{\n echo $k_visit.\"\\n\";\n}<\/pre>\n\n\n\n<p>If the client needs a Purchase Option to book the session, you\u2019ll need to generate a list of all the Purchase Options available for the client to purchase. You\u2019ll need the <span class=\"coding_type\">id_purchase_item<\/span> and  <span class=\"coding_type\">k_id<\/span> to identify the item. Both values are needed to identify the Purchase Option, with the <span class=\"coding_type\">id_purchase_item<\/span> acting as the category and <span class=\"coding_type\">k_id<\/span> as the key in that category. Additionally, you\u2019ll need to know the price of the Purchase Option.<\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Retrieve Purchase Option information applicable to a session.\n $o_purchase_model = new \\WellnessLiving\\Wl\\Book\\Process\\Purchase\\PurchaseModel($o_config);\n $o_purchase_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n $o_purchase_model->dt_date_gmt='2023-04-01 20:00:00';\n $o_purchase_model->k_business='3';\n $o_purchase_model->k_class_period='134';\n $o_purchase_model->id_mode= ModeSid::SPA_BACKEND;\n $o_purchase_model->uid = '131';\n\n\/\/ Perform the request.\n $o_purchase_model->get();\n\n\/\/ Print the names, identifiers, and prices of Purchase Options the client can buy.\nforeach($o_purchase_model->a_purchase as $a_purchase)\n{\n echo $a_purchase['s_title'].'    ';\n echo $a_purchase['id_purchase_item'].'::'.$a_purchase['k_id'].'    ';\n echo $a_purchase['f_price'].\"\\n\";\n}<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<p>It\u2019s 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.<\/p>\n\n\n\n<p>The <span class=\"coding_type\">id_purchase_item<\/span> and <span class=\"coding_type\">k_id<\/span> values are used in the <span class=\"coding_type\">a_item<\/span> property. The <span class=\"coding_type\">dt_date<\/span> value from the class list is used in the <span class=\"coding_type\">dt_date_gmt<\/span> field, and <span class=\"coding_type\">k_class_period<\/span> is also used.<\/p>\n\n\n\n<div class=\"wp-block-columns\">\n<div class=\"wp-block-column\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Complete a booking for a client.\n $o_payment_model = new \\WellnessLiving\\Wl\\Book\\Process\\Payment\\PaymentModel($o_config);\n $o_payment_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n\n $o_payment_model->a_pay_form=[\n   \\WellnessLiving\\WlPayMethodSid::ECOMMERCE => [\n     'a_pay_card' => [\n       'a_pay_address' => [\n         'is_new' => 0,\n         'k_geo_country' => 1,\n         'k_geo_region' => 11,\n         'k_pay_address' => 14,\n         's_city' => 'New-York',\n         's_name' => 'John',\n         's_postal' => '12345',\n         's_street1' => 'Baker str.',\n         's_street2' => ''\n       ],\n       'i_csc' => 999,\n       'i_month' => 10,\n       'i_year' => 25,\n       's_name' => 'Visa',\n       's_number' => '4111111111111111'\n     ],\n     'f_amount' => '55.00',\n     's_test' => 'q',\n     'sid_pay_method' => 'ecommerce'\n   ]\n ];\n\n $o_payment_model->a_item = [\n   [\n     'i_count' => 1, \/\/ The number of items purchased.\n     'id_purchase_item' => 1,\n     'k_id' => '1',\n   ]\n ];\n\n $o_payment_model->dt_date_gmt='2023-04-01 20:00:00';\n $o_payment_model->id_mode=\\WellnessLiving\\Wl\\Mode\\ModeSid::SPA_BACKEND;\n $o_payment_model->k_class_period='134';\n $o_payment_model->uid = '4';\n\n\/\/ Perform the request.\n $o_payment_model->post();\n\n\/\/ Display the number of sessions successfully booked.\n if(count($o_payment_model->a_login_activity_book)>0)\n   echo count($o_payment_model->a_login_activity_book).\" session(s) booked\\n\";\n}<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>To begin this tutorial, select a class session to book. You can identify a class session by combining the session\u2019s class period key (k_class_period) with the date and time provided in UTC. Not all class sessions will require the client to make a purchase. For example, a class session could be free of charge, or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[28,7],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts\/72"}],"collection":[{"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/comments?post=72"}],"version-history":[{"count":21,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts\/72\/revisions"}],"predecessor-version":[{"id":480,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts\/72\/revisions\/480"}],"wp:attachment":[{"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/media?parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/categories?post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/tags?post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}