{"id":100,"date":"2023-04-10T16:58:25","date_gmt":"2023-04-10T16:58:25","guid":{"rendered":"https:\/\/www.wellnessliving.com\/developer-portal\/?p=100"},"modified":"2024-11-11T03:06:19","modified_gmt":"2024-11-11T03:06:19","slug":"making-a-purchase-for-a-client","status":"publish","type":"post","link":"https:\/\/www.wellnessliving.com\/developer-portal\/tutorials\/making-a-purchase-for-a-client\/","title":{"rendered":"Making a purchase for a client"},"content":{"rendered":"\n<p>In this tutorial, start by identifying the product the client wants to buy from the <a href=\"https:\/\/www.wellnessliving.com\/knowledge-sharing\/knowledge-base\/the-store\/\" target=\"_blank\" rel=\"noreferrer noopener\">store<\/a>.<\/p>\n\n\n\n<p>To identify a product for the client, you can first retrieve a list of available products. When selecting an item, take note of the <span class=\"coding_type\">id_sale<\/span> value showing the general category of item, along with the <span class=\"coding_type\">k_id<\/span> value that serves as an identifier within that category. The same <span class=\"coding_type\">k_id<\/span> value can be used with multiple <span class=\"coding_type\">id_sale<\/span> values (both are necessary to identify a product).<\/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 products from the store.\n$o_catalog_model = new \\WellnessLiving\\Wl\\Catalog\\StaffApp\\CatalogList\\CatalogListModel($o_config);\n$o_catalog_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n$o_catalog_model->k_business='3';\n$o_catalog_model->k_location='3';\n\n\/\/ Perform the request.\n$o_catalog_model->get();\n\n\/\/ Print each product's k_id, id_sale, and name.\nforeach ($o_catalog_model->a_shop_product as $a_product)\n{\n\n  if($a_product['id_sale'] === WlSaleSid::PROMOTION_SERVICE)\n    echo 'Appointment Membership: ';\n  else if($a_product['id_sale'] === WlSaleSid::PROMOTION_CLASS)\n    echo 'Class Membership: ';\n\n  echo $a_product['k_id'].' '.$a_product['id_sale'].' '.$a_product['text_title'].\"\\n\";\n}<\/pre>\n\n\n\n<p>After selecting a product, determine the total price the client will have to pay (including taxes and any other service fees or charges).<\/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 list of store categories.\n$o_cart_model = new \\WellnessLiving\\Wl\\Catalog\\StaffApp\\CatalogCart\\CatalogCartModel($o_config);\n$o_cart_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n$uid = 4;\n$o_cart_model->a_item=[\n [\n   'i_quantity' => 1,\n   'id_sale' => 1,\n   'k_id' => 1\n ]\n];\n$o_cart_model->is_check_cart_item=true;\n$o_cart_model->k_business='3';\n$o_cart_model->k_location='3';\n$o_cart_model->uid_current=$uid;\n$o_cart_model->uid_customer=$uid;\n\n\/\/ Perform the request.\n$o_cart_model->get();\n\necho \"\\n\\n\\n\";\necho \"Total price: \". $o_cart_model->m_total.\"\\n\"<\/pre>\n\n\n\n<p>You\u2019ll also need to retrieve the client\u2019s address to complete the payment with a credit card.<\/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 client's address.\n$o_info_model = new \\WellnessLiving\\Wl\\Pay\\Address\\AddressModel($o_config);\n$o_info_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n$o_info_model->id_pay_owner=\\WellnessLiving\\WlPayOwnerSid::USER;\n$o_info_model->k_id='4';\n\n\/\/ Perform the request.\n$o_info_model->get();\n\n\/\/ Print address information.\nif($o_info_model->a_pay_address &amp;&amp; $o_info_model->a_pay_address[0])\n var_dump($o_info_model->a_pay_address[0]);<\/pre>\n\n\n\n<p>Once you\u2019ve determined the product\u2019s <span class=\"coding_type\">id_sale<\/span>, <span class=\"coding_type\">k_id<\/span>, and total price, you can move to the next step. Use the <span class=\"coding_type\">m_total<\/span> amount from the previous step as the <span class=\"coding_type\">f_total value<\/span> in this next call. To make a purchase online, you\u2019ll need to use a credit card. Upon success, you\u2019ll receive a purchase key (<span class=\"coding_type\">k_purchase<\/span>).<\/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=\"\">\/\/ Perform the purchase.\n$o_cart_model = new \\WellnessLiving\\Wl\\Catalog\\Payment\\PaymentModel($o_config);\n$o_cart_model->cookieSet($o_notepad->cookieGet()); \/\/ Store cookies to maintain the session.\n\n$o_cart_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' => '111',\n     'i_month' => '10',\n     'i_year' => '25',\n     'is_new' => '1',\n     'k_pay_bank' => null,\n     's_number' => '4111111111111111'\n   ],\n   'f_amount' => '55.00',\n   'is_enable_surcharge' => true,\n   'm_surcharge' => '0.00',\n   's_test' => 'q',\n   'sid_pay_method' => 'ecommerce'\n ]\n];\n\n$o_cart_model->a_item = [\n [\n   'i_quantity' => 1, \/\/ The number of sessions booked.\n   'id_purchase_item' => WlPurchaseItemSid::PROMOTION,\n   'id_sale' => \\WellnessLiving\\WlSaleSid::PROMOTION_CLASS,\n   'k_id' => '1',\n ]\n];\n\n$o_cart_model->id_mode=\\WellnessLiving\\Wl\\Mode\\ModeSid::WEB_BACKEND;\n$o_cart_model->is_staff=true;\n$o_cart_model->k_business='3';\n$o_cart_model->k_location='3';\n$o_cart_model->uid=100;\n\n\/\/ Perform the request\n$o_cart_model->post();\n\necho \"\\n\\n\\n\";\necho \"Purchase key: \". $o_cart_model->k_purchase.\"\\n\";<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,36],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts\/100"}],"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=100"}],"version-history":[{"count":11,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts\/100\/revisions"}],"predecessor-version":[{"id":484,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/posts\/100\/revisions\/484"}],"wp:attachment":[{"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/media?parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/categories?post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellnessliving.com\/developer-portal\/wp-json\/wp\/v2\/tags?post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}