sortin-brand-pkg
v1.0.7
Published
Sortin Rewards App for sustainable brands
Downloads
4
Readme
About
Sortin Rewards Package v1.0.7
Installation
Use NPM to install the package in React Project
npm install sortin-brand-pkg
Widgets
- Sortin Banner:
<SortinBanner/>
tag is used for global banner placed on the bottom left side or the footer element of all pages. The tag is to be implemented at the root component of the react project (main.jsx/ main.tsx) Props:type="banner"
for footer element on black background with 100% page width ortype="fab"
for floating action button on left bottom corner of all pagessize="sm" || "md" || "lg" || "xl"
(Optional) for different Fab banner sizes on screen size below 480px.
Example:<SortinBanner type="fab" size="md"/>
For padding issues after placing//main.jsx ReactDOM.createRoot(document.getElementById("root")).render( <Provider store={store}> <App /> <SortinBanner type="fab" /> </Provider> );
<SortinBanner/>
, add adiv
withstyle={{paddingBottom:'50px'}}
in Main.jsx or any other css value for bottom padding and wrap<App/>
and<SortinBanner/>
under it.
Sortin Product Widget:
<SortinProductWidget/>
tag is used for a single product on product description page to display emission data. Props:id:string
where id is the productId.<SortinProductWidget id={productId}/>
Example:
No
<div>
tag orclassName
is required. (This is just for reference)<div className="other-product-info flex flex-col gap-x-2"> <SortinProductWidget id={productData?.id}/> <div className="font-bold text-white p-5 mt-2"> Brand: {productData?.brandName} </div> </div>
Sortin Cart Widget:
<SortinCartWidget/>
tag is used for the cart page to display total emission information for the entire cart. Props:cartItems
is array of products added to cart withId, quantity, and price
as the necessary props.<SortinCartWidget cartItems={cartItems}/>
Example Format Of cartItems :
cartItems = [{ "id": 123, "quantity": 2, "price": 100 }, { "id": 124, "quantity": 3, "price": 150 }]
Example Code: No
<div>
tag orclassName
is required. This is just for reference.//cart.jsx <div className='lg:col-span-4 lg:pl-4'> <SortinCartWidget cartItems={cartItems}/> </div>
Sortin Cart Item Widget:
<SortinCartItemWidget id={id} qty={quantity}/>
is used to display emission data and sortin coins to be earned by user for every product in cart. This is to be displayed under the cart lines of individual products added by the user. Props:id={product_id}, qty={product_quantity}
<div className="font-medium sm:ml-auto"> <SortinCartItemWidget id={product_id} qty={product_qty}/> </div>
Discount Code
- The discount code generated via sortin is dispatched through an event
"SORTIN_DISCOUNT_GENERATED"
. Subscribe to this event and apply the discount code using store's predefined method.window.addEventListener("SORTIN_DISCOUNT_GENERATED", (event: Event)=>{ const discountCode= (event as any).data; // Generated Discount Code // Implement Discount Code Apply Function })
- Delete discount code from Local Storage when order is created:
localStorage.removeItem("sortinDiscountCode")
Create Order API
Send an API request to sortin in order to reward users after order creation, with the following configuration:
- Embed sortin_user_id in order metadata to be sent to your backend after fetching it from localStorage of your website.
"sortinUserData"
is the local storage key.const sortinUser = JSON.parse(localStorage.get("sortinUserData")) const sortinUserId = sortinUser.userId
- Add discount code used by the user in order metadata. Discount code via sortin will be generated and pasted by user before checkout or can be fetched by the host website from localStorage and pasted directly in the promocode/discount input box.
- API Payload Schema: (order_metadata)
Example Payload (order_metadata):type Customer = { firstName: string; lastName: string; email?: string; phone: string; }; type Address = { addressLine: string; city: string; state: string; pincode: string; } type Product = { productId: string; quantity: number; price: string; }; type Order = { userId: string | null; //sortinUserId orderId: string; //unique value to be supplied with each order productQty: number; subtotal: string; total: string; customer: Customer; address: { billingAddress?: Address | null; shippingAddress: Address; }; products: Product[]; discount: string | null; };
{ "orderId": "57sad09fg6h470", "productQty": 1, "subtotal": "2579.95", "total": "3044.34", "userId":"717d6b80-dc9f-4b80-bc37-4b723ab84284", "customer": { "firstName": "sid", "lastName": "saxena", "email": "[email protected]", "phone": "23950207530" }, "address": { "billingAddress": { "addressLine": "Caunaut Place Hanuman Road Area Connaught Place 231/213", "city": "New Delhi", "state": "DL", "pincode": "110001" }, "shippingAddress": { "addressLine": "Caunaut Place Hanuman Road Area Connaught Place 231/213", "city": "New Delhi", "state": "DL", "pincode": "110001" } }, "products": [ { "productId": "70dsf6368s454", "quantity": 1, "price": "2579.95" } ], "discount": "sortin_50_975ac4" }
- API call:
endpoint: https://qektcoqosyapxflftmss.supabase.co/functions/v1/custom-brand-app/order/create
method:POST
headers: x-sortin-key
An access key provided by sortin, to be stored in host page environment and supplied with each create order api callbody: order_metadata
const response = await fetch( 'https://qektcoqosyapxflftmss.supabase.co/functions/v1/custom-brand-app/order/create', { method: "POST", headers:{ "Content-Type": "application/json", "x-sortin-key": process.env.x-sortin-key }, body: JSON.stringify(order_metadata) })