Norsani API

Norsani API was developed to allow access to Norsani resources through REST calls. To use the Norsani API you must download and activate the Norsani API WordPress plugin.

You can use any programming language your prefer to connect with the API.

React Native developers can use the Norsani React Native client package to easily connect with the API over HTTP or HTTPS.

Requirements

  • Norsani 2.14+

  • WooCommerce 3.6+.

  • WordPress 4.4+.

  • Pretty permalinks in Settings > Permalinks so that the custom endpoints are supported. Default permalinks will not work.

Authentication

You may access the API over either HTTP or HTTPS, but HTTPS is recommended where possible. Norsani uses the WooCommerce API customer key and secret to authenticate so before you start you should obtain your WooCommerce API keys from WooCommerce settings -> Advance -> REST API.

Authentication over HTTPS

You may use HTTP Basic Auth by providing the REST API Consumer Key as the username and the REST API Consumer Secret as the password in the request's Authorization header.

Occasionally some servers may not parse the Authorization header correctly (if you see a "Consumer key is missing" error when authenticating over SSL, you have a server issue). In this case, you may provide the consumer key/secret as query string parameters instead.

Authentication over HTTP

You must use OAuth 1.0a "one-legged" authentication to ensure REST API credentials cannot be intercepted by an attacker. Typically you will use any standard OAuth 1.0a library in the language of your choice to handle the authentication. For React Native users you can simply use the React Native Norsani API client that will handle the autentication for you.

API Endpoints

Load App

GET https://yourwebsite.com/wp-json/norsani/v1/loadappdata

This is called to load a list of all vendors but also returns other data sets. Please see the call response for more information.

Query Parameters

NameTypeDescription

vendortype

string

Vendor type to retrieve. Pass null to get all types.

ordertype

string

User selected order type. Pass null to get all types.

customer

string

Current user's email address.

locality

string

User selected locality.

/* The response is an encoded JSON data string
 * that contains the below PHP (WordPress,WooCommerce) data.
*/

