@vinit & @ish taking this one step further, I added a preferred payment option. If the user selects credit card, I make two API calls to Math.js. The first calculates the services fee associated with the credit transaction, and the second rounds the total since it is based on a percentage. The only hiccup is the math.js devs have not added a second argument for
ceil which would allow you to identify the decimal that will always round up. Right now it only rounds to the nearest whole number.
However, there is already a discussion thread on GitHub about adding this feature. I commented on my user case, so here is hoping they add it. If anyone else is interested in them including this feature, leave a comment on the thread https://github.com/josdejong/mathjs/issues/1021 You can add a rounding function with a second argument, but this will round either up or down depending on whether the number is less than five or greater than or equal to five. Those pennies add up, so I wouldn’t suggest going this route as rule of thumb. However, if you are okay with rounding to the nearest dollar than your API calls would look something like this:
The previous gambit filters users based on age. In this case anyone renewing a license that is 20-67 years old will jump to this gambit as the fee is 41.72 for this age bracket. Other ages have adjusted fees (this particular fee calculator has nine gambit outcomes the user will jump to based on age)
(I would add the preferred payment selection to this list as well… I simply forgot for the demo
This is what the user will see as an end result
Now taking this one step further, this could be used to apply discount codes and whatnot to an order. I’m thinking that a paypal/square API integration shouldn’t be too hard to implement. If we could make these payment methods make the call on the totals ran through math.js, in theory we can add a simple payment method within bots that calculates totals of items, calculates discounts, and hands off the totals to Paypal/Square/etc.
See! All I needed was the video tutorial!