In this tutorial, start by identifying the product the client wants to buy from the store.
To identify a product for the client, you can first retrieve a list of available products. When selecting an item, take note of the id_sale value showing the general category of item, along with the k_id value that serves as an identifier within that category. The same k_id value can be used with multiple id_sale values (both are necessary to identify a product).
// Retrieve a list of products from the store. $o_catalog_model = new \WellnessLiving\Wl\Catalog\StaffApp\CatalogList\CatalogListModel($o_config); $o_catalog_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session. $o_catalog_model->k_business='3'; $o_catalog_model->k_location='3'; // Perform the request. $o_catalog_model->get(); // Print each product's k_id, id_sale, and name. foreach ($o_catalog_model->a_shop_product as $a_product) { if($a_product['id_sale'] === WlSaleSid::PROMOTION_SERVICE) echo 'Appointment Membership: '; else if($a_product['id_sale'] === WlSaleSid::PROMOTION_CLASS) echo 'Class Membership: '; echo $a_product['k_id'].' '.$a_product['id_sale'].' '.$a_product['text_title']."\n"; }
After selecting a product, determine the total price the client will have to pay (including taxes and any other service fees or charges).
// Retrieve the list of store categories. $o_cart_model = new \WellnessLiving\Wl\Catalog\StaffApp\CatalogCart\CatalogCartModel($o_config); $o_cart_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session. $uid = 4; $o_cart_model->a_item=[ [ 'i_quantity' => 1, 'id_sale' => 1, 'k_id' => 1 ] ]; $o_cart_model->is_check_cart_item=true; $o_cart_model->k_business='3'; $o_cart_model->k_location='3'; $o_cart_model->uid_current=$uid; $o_cart_model->uid_customer=$uid; // Perform the request. $o_cart_model->get(); echo "\n\n\n"; echo "Total price: ". $o_cart_model->m_total."\n"
You’ll also need to retrieve the client’s address to complete the payment with a credit card.
// Retrieve the client's address. $o_info_model = new \WellnessLiving\Wl\Pay\Address\AddressModel($o_config); $o_info_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session. $o_info_model->id_pay_owner=\WellnessLiving\WlPayOwnerSid::USER; $o_info_model->k_id='4'; // Perform the request. $o_info_model->get(); // Print address information. if($o_info_model->a_pay_address && $o_info_model->a_pay_address[0]) var_dump($o_info_model->a_pay_address[0]);
Once you’ve determined the product’s id_sale, k_id, and total price, you can move to the next step. Use the m_total amount from the previous step as the f_total value in this next call. To make a purchase online, you’ll need to use a credit card. Upon success, you’ll receive a purchase key (k_purchase).
// Perform the purchase. $o_cart_model = new \WellnessLiving\Wl\Catalog\Payment\PaymentModel($o_config); $o_cart_model->cookieSet($o_notepad->cookieGet()); // Store cookies to maintain the session. $o_cart_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' => '111', 'i_month' => '10', 'i_year' => '25', 'is_new' => '1', 'k_pay_bank' => null, 's_number' => '4111111111111111' ], 'f_amount' => '55.00', 'is_enable_surcharge' => true, 'm_surcharge' => '0.00', 's_test' => 'q', 'sid_pay_method' => 'ecommerce' ] ]; $o_cart_model->a_item = [ [ 'i_quantity' => 1, // The number of sessions booked. 'id_purchase_item' => WlPurchaseItemSid::PROMOTION, 'id_sale' => \WellnessLiving\WlSaleSid::PROMOTION_CLASS, 'k_id' => '1', ] ]; $o_cart_model->id_mode=\WellnessLiving\Wl\Mode\ModeSid::WEB_BACKEND; $o_cart_model->is_staff=true; $o_cart_model->k_business='3'; $o_cart_model->k_location='3'; $o_cart_model->uid=100; // Perform the request $o_cart_model->post(); echo "\n\n\n"; echo "Purchase key: ". $o_cart_model->k_purchase."\n";