$data = array( // use WP filter norsani_app_load_data to extend.
'vendors' => array( // will return all vendors that match the vendor and order types sent in the request./
				$vendor_id => array( // key is the vendor id (int)
					'name' => $vendor_obj->get_store_name(),
					'logo' => $vendor_logo, // image link (small)
					'cover' => $vendor_cover, // image link (large)
					'address' => $vendor_obj->get_store_address(),
					'contact_number' => filter_var($vendor_obj->get_contact_number(), FILTER_SANITIZE_NUMBER_INT),
					'address_geo' => $vendor_obj->get_store_geolocation_address(), // lat,lng
					'is_busy' => intval($peak_orders) > 0 && intval($current_processing_orders) > intval($peak_orders),
					'peak_delivery_fee' => frozr_delivery_settings($vendor_id,'shipping_fee_peak',true), // float
					'delivery_fee_per' => $vendor_obj->get_calculate_delivery_by(),
					'min_delivery' => $vendor_obj->get_delivery_minimum_order_amount(), // float
					'delivery_zone' => $vendor_obj->get_delivery_zone_filtered(), // array()
					'rating' => $rating_avarage > 0 ? number_format(min( 5, $rating_avarage ), 1) : 0,
					'vendorclass' => $tags_array, // array of tag names.
					'notice' => $vendor_obj->get_store_notice(), // string
					'is_open' => frozr_is_rest_open($vendor_id), // bool
					'timing_status' => frozr_rest_status($vendor_id), // string
					'social' => array('twitter' => esc_url( $vendor_obj->get_social_twitter() ), 'facebook' => esc_url( $vendor_obj->get_social_fb() ), 'youtube' => esc_url( $vendor_obj->get_social_youtube() ), 'instagram' => esc_url( $vendor_obj->get_social_insta() )),
					'orders_made' => intval(frozr_count_user_object('wc-completed','shop_order',$vendor_id)),
				)
			),
'vendors_tags' => array( // will return all vendor tags that match the vendor and order types sent in the request.
					array(
						'termID' => $term->term_id,
						'thumb' => $thumbnail, // image link
						'slug' => $term->slug,
						'name' => $term->name
					),
				),
'featured_vendors' => array(23,32,56), // ids of featured vendors
'featured_items' => array(
						array(
							'id' => $product_id,
							'is_variable' => $product_obj->is_type( 'variable' ),
							'title' => $product_obj->get_name(),
							'author' => $vendor_obj->get_store_name(),
							'author_id' => $id,
							'categories' => array(),
							'image' => wp_get_attachment_thumb_url( $product_obj->get_image_id() ),
							'price' => $price, // string
							'on_sale' => $product_obj->is_on_sale(),
							'regular_price' => $product_obj->get_regular_price(),
							'sale_price' => $product_obj->get_sale_price(),
							'has_coupon' => $has_coupon, // bool
							'rating' => floatval(min( 5, round( $product_obj->get_average_rating(), 1 ) )),
						),
					),
'recommended_vendors' => array(23,32,56), // ids of featured vendors if the customer email was provided
'top_rated_vendors'	=> array( // ordered by top
						$vendor_id => frozr_get_readable_seller_rating($vendor_id, false),
						$vendor_id  => frozr_get_readable_seller_rating($vendor_id, false),
						$vendor_id  => frozr_get_readable_seller_rating($vendor_id, false)
						),
'special_items' => array(
					23 => array(
						array( 
							'id' => $product_id,
							'is_variable' => $product_obj->is_type( 'variable' ),
							'title' => $product_obj->get_name(),
							'author' => $vendor_obj->get_store_name(),
							'author_id' => $id,
							'categories' => $itemcats,
							'image' => wp_get_attachment_thumb_url( $product_obj->get_image_id() ),
							'price' => $price, // string
							'on_sale' => $product_obj->is_on_sale(),
							'regular_price' => $product_obj->get_regular_price(),
							'sale_price' => $product_obj->get_sale_price(),
							'has_coupon' => $has_coupon, // bool
							'rating' => floatval(min( 5, round( $product_obj->get_average_rating(), 1 ) )),
						),
					),
				),
'coupons' => array( // will return all valid coupons.
				array(
					'product_ids'	=> array_map( 'absint', (array) $coupon_obj->get_product_ids() ),
					'vendor_name'	=> $vendor_obj->get_store_name(),
					'vendor_logo'	=> $vendor_obj->get_store_logo() ? wp_get_attachment_thumb_url(absint( $vendor_obj->get_store_logo() )) : '',
					'vendor_cover' => $vendor_obj->get_store_banner() ? wp_get_attachment_thumb_url(absint( $vendor_obj->get_store_banner() )) : '',
					'vendor_id'	=> $coupon->post_author,
					'ending'		=> $coupon_ends, // ending message (string)
					'expiry_date'	=> $expiry_date, // Y-m-d H:i
					'type'		=> $coupon_obj->get_discount_type(),
					'amount'		=> $coupon_obj->get_amount(),
					'free_shipping' => 'yes' == $free_shipping,
					'code'		=> $coupon_obj->get_code(),
				),
			)
);

Get a single vendor

GET https://yourwebsite.com/wp-json/norsani/v1/get_vendor/id

Returns resources of a single vendor.

Path Parameters

NameTypeDescription

id

integer

Id of the vendor to return.

/* The response is an encoded JSON data string
 * that contains the below PHP (WordPress,WooCommerce) data.
*/

