* - An instance of JSONObject that contains promotion information.
* @return
* - Promotion object that corresponds to the json input.
*/
private Promotion assemblePromotionObjectFromJSON(JSONObject jsonObject) {
Promotion promotion = new Promotion();
promotion.setId((String) jsonObject.get("id"));
promotion.setOrderId((String) jsonObject.get("order_id"));
promotion.setDiscountAmount(Double.valueOf(jsonObject.get("discount_amount").toString()));
String status = (String) jsonObject.get("status");
promotion.setStatus(PromotionStatus.valueOf(status));
ArrayList<JSONObject> conditions = (ArrayList<JSONObject>) jsonObject.get("conditions");
ArrayList<JSONObject> rules = (ArrayList<JSONObject>) jsonObject.get("rules");
List<PromotionCondition> promotionConditions = new ArrayList<PromotionCondition>();
for(JSONObject jsonCondition : (conditions != null ? conditions : rules)) {
PromotionCondition promotionCondition = new PromotionCondition();
promotionCondition.setDimension((String) jsonCondition.get("dimension"));
promotionCondition.setValue((String) jsonCondition.get("value"));
promotionConditions.add(promotionCondition);
}
promotion.setPromotionConditions(promotionConditions);
return promotion;
}