amrest_helper
v1.0.1
Published
Lib which help to connect with amrest architecture. Contains helpfull builders and easy connect to endpoints
Downloads
1
Readme
AMREST HELPER
Installation
npm install amrest_helper
Usage
React
Before use any endpoints set RestaurantId
#!javascript
import Amrest from 'amrest_helper'
...
Amrest.setRestaurantId(32)
...
our endpoints it's a Promise object, every call is asynchrous
#!javascript
import Amrest from 'amrest_helper'
...
Amrest.getMenu('1488808560340').then((menu) => {
console.log(menu)
})
...
we can catch every error
#!javascript
import Amrest from 'amrest_helper'
...
Amrest.getMenu('1488808560340').then((menu) => {
console.log(menu)
}).catch(err => {
console.log(err)
})
...
###Example:###
#!javascript
import React from 'react'
import Amrest, { Basket, Customer, DeliveryAddress, Order } from 'amrest_helper'
export default class Sample extends React.Component {
constructor (props) {
super(props)
this.state = {
menu: {}
}
this.basket = new Basket()
this.order = new Order()
this.submitWithOneProduct = this.submitWithOneProduct.bind(this)
}
submitWithOneProduct() {
if (this.state.menu) {
this.basket.addBasketLine(this.state.menu.menu.categories[6].products['14500251'], 2)
this.order.setCustomer(Customer().setName('Andsafsadf').setPhoneNumber('123654234').getJSON())
this.order.setDeliveryAddress(
DeliveryAddress()
.setName('Andsafsadf')
.setCity('Warszawa')
.setStreet('Aroniowa')
.setHouseNumber('199')
.getJSON())
this.order.setBasket(this.basket.getJSON())
Amrest.postOrderSubmit(this.order.getJSON()).then(() => {
console.log('Order submitted!')
})
}
}
componentDidMount () {
Amrest.setLanguage('EN')
Amrest.setRestaurantId(21)
Amrest.getMenu().then(menu => {
this.setState({menu: menu})
}
}
render () {
return (
<button onClick={() => this.submitWithOneProduct()}> Click </button>
)
}
}
Config
setLanguage(string) - set language (default value: 'PL'), params:
- lang - Language (example. 'PL', 'EN')
setDeliveryType(string) - set delivery type (default value: 'DELIVERY'), params:
- type - delivery type (example. 'DELIVERY', 'DINE_IN')
setRestaurantId(number) - set restaurant id required, params:
- restauraintId - Restaurant id (example. 512, 222)
Endpoints
getMenu(string) - The method returns the menu for the given restaurant, params:
- last - Last Modified, timestamp (example. '1488808560340')
getProductConfig(string, string, string) - The method returns further details for the selected product option, params:
prodId - Product identifier whose details are downloaded
productType - Product type
configId - ID number of the selected configuration option
putProductConfig(object) - Download a new configuration for the product, params:
- body - ProductConfigUpdateRequest
#!json
{
"currentProduct": {
"id": 764334678,
"name": "Buckets 30 hot wings",
"price": 12.9,
"img": "string",
"description": "Buckets 30 hot wings",
"productType": 2,
"priority": 1,
"extrasCategoryId": 20,
"condimetsCategoryId": 20,
"requiredCondimentsCategoryId": 20,
"checkboxCondimentsCategoryId": 20,
"subCategoryId": 2,
"productConfig": [
{
"optionId": 12125,
"optionNum": 0,
"optionTitle": "Group name",
"img": "url/to/KFCoto",
"price": "string",
"description": "string",
"singleChoice": true,
"additionalProperties": [
{
"key": 5,
"value": 5
}
],
"availableItems": [
{
"productId": 54357688,
"name": "Chips",
"isDefault": false,
"img": "http://url/to/KFCoto",
"price": 2.55,
"quantity": 4,
"unitPrice": 24.3,
"description": "crunchy wings"
}
],
"bucketGroupName": "Chickens",
"bucketGroupPriority": 1
}
],
"additionalProperties": [
{
"key": 5,
"value": 5
}
],
"promoCodeProduct": true,
"favouriteProduct": true,
"upsellId": 5
},
"choosedModification": {
"optionId": 234311,
"optionNum": 5,
"optionProduct": [
{
"id": 5,
"isDouble": false
}
]
}
}
postOrderSubmit(object) - Submit an order, params:
- body - Basket
#!json
{
"basket": {
"promoCode": "235gewr",
"basketLines": [
{
"quantity": 1,
"uuid": "ssddsgo-sdg235",
"parentuuid": "sdgs",
"positionPrice": "string",
"product": {
"id": 764334678,
"name": "Buckets 30 hot wings",
"price": 12.9,
"img": "string",
"description": "Buckets 30 hot wings",
"productType": 2,
"priority": 1,
"extrasCategoryId": 20,
"condimetsCategoryId": 20,
"requiredCondimentsCategoryId": 20,
"checkboxCondimentsCategoryId": 20,
"subCategoryId": 2,
"productConfig": [
{
"optionId": 12125,
"optionNum": 0,
"optionTitle": "Group name",
"img": "url/to/KFCoto",
"price": "string",
"description": "string",
"singleChoice": true,
"additionalProperties": [
{
"key": 5,
"value": 5
}
],
"availableItems": [
{
"productId": 54357688,
"name": "Chips",
"isDefault": false,
"img": "http://url/to/KFCoto",
"price": 2.55,
"quantity": 4,
"unitPrice": 24.3,
"description": "crunchy wings"
}
],
"bucketGroupName": "Chickens",
"bucketGroupPriority": 1
}
],
"additionalProperties": [
{
"key": 5,
"value": 5
}
],
"promoCodeProduct": true,
"favouriteProduct": true,
"upsellId": 5
}
}
]
},
"customer": {
"customerName": "string",
"firstName": "string",
"lastName": "string",
"phoneNumber": "string",
"emailAddress": "string"
},
"deliveryAddress": {
"id": 1,
"name": "Dom",
"city": "Warszawa",
"street": "Aroniowa",
"houseNumber": 199,
"apartNumber": 5,
"zipCode": "02-083",
"lat": 20.235235,
"lng": 51.235235,
"isDefault": false,
"inDeliveryZone": false
},
"deliveryNotes": "Please bring hot",
"deliveryTime": 690,
"orderInvoice": {
"name": "My invoice no 1.",
"taxid": 11111111111,
"addressCity": "Warszawa",
"addressStreet": "Podbipięty 51",
"addressPostalcode": "01-924",
"companyName": "Budimex",
"defaultInvoice": true
},
"invoice": false,
"deliveryType": "DELIVERY",
"orderType": "DI/TA",
"paymentType": "CASH",
"cashDeclared": 50,
"restaurantId": 5,
"takeAwayPass": "string",
"termsOfUse": true,
"mobileDeviceId": "sdgosdg-15125ss-dgsd",
"reorder": true
}
Builders
Order
getJSON() - The method returns the order json
setBasket(object) - The method set basket, params:
- basket - Basket object (example. in Basket builder)
setCustomer(object) - The method set customer, params:
- customer - Customer object (example. in Customer builder)
setDeliveryAddress(object) - The method set delivery address, params:
- deliveryAddress - Delivery address object (example. in DeliveryAddress builder)
setDeliveryTime(number) - The method set delivery time (default: 30), params:
- deliveryTime - Delivery time as minutes (example. 30)
setPaymentType(string) - The method set payment type (default: 'CASH'), params:
- paymentType - Payment type (example. 'CASH', 'CARD')
setCashDeclared(number) - The method set declared cash from customer (default: 0), params:
- cashDeclared - Cash declared (example. 50, 100)
setInvoice(boolean) - The method set if the customer wants invoice, params:
- invoice - Invoice (example. true, false)
setOrderInvoice(object) - The method set order Invoice, params:
- orderInvoice - Order Invoice object (example. in OrderInvoice builder)
setTermsOfUse(boolean) - The method set if the customer accept terms of use, params:
- termsOfUse - Terms of use (example. true, false)
Basket
getJSON() - The method returns the basket json
setPromoCode(string) - The method set promo code, params:
- code - Promo Code (example. '14sdA8856C40')
setBasketLines(string) - The method set Basket Lines, params:
- basketLines - Promo Code (example look submit endpoint)
addBasketLine(string, number, string) - The method add basket line to basket lines, params:
product - Product (example look submit endpoint)
quantity (default: 1) - Quantity (example 1, 2)
parentUuid - required for products from 'extrasCategories' ( get uuid from added products )
removeBasketLine(number) - The method remove product from basket lines, params:
- index - line index to remove (example. 2, 0)
setCustomer(object) - The method set customer, params:
- customer - Customer object (example. in Customer builder)
setDeliveryAddress(object) - The method set delivery address, params:
- deliveryAddress - Delivery address object (example. in DeliveryAddress builder)
setDeliveryTime(number) - The method set delivery time (default: 30), params:
- deliveryTime - Delivery time as minutes (example. 30)
setPaymentType(string) - The method set payment type (default: 'CASH'), params:
- paymentType - Payment type (example. 'CASH', 'CARD')
setCashDeclared(number) - The method set declared cash from customer (default: 0), params:
- cashDeclared - Cash declared (example. 50, 100)
setInvoice(boolean) - The method set if the customer wants invoice, params:
- invoice - Invoice (example. true, false)
setOrderInvoice(object) - The method set order Invoice, params:
- orderInvoice - Order Invoice object (example. in OrderInvoice builder)
setTermsOfUse(boolean) - The method set if the customer accept terms of use, params:
- termsOfUse - Terms of use (example. true, false)
Customer
getJSON() - The method returns the customer json
setName(string) - The method set name for customer, params:
- name - Customer name (example. 'Andrjew Sakasvili')
setPhoneNumber(string) - The method set customer phone number, params:
- phoneNumber - Phone number (example '669359630')
DeliveryAddress
getJSON() - The method returns the delivery address json
setName(string) - The method set name for delivery address, params:
- name - Delivery address name (example. 'dom')
setCity(string) - The method set city, params:
- city - City (example 'Warsaw')
setStreet(string) - The method set street, params:
- street - Street (example 'Bonifacego')
setHouseNumber(string) - The method set house number, params:
- number - House number (example '43', '54b')
setApartNumber(string) - The method set apart number, params:
- number - Apart number (example '12', '54a)
OrderInvoice
getJSON() - The method returns the order invoice json
setAddressCity(string) - The method set invoice city, params:
- addressCity - invoice city (example 'Warsaw')
setAddressPostalcode(string) - The method set postal code, params:
- addressPostalcode - invoice postal code (example '02-563')
setName(string) - The method set name for invoice, params:
- name - Invoice name (example. 'dom')
setAddressStreet(string) - The method set address street and number, params:
- addressStreet - Address street and number (example '43', '54b')
setCompanyName(string) - The method set company name, params:
- companyName - Company name (example 'Texeldon Sp.z.o.o')
setTaxid(number) - The method set tax id, params:
- taxid - tax number (example 11111111111)