$data = array(
	'name' => $vendor->get_store_name(),
	'logo' => $vendor->get_store_logo() ? wp_get_attachment_url(absint( $vendor->get_store_logo() )) : '',
	'cover' => $vendor->get_store_banner() ? wp_get_attachment_url(absint( $vendor->get_store_banner() )) : '',
	'address' => $vendor->get_store_address(),
	'contact_number' => filter_var($vendor->get_contact_number(), FILTER_SANITIZE_NUMBER_INT),
	'address_geo' => $vendor->get_store_geolocation_address(),
	'is_busy' => intval($peak_orders) > 0 && intval($current_processing_orders) > intval($peak_orders),
	'peak_delivery_fee' => frozr_delivery_settings($id,'shipping_fee_peak',true),
	'delivery_fee_per' => $vendor->get_calculate_delivery_by(),
	'min_delivery' => $vendor->get_delivery_minimum_order_amount(),
	'delivery_zone' => $vendor->get_delivery_zone_filtered(),
	'rating' => $rating_avarage > 0 ? number_format(min( 5, $rating_avarage ), 1) : 0,
	'review_count' => $total_count,
	'vendorclass' => array($tag_name,...),
	'notice' => $vendor->get_store_notice(),
	'is_open' => frozr_is_rest_open($id), // bool
	'timing_status' => frozr_rest_status($id), // string
	'social' => array('twitter' => esc_url( $vendor->get_social_twitter() ), 'facebook' => esc_url( $vendor->get_social_fb() ), 'youtube' => esc_url( $vendor->get_social_youtube() ), 'instagram' => esc_url( $vendor->get_social_insta() )),
	'orders_made' => intval(frozr_count_user_object('wc-completed','shop_order',$id)),
	'productcats' => array(
						$category_name => array($product_id,...),
					),
	'menus' => array(
					array('title' => $menu_title, 'timing' => $timing)
				),
	'activemenu' => $active_menu, // the title of the menu that should be automatically visible.
	'products' => array(
		array(
			'id' => $product_id,
			'title' => $product_obj->get_name(),
			'is_variable' => $product_obj->is_type( 'variable' ),
			'excerpt' => $product_obj->get_short_description(),
			'vendor_id' => $id,
			'vendor_name' => $vendor->get_store_name(),
			'imagelink' => $image, // image link (large),
			'price' => $price, // if simple (price) if variable (lowest - highest)
			'on_sale' => $product_obj->is_on_sale(),
			'regular_price' => $regular_price, // if simple (price) if variable (lowest - highest)
			'sale_price' => $product_obj->get_sale_price(),
			'menus' => get_post_meta( $product_id, 'product_meal_type', true),
			'rating' => floatval(min( 5, round( $product_obj->get_average_rating(), 1 ) )),
			'promotions' => frozr_product_promotions( $product_id ),
			'categories' => wp_get_post_terms( $product_id, 'product_cat', array("fields" => "names") ),
			'ingredients' => array($ingredient_name,...),
			'variations' => array(
								array(
									'id' => $variation['variation_id'],
									'price' => $variation['display_price'],
									'description' => strip_tags($variation['variation_description']),
									'options' => array(
													array('title' => $attr_name, 'selection' => $option),
													array('title' => $attr_name, 'selection' => $option),
												),
								)
							),
			'preparation' => frozr_get_product_preparation_time($product_id, false),
			'maxorders' => frozr_product_get_max_orders($product_id),
			'remainingorders' => frozr_product_max_orders($product_id),
			'min_qty' => $product_obj->get_min_purchase_quantity() > 0 ? $product_obj->get_min_purchase_quantity() : 1,
			'available' => frozr_product_availability_notice($product_id, false),
			'is_special' => frozr_is_item_special($product_id),
			'is_offline' => $item->post_status == 'offline' ? true : false,
			'vairationsoptions' => $vairation_options,
			'upsells' => $product_obj->get_upsell_ids(),
			'coupons' => array(
							array(
								'product_ids'	=> array_map( 'absint', (array) $coupon_obj->get_product_ids() ),
								'message'		=> $message, // this will either show the coupon description or go online text.
								'code'			=> $coupon_obj->get_code(),
							)
						),
			'has_coupon' => count($product_coupons) > 0,
			'crosssells' => $product_obj->get_cross_sell_ids(),
		),
	),
);

Get a single Product

GET https://yourwebsite.com/wp-json/norsani/v1/getproduct/id

Path Parameters

NameTypeDescription

id

integer

id of the product to return.

/* The response is an encoded JSON data string
 * that contains the below PHP (WordPress,WooCommerce) data.
*/

