Headline:
Improve handling of prices by external system
Description:
If pricing is obtained by a python task which obtains costs from an external system, this can take a few seconds to complete and update the price on the order form.
To improve this:
- If a plan is not selected, or is changed, then show a “calculating…” placeholder prior to the script completing and prevent the form being submitted.
- In the event of an error / invalid price, display a message (either generated by the task or from Morpheus) and prevent ordering. At the moment our script has a try/catch block and simply produces a price of £999,999.99 if the external system is unavailable.
- Prevent going to the next page of the order screen while waiting for task to complete. At present, you can change plan and if the task takes 2-3 seconds to complete you can click Next on the order form which uses the newly-selected plan, but the originally displayed price.
Example/Use case(s):
Custom pricing generated from a Python task which obtains data from an external system. Can replicate the issue of slow pricing by a simple python task - select a plan, wait for price to appear, change the plan and go to the order summary and the new plan will be selected but with the original price:
import time
import json
import random
time.sleep(5)
month_total_price = round(random.uniform(1.00, 99.99), 2)
prices = {
'priceData': [
{
'incurCharges': 'always',
'currency': 'GBP',
'unit': 'month',
'cost': month_total_price,
'price': month_total_price
},
{
'incurCharges': 'running',
'currency': 'GBP',
'unit': 'month',
'cost': 0,
'price': 0
},
{
'incurCharges': 'stopped',
'currency': 'GBP',
'unit': 'month',
'cost': 0,
'price': 0
}
]
}
print(json.dumps(prices, indent=2, separators=(',', ':')))