Developer Resources
Client Side Pricing Engine
23 min
the client side pricing engine is a powerful client side calculation tool that mirrors nue's server side pricing logic, enabling real time price calculations without server roundtrips this ensures consistent pricing across your application while providing immediate feedback to users the engine is designed to handle both new order price calculations and change order price calculations with the same accuracy as server side calculations, reducing latency and dependency on network requests \# primary use cases \# new order price calculations this functionality calculates prices for new products based on the following factors base product pricing quantity selections term length unit of measure (e g , monthly, annual, one time) product options and configurations \# change order price calculations this functionality provides immediate pricing feedback when users make changes to existing subscriptions, such as adjusting quantities changing subscription terms renewing subscriptions co terming subscriptions cancelling subscriptions term calculations this functionality provides the term calculation engine that can be used in both new order and change order calculations, handling automatic term calculations for subscription durations support for all term types (monthly, quarterly, yearly) various term basis calculations (30/360, actual/360) \# key benefits real time calculations instantly calculate prices based on product configurations and user actions server side parity ensures the same pricing logic is applied as on the server side, ensuring consistency offline capability calculate pricing without needing to rely on network connectivity performance offload resource heavy pricing calculations to the client, improving server performance consistency accurate and uniform pricing across all platforms, ensuring a seamless experience \# installation \# registry setup add the following to your npmrc file \# node version control engine strict=true \# registry configuration registry=https //registry npmjs org/ @nue apps\ registry=https //gitlab com/api/v4/projects/42706932/packages/npm/ always auth=true \# authentication (contact nue team for token) //gitlab com/api/v4/projects/42706932/packages/npm/ authtoken=${gitlab npm auth token} package installation npm i @nue apps/nue pricing clientjs \# typescript ts types for all nue self service related objects are available in the nue js library npm i @nue apps/nue js // usage import type { subscription, product, localpricingenginesubscriptionchange } from '@nue apps/nue js' \# usage via cdn by request, nue can also provide an access token to access a cdn link for using the pricing engine in no code, low code, or buildless html/js projects step 1 include the script include the script in your html using the cdn link \<script src="https //ss pricing client nue io/nue pricing clientjs 1 1 4 js?token=request token from nue">\</script> this script loads the nuepricingengine global object, which contains all the classes and methods for pricing calculations note the package version number in the example \<script> code above (1 1 4) may be outdated ask your nue admin for the latest version number step 2 use the nuepricingengine global object all standard pricing engine classes can be instantiated as usual via the nuepricingengine global object example \<script> const productcalculator = new nuepricingengine nueproductcalculator({ termbasis "eu30/360", }); const calculationresult = productcalculator calculate({ // input object for calculation }); \</script> for details on pricing engine usage, continue reading below \# new order price calculations to calculate prices for new products, you typically need to retrieve product data ( get /catalog/product ) once the data is retrieved, it can be passed to the nueproductcalculator to perform the price calculation example code import { nueproductcalculator, productcalculationobject, } from '@nue apps/nue pricing clientjs'; // example product data (usually fetched from an api) const productresponse = { "id" "01tei0000088m9qiau", "name" "revenue dashboard", "sku" "revenue dashboard", "pricemodel" "recurring", "pricebookentries" \[ { "id" "01uei000002fr2diaa", "listprice" 9 9, "uom" { "name" "user/month", "quantitydimension" "user", "termdimension" "month" }, "currencyisocode" "usd" } ], "uom" { "name" "user/month", "quantitydimension" "user", "termdimension" "month" } }; // assuming product data and price book entries are retrieved from api and prepared const product = productresponse; const pricebookentry = product pricebookentries\[0]; // construct the product input object for price calculation const productinput productcalculationobject = { id product id, // product id from api response priceinfo { listprice pricebookentry listprice, pricetags product productpricetags || \[], }, productinfo { sku product sku, pricemodel product pricemodel, name product name, productcategory product productcategory, recordtype product recordtype, showincludedproductoptions product showincludedproductoptions, freetrialtype product freetrialtype, freetrialunit product freetrialunit }, //new order details quantity 1, startdate "2024 03 20", term 12, uom pricebookentry uom, productoptions product productoptions || \[], }; // initialize the pricing calculator const productcalculator = new nueproductcalculator({ termbasis "30/360", }); // perform the pricing calculation const result = productcalculator calculate(productinput); example response { "details" { "deltaacv" 60, "deltaarr" 60, "deltacmrr" 5, "deltatcv" 5, "discountamount" 0, "discountpercentage" 0, "id" "01tfj000000lwt9qao", "listtotal" 5, "netsalesprice" 5, "salesprice" 5, "systemdiscount" 0, "systemdiscountamount" 0, "subtotal" 5, "totalamount" 5, "totalprice" 5 }, "summary" { "discountamount" 0, "discountpercentage" 0, "listtotal" 5, "subtotal" 5, "systemdiscountamount" 0, "systemdiscountpercentage" 0, "totalamount" 5, "totalprice" 5 } } \# change order price calculations for change order pricing , the client side pricing engine can handle subscription changes like adjusting quantities, modifying terms, renewing subscriptions, and co terminating subscriptions \# api request for pricing engine data to streamline the process of collecting data necessary for change order pricing calculations, we provide an api endpoint that fetches all relevant information in one request for a specific customer this endpoint consolidates the pricing data from multiple sources, making it easier for the client side pricing engine to perform accurate price calculations for subscription changes across all customer subscriptions request get https //api nue io/ss/orders/pricing engine input?customerids=\["customerid"] example response { "status" "success", "data" { "sub 00000483" { "changes" \[ { "changetype" "newproduct", "enddate" "2025 01 12", "linetype" "lineitem", "listtotal" 148 5, "netsalesprice" 9 9, "quantity" 15, "startdate" "2024 12 13", "subtotal" 148 5, "term" 1, "totalamount" 148 5, "totalprice" 148 5 }, { "changetype" "updatequantity", "enddate" "2025 01 12", "linetype" "lineitem", "listtotal" 29 7, "netsalesprice" 9 9, "quantity" 3, "startdate" "2024 12 13", "subtotal" 29 7, "term" 1, "totalamount" 29 7, "totalprice" 29 7 } ], "orderproduct" { "enddate" "2025 01 12", "listprice" 9 9, "listtotal" 178 2, "pricetags" \[ { "active" true, "code" "10percentoffdemo", "id" "a0xei000003grovmag", "lastpublishedbyid" "005ei00000ggd7tiaf", "lastpublisheddate" "2024 12 13", "name" "10% discount term based", "pricetagtype" "term", "pricetiers" \[ { "chargemodel" "perunit", "discountpercentage" 10, "endunit" 12, "id" "a0yei000002ebjvma0", "name" "pt 00000000", "startunit" 0, "tiernumber" 1 } ], "pricetype" "volume", "publishstatus" "published", "recordtype" "discountdimension", "starttime" "2023 03 31t16 01z", "uomdimension" "quarter" } ], "product" { "id" "01tei0000088m9qiau", "name" "revenue dashboard", "pricemodel" "recurring", "productcategory" "recurringservices", "showincludedproductoptions" false, "sku" "revenue dashboard" }, "quantity" 18, "refid" "25bb7873 7649 4c84 b2bd e8dda2929e03", "startdate" "2024 12 13", "subtotal" 178 2, "term" 1, "uom" { "decimalscale" 0, "name" "user/month", "quantitydimension" "user", "roundingmode" "up", "termdimension" "month" } } } }, "warnings" \[] } the response data is a map keyed by each subscription name // typescript // you can also import this type from the @nue apps/nue js library import type { localpricingenginesubscriptionchange } from '@nue apps/nue js' // ts type for each value in the map type localpricingenginesubscriptionchange = { changes localpricingenginechanges; orderproduct localpricingengineorderproduct; } // ts type for full `data` map type subscriptionpricingenginemap = record\<string, localpricingenginesubscriptionchange> \# recalculating subscription pricing example code import type { localpricingenginesubscriptionchange, subscription, subscriptionwithproduct } from '@nue apps/nue js' type subscriptionpricingenginemap = record\<string, localpricingenginesubscriptionchange> // fetch subscription pricing data (add own error handling) async function getpricingenginemap(customerid) subscriptionpricingenginemap { try { const response = await fetch(`https //api nue io/ss/orders/subscriptions/pricing engine input?customerids=\["customerid"]`); const parsed = await response json(); return parsed? data } catch(err) { // handle error } }; const pricingenginemap = await getpricingenginemap(); //the object for the subscription being changed const subscription subscription | subscriptionwithproduct = subscriptionbeingcalculated; // find the matching pricing data from the pricingenginemap const pricingdata localpricingenginesubscriptionchange = pricingenginemap? \[subscription name]; // constructing the subscription input object const subscriptioninput changeordercalculationasset = { totalprice subscription totalprice, totalamount subscription totalamount, term subscription subscriptionterm, assetnumber subscription name, startdate subscription subscriptionstartdate, enddate subscription subscriptionenddate, quantity subscription quantity, listtotal pricingdata orderproduct listtotal, subtotal pricingdata orderproduct subtotal, pricingdata, // include rest of the pricing data }; // initialize and use the pricing change order calculator const changeordercalculator = new nuepricingchangeordercalculator(); //changes array that includes all changes to the subscription const changes = \[{ changetype 'renew', renewalterm 12 }] const result = changeordercalculator calculatewithassetchanges(subscriptioninput, changes); example response { "assetprice" { "assetnumber" "sub 000084", "changeitems" \[ { "deltaacv" 50000, "deltaarr" 50000, "deltacmrr" 4166 666666666667, "deltatcv" 600000, "discountamount" 0, "discountpercentage" 0, "enddate" "2046 03 03", "listtotal" 600000, "netsalesprice" 500, "quantity" 100, "salesprice" 500, "startdate" "2034 03 04", "subtotal" 600000, "systemdiscount" 0, "systemdiscountamount" 0, "term" 12, "changetype" "renew", "totalamount" 660000, "totalprice" 600000 } ], "enddate" "2046 03 03", "quantity" 100, "startdate" "2022 03 04", "term" 24 }, "pricesummary" { "totalamount" 660000, "totalprice" 600000 } } \# term calculations the term calculator provides a simple way to calculate subscription terms for both new orders and change orders, eliminating the need for complex date and term calculations in your application example code import { nuetermcalculator } from '@nue apps/nue pricing clientjs'; // initialize the term calculator const termcalculator = new nuetermcalculator(); // calculate term between two dates const term = termcalculator calculateterm( "2024 03 20", // start date "2025 03 20", // end date "month", // term "30/360" // term basis "30/360" | "actual/actual" | "eu30/360" | "actual/360" | "actual/365"; ); console log('calculated term ', term); example response calculated term 12 033333333333333
🤔
Have a question?
Get answers fast with Nue’s intelligent AI, expert support team, and a growing community of users - all here to help you succeed.
To ask a question or participate in discussions, you'll need to authenticate first.