$data = array(
	'id' => $product_id,
	'title' => $product_obj->get_name(),
	'excerpt' => $product_obj->get_short_description(),
	'vendor_id' => $vendor_id,
	'vendor_name' => $vendor_obj->get_store_name(),
	'imagelink' => $product_obj->get_image_id() > 0 ? wp_get_attachment_url( $product_obj->get_image_id() ) : null,
	'price' => $price, // if simple (price) if variable (lowest - highest)
	'regular_price' => $product_obj->get_regular_price(),
	'sale_price' => $product_obj->get_sale_price(),
	'rating' => floatval(min( 5, round( $product_obj->get_average_rating(), 1 ) )),
	'promotions' => frozr_product_promotions( $product_id ), //array of arrays. See the function in Norsani for more info.
	'categories' => wp_get_post_terms( $product_id, 'product_cat', array("fields" => "names") );,
	'ingredients' => array($ingredient_name,...),
	'variations' => array(
						array(
							'id' => $variation['variation_id'],
							'price' => $variation['display_price'],
							'description' => strip_tags($variation['variation_description']),
							'options' => array(
											array('title' => $attr_name, 'selection' => $option),
											array('title' => $attr_name, 'selection' => $option),
										),
						)
					),
	'preparation' => frozr_get_product_preparation_time($product_id, false), // string
	'maxorders' => frozr_product_get_max_orders($product_id), // max orders per day
	'remainingorders' => frozr_product_max_orders($product_id), // remaining orders for today
	'min_qty' => $product_obj->get_min_purchase_quantity() > 0 ? $product_obj->get_min_purchase_quantity() : 1,
	'available' => frozr_product_availability_notice($product_id, false),
	'is_special' => frozr_is_item_special($product_id), // bool
	'is_offline' => $item->post_status == 'offline' ? true : false,
	'vairationsoptions' => array(
								wc_attribute_label( $attribute->get_name() )] => array( esc_html($option->name) ),
							),
	'upsells' => $product_obj->get_upsell_ids(),
	'coupons' => array(
					array(
						'product_ids'	=> array_map( 'absint', (array) $coupon_obj->get_product_ids() ),
						'message'		=> $message, // this will either show the coupon description or go online text.
						'code'			=> $coupon_obj->get_code(),
					)
				),
	'has_coupon' => count($coupons) > 0,
	'crosssells' => $product_obj->get_cross_sell_ids(),
);

Search Vendors

GET https://yourwebsite.com/wp-json/norsani/v1/searchvendors

Search vendors by keyword. This will search for the keyword within the vendor name, tags, and address.

Query Parameters

NameTypeDescription

vendortype

string

Type of vendors to search. pass null to search all.

ordertype

string

Search vendors that offer this order type. Pass null to search all.

keyword

string

Search keyword

/* The response is an encoded JSON data string
 * that contains the below PHP (WordPress,WooCommerce) data.
*/

$data = array(
	array(
		'id' => $vendor_id,
		'name' => $vendor_obj->get_store_name(),
		'logo' => $vendor_logo_src, // image link (small)
		'address' => $vendor_obj->get_store_address(),
		'address_geo' => $vendor_obj->get_store_geolocation_address(), // string lat,lng
		'delivery_zone' => $vendor_obj->get_delivery_zone_filtered(), // array()
		'rating' => $rating_avarage > 0 ? number_format(min( 5, $rating_avarage ), 1) : 0,
		'vendorclass' => array($tag_name,...),
		'timing_status' => frozr_is_rest_open($vendor_id),
		'orders_made' => intval(frozr_count_user_object('wc-completed','shop_order',$vendor_id)),
	)
);

Get locality options

GET https://yourwebsite.com/wp-json/norsani/v1/localityoptions

Will get the locality options available on the website. This endpoint does not accept any parameters.

/* The response is an encoded JSON data string
 * that contains the below PHP (WordPress,WooCommerce) data.
*/

$data = array(
			array('label' => $option_label, 'value' => $option_value),
			array('label' => $option_label, 'value' => $option_value),
		);

Get data of user favorite vendors

GET https://yourwebsite.com/wp-json/norsani/v1/getfavoritevendors

Query Parameters

NameTypeDescription

ids

string

A comma separated string of vendor ids.

/* The response is an encoded JSON data string
 * that contains the below PHP (WordPress,WooCommerce) data.
*/

$data = array(
	'name' => $vendor->get_store_name(),
	'logo' => $vendor_logo, // image link (small)
	'cover' => $vendor_cover, // image link (large)
	'address' => $vendor->get_store_address(),
	'contact_number' => esc_html( $vendor->get_contact_number() ),
	'address_geo' => $vendor->get_store_geolocation_address(),
	'is_busy' => intval($peak_orders) > 0 && intval($current_processing_orders) > intval($peak_orders),
	'peak_delivery_fee' => frozr_delivery_settings($id,'shipping_fee_peak',true), // float
	'delivery_fee_per' => $vendor->get_calculate_delivery_by(),
	'min_delivery' => $vendor->get_delivery_minimum_order_amount(),
	'delivery_zone' => $vendor->get_delivery_zone_filtered(),
	'rating' => $rating_avarage > 0 ? number_format(min( 5, $rating_avarage ), 1) : 0,
	'vendorclass' => array($tag_name,...),
	'notice' => $vendor->get_store_notice(),
	'is_open' => frozr_is_rest_open($id), // bool
	'timing_status' => frozr_rest_status($id), // string
	'social' => array('twitter' => esc_url( $vendor->get_social_twitter() ), 'facebook' => esc_url( $vendor->get_social_fb() ), 'youtube' => esc_url( $vendor->get_social_youtube() ), 'instagram' => esc_url( $vendor->get_social_insta() )),
	'orders_made' => intval(frozr_count_user_object('wc-completed','shop_order',$id)),
);

Get data of user favorite products

GET https://yourwebsite.com/wp-json/norsani/v1/getfavoriteitems

Query Parameters

NameTypeDescription

ids

string

A comma separated list of product ids.

/* The response is an encoded JSON data string
 * that contains the below PHP (WordPress,WooCommerce) data.
*/

$data = 
	array(
		'id' => $product_id,
		'title' => $product_obj->get_name(),
		'is_variable' => $product_obj->is_type( 'variable' ),
		'excerpt' => $product_obj->get_short_description(),
		'vendor_id' => $id,
		'vendor_name' => $vendor->get_store_name(),
		'imagelink' => $image, // image link (large)
		'price' => $price, // if simple (price) if variable (lowest - highest)
		'on_sale' => $product_obj->is_on_sale(),
		'regular_price' => $regular_price, // if simple (price) if variable (lowest - highest)
		'sale_price' => $product_obj->get_sale_price(),
		'rating' => floatval(min( 5, round( $product_obj->get_average_rating(), 1 ) )),
		'promotions' => frozr_product_promotions( $product_id ),
		'categories' => wp_get_post_terms( $product_id, 'product_cat', array("fields" => "names") ),
		'ingredients' => array($ingredient_name,...),
		'variations' => array(
							array(
								'id' => $variation['variation_id'],
								'price' => $variation['display_price'],
								'description' => strip_tags($variation['variation_description']),
								'options' => array(
												array('title' => $attr_name, 'selection' => $option),
												array('title' => $attr_name, 'selection' => $option),
											),
							)
						),
		'preparation' => frozr_get_product_preparation_time($product_id, false),
		'maxorders' => frozr_product_get_max_orders($product_id),
		'remainingorders' => frozr_product_max_orders($product_id),
		'min_qty' => $product_obj->get_min_purchase_quantity() > 0 ? $product_obj->get_min_purchase_quantity() : 1,
		'available' => frozr_product_availability_notice($product_id, false),
		'is_special' => frozr_is_item_special($product_id),
		'is_offline' => $item->post_status == 'offline' ? true : false,
		'vairationsoptions' => $vairation_options,
		'upsells' => $product_obj->get_upsell_ids(),
		'crosssells' => $product_obj->get_cross_sell_ids(),
	),
);

Get list of user orders

GET https://yourwebsite.com/wp-json/norsani/v1/getorders

Get a list of the user previous orders.

Query Parameters

NameTypeDescription

email

string

numberorders

integer

Number of orders to get

/* The response is an encoded JSON data string
 * that contains the below PHP (WordPress,WooCommerce) data.
*/

$data = array(
	'orders' => array(
					array(
						'order_id'	=> $order->get_id(),
						'date'		=> $order_date, // Y-m-d h:i a
						'details'	=> sprintf(__('%s %s from %s','norsani-api'), $item_count, _n('item', 'items',$item_count,'norsani-api'), $store_name),
						'status'	=> $order->get_status(),
					)
				),
	'count' => $orders_count // number of orders returned.
);

Get single order data

GET https://yourwebsite.com/wp-json/norsani/v1/getorder/id

Path Parameters

NameTypeDescription

id

integer

Id of the order to get.

/* The response is an encoded JSON data string
 * that contains the below PHP (WordPress,WooCommerce) data.
*/

$data = array(
	'vendor_id'		=> $vendor_id,
	'store_name'	=> $store_name,
	'store_logo'	=> $vendor_obj->get_store_logo() ? wp_get_attachment_url(absint( $vendor_obj->get_store_logo() )) : '',
	'address'		=> $vendor_obj->get_store_address(),
	'is_store_open'	=> frozr_is_rest_open($vendor_id),
	'coupons'		=> $order->get_used_coupons(),
	'payment_gateway' => false !== $payment_gateway ? ( ! empty( $payment_gateway->method_title ) ? $payment_gateway->method_title : $payment_gateway->get_title() ) : __( 'Payment gateway', 'norsani-api' ),
	'discount'		=> 0 < $order->get_total_discount() ? $order->get_total_discount() : 0,
	'sub_total'		=> $order->get_subtotal(),
	'total'			=> $order->get_total(),
	'date'			=> $order_date,
	'status'		=> $order->get_status(),
	'taxes'			=> array(
							array('label' => esc_html($tax->label), 'amount' => strip_tags( $tax->formatted_amount )),
							array('label' => esc_html($tax->label), 'amount' => strip_tags( $tax->formatted_amount )),
						),
	'fees'			=> array(
							array('name' => $item->get_name() ? $item->get_name() : __( 'Fee', 'norsani-api' ), 'amount' => $item->get_total()),
							array('name' => $item->get_name() ? $item->get_name() : __( 'Fee', 'norsani-api' ), 'amount' => $item->get_total()),
						)
	'refunds'		=> array(
							array(
								'id'		=> $refund->get_id(),
								'details'	=> $details,
								'reason'	=> $refund->get_reason() ? esc_html( $refund->get_reason() ) : null,
								'amount'	=> $refund->get_amount(),
								'currency'	=> $refund->get_currency()
							),
						)
	'items'			=> array(
							array(
								'id' => $product->get_parent_id() > 0 ? $product->get_parent_id() : $product->get_id(),
								'name' => $item->get_name(),
								'imagelink' => wp_get_attachment_thumb_url(absint($product->get_image_id())),
								'variation_id' => $item->get_variation_id() ? $item->get_variation_id() : 0,
								'price' => $order->get_item_total($item),
								'total' => $order->get_line_total($item, true, false),
								'discount' => $item->get_subtotal() !== $item->get_total() ? wc_format_decimal( $order->get_item_subtotal( $item, false, false ) - $order->get_item_total( $item, false, false )) : 0,
								'qty' => $item->get_quantity(),
								'meta_data' => $meta_data[strip_tags($meta->display_key)] = strip_tags($meta->display_value),
								'currency' => $order->get_currency(),
								'refunded' => $refunded = $order->get_total_refunded_for_item( $item_id ) ? $refunded : 0,
								'taxes' => array(
												array(
														'id'		=> $tax_item_id,
														'total'		=> $tax_item_total,
														'subtotal'	=> $tax_item_subtotal,
													)
											),
							),
						)
);

Add to cart

POST https://yourwebsite.com/wp-json/norsani/v1/addtocart

This uses the WooCommerce frontend cart functions to calculate totals, so you always get the up to date accurate cart totals collection on your app. This does not save any data on the server so each time you add a product to cart you should also send the previous cart data.

Query Parameters

NameTypeDescription

cartData

array

Array of cart data to be send as request. array( vendor_id => array( 'items' => array( productID => imagelink => variationID => qty => orderType => specialNotes => variations => // If not applicable set null price => name => maxOrders => remainingOrders => minQty => ), ), ... )

coupons

array

Array of coupon codes to apply.

/* The response is an encoded JSON data string
 * that contains the below PHP (WordPress,WooCommerce) data.
*/

$data = array(
	'added_data' => $added_data[$vendor_id]['items'][] = $cart_item_data, // WooCommerce cart item data. This will only iclude items that was successfully added to cart. This should be saved for next add to cart and checkout calls.
	'messages' => $messages, // Array of error message if found while adding products.
	'cross_sells' => $cross_sells[] = array( // use WP filter norsani_app_cross_sells_data to extend.
				'id' => $product_id,
				'title' => $product_obj->get_name(),
				'is_variable' => $product_obj->is_type( 'variable' ),
				'author' => $vendor_obj->get_store_name(),
				'author_id' => $vendor_id,
				'cats' => $item_cats, // array of category names.
				'image' => wp_get_attachment_thumb_url( $product_obj->get_image_id() ),
				'price' => $price,
				'on_sale' => $product_obj->is_on_sale(),
				'regular_price' => $product_obj->get_regular_price(),
				'sale_price' => $product_obj->get_sale_price(),
				'rating' => floatval(min( 5, round( $product_obj->get_average_rating(), 1 ) )),
			),
	'totals' => array(
		'total' => $cart_total,
		'sub_total' => $cart_subtotal,
		'coupons' => $coupons[] = array(
								'name' => wc_cart_totals_coupon_label( $coupon, false ),
								'amount' => $discount_amount, 
								'free_delivery' => $free_delivery_message, 
								'code' => $code
								),
		'fees' => $fees[] = array(
							'name' => esc_html( $fee->name ),
							'fee' => $cart_totals_fee
							),
		'taxes' => $taxes[] = array(
							'name' => esc_html( WC()->countries->tax_or_vat() ) . $estimated_text,
							'amount' => $cart->get_taxes_total()
							),
	)
)

Get the checkout form.

POST https://yourwebsite.com/wp-json/norsani/v1/getcheckoutform

This will get the checkout form fields as required on the website in addition to the checkout order review and totals.

Query Parameters

NameTypeDescription

cartData

array

Cart data as sent in the Add to Cart request.

coupons

array

Array of coupon codes used in cart.

orderType

string

The user selected order type.

/* The response is an encoded JSON data string
 * that contains the below PHP (WordPress,WooCommerce) data.
*/

$data = array(
	'added_data' => $added_data[$vendor_id]['items'][] = $cart_item_data, // WooCommerce cart item data.
	'messages' => $messages, // Array of error message if found while adding products.
	'checkout_data' => $checkout_data[] = array(
				'vendor_id' => $vendor_id,
				'name' => $vendor->get_store_name(),
				'address' => $vendor->get_store_address(),
				'is_pre_order' => $is_pre_order,
				'preparation_time' => $preparation_time,
				'total_delivery' => $total_formatted_delivery,
				'timing_options' => array( // Order timing.
									'minimum_time'		=> apply_filters('frozr_order_default_time',$minimum_time,$vendor,$item_id), // default time to show.
									'time_instructions' => $timing_det, // instructions for the user for accepted time interval.
									'has_unfixed_time'	=> false, // If true it means the user cannot select an order scheduling time because of different menu timings of the products he is ordering.
									'dates'				=> $days_options, // array of days the user can select.
								),
			),
	'login_required' => $checkout->is_registration_enabled(),
	'billing_form' => $checkout->get_checkout_fields( 'billing' ),
	'totals' => array(
		'total' => $cart_total,
		'sub_total' => $cart_subtotal,
		'coupons' => $coupons[] = array(
								'name' => wc_cart_totals_coupon_label( $coupon, false ),
								'amount' => $discount_amount, 
								'free_delivery' => $free_delivery_message, 
								'code' => $code
								),
		'fees' => $fees[] = array(
							'name' => esc_html( $fee->name ),
							'fee' => $cart_totals_fee
							),
		'taxes' => $taxes[] = array(
							'name' => esc_html( WC()->countries->tax_or_vat() ) . $estimated_text,
							'amount' => $cart->get_taxes_total()
							),
	)
)

Verify checkout data

POST https://yourwebsite.com/wp-json/norsani/v1/verifycheckout

This call must be done just before user has been charged for the order. This will return a data array ready to be used with WooCommerce create order API endpoint. NOTE: This will create a WooCommerce on-hold order.

Query Parameters

NameTypeDescription

cartData

array

Cart data as send in Add to cart request.

ordertimings

array

Order preparation time array. i.e array( array( 'vendor_id' => 23, 'time' => 13:22, 'date' => 26 May, ), ... )

coupons

array

Array of coupon codes used.

billingForm

array

Billing form data. i.e array('billing_email' => user@example.com, ...)

paymentMethod

string

This must be the payment method slug used on WooCommerce. i.e for cash on delivery, WooCommerce uses "COD" slug.

customerNote

string

Delivery notes.

userLocation

string

User full address.

userLocationGeo

string

User geo-location address lat,lng

/* The response is an encoded JSON data string
 * that contains the below PHP (WordPress,WooCommerce) data.
*/

$data = array(
	'create' => $checkout_data[] = array(
				'payment_method' => $payment_method,
				'payment_method_title' => $payment_method == 'cod' ? __('Cash on Delivery','norsani-api') : $payment_method,
				'billing' => $billing_form,
				'set_paid' => false,
				'status' => 'on-hold',
				'meta_data' => $meta_data, // array of order metadata added by Norsani like order preparation time, user geolocation ...etc
				'line_items' => $items, // WooCommerce order line items.
				'coupon_lines' => $coupon_lines, // WooCommerce order coupon lines.
				'fee_lines' => $fee_lines, // Woocommerce order fee lines.
				'customer_note' => $customer_note // This will only be available if there is a note.
			)
);

Last updated