//partendo dal JToken crea la lista delle campagne private List <FidelityCampaign> CreateCampaignListFromToken(JToken tokenRewards) { List <FidelityCampaign> list = new List <FidelityCampaign>(); if (tokenRewards.Children().Count() > 0) { foreach (JToken tokenCamp in tokenRewards.Children()) { FidelityCampaign campaign = new FidelityCampaign(); campaign.Id = tokenCamp.Value <string>("id"); campaign.Name = tokenCamp.Value <string>("name"); try { campaign.AddData("description", tokenCamp.SelectToken("description").ToString()); } catch { campaign.AddData("description", "no description"); } campaign.AddData("type", tokenCamp.SelectToken("type").ToString()); //addReward list.Add(campaign); } } return(list); }
public virtual APIResult <CardPointsCampaign> AddPoints(string numPoints, string campaignId, string customerId) { APIResult <CardPointsCampaign> res = new APIResult <CardPointsCampaign>(); FidelityCustomer customer; if (customerId == null) { customer = GetCustomerFromAuthenticatedUser(); } else { customer = GetCustomerFromIdOrEmail(customerId); } FidelityCampaign campaign = new FidelityCampaign(); campaign.Id = campaignId; if (customer != null) { APIResult <bool> resAdd = _sendService.SendAddPoints(settingsPart, customer, campaign, numPoints); if (!resAdd.success) { res = new APIResult <CardPointsCampaign> { success = false, data = null, message = resAdd.message }; } else { APIResult <FidelityCustomer> resCust = _sendService.SendCustomerDetails(settingsPart, customer); if (!resCust.success) { res = new APIResult <CardPointsCampaign> { success = false, data = null, message = resCust.message }; } else { res.success = resAdd.success; res.message = resAdd.message; CardPointsCampaign data = new CardPointsCampaign() { idCampaign = campaignId, idCustomer = customer.Id, points = resCust.data.PointsInCampaign[campaignId] }; res.data = data; } } } else { res = new APIResult <CardPointsCampaign> { success = false, data = null, message = "The user is not configured to use " + GetProviderName() }; } _workflowManager.TriggerEvent("AddFidelityPoints", null, () => new Dictionary <string, object> { { "result", res } }); return(res); }
public virtual APIResult <FidelityCampaign> GetCampaignData(string id) { FidelityCampaign campaign = new FidelityCampaign(); campaign.Id = id; return(_sendService.SendCampaignData(settingsPart, campaign)); }
public virtual APIResult <FidelityReward> GiveReward(string rewardId, string campaignId, string customerId) { APIResult <FidelityReward> res = new APIResult <FidelityReward>(); FidelityCustomer customer; if (customerId == null) { customer = GetCustomerFromAuthenticatedUser(); } else { customer = GetCustomerFromIdOrEmail(customerId); } if (customer != null) { FidelityReward reward = new FidelityReward(); reward.Id = rewardId; FidelityCampaign campaign = new FidelityCampaign(); campaign.Id = campaignId; APIResult <bool> resGive = _sendService.SendGiveReward(settingsPart, customer, reward, campaign); if (!resGive.success) { res = new APIResult <FidelityReward> { success = false, data = null, message = resGive.message }; } else { APIResult <FidelityCampaign> resCamp = _sendService.SendCampaignData(settingsPart, campaign); if (!resCamp.success) { res = new APIResult <FidelityReward> { success = false, data = null, message = resCamp.message }; } else { res.message = resGive.message; res.success = resGive.success; res.data = resCamp.data.Rewards.Where(r => r.Id.Equals(rewardId)).First(); } } } else { res = new APIResult <FidelityReward> { success = false, data = null, message = "The user is not configured to use " + GetProviderName() }; } _workflowManager.TriggerEvent("RedeemFidelityReward", null, () => new Dictionary <string, object> { { "result", res } }); return(res); }
//TODO controllare se con la campagna sbagliata crasha male public override APIResult <FidelityCampaign> GetCampaignData(string id) { FidelityCampaign campaign = new FidelityCampaign(); campaign.Id = id; APIResult <FidelityCampaign> res = _sendService.SendCampaignData(settingsPart, campaign); APIResult <IEnumerable <FidelityCampaign> > resList = _sendService.SendCampaignList(settingsPart); FidelityCampaign campInList = resList.data.Where(c => c.Id.Equals(id)).First(); res.data.Data = campInList.Data; res.data.Name = campInList.Name; return(res); }
//partendo dal JToken che rappresenta il catalogo setta la propietà catalogo dalla campaign private void AddRewardsInCampaignFromToken(JToken tokenRewards, FidelityCampaign campaign) { if (tokenRewards.Children().Count() > 0) { foreach (JToken tokenRew in tokenRewards.Children()) { FidelityReward reward = new FidelityReward(); reward.Id = tokenRew.Value <string>("id"); reward.Description = tokenRew.Value <string>("description"); campaign.Rewards.Add(reward); campaign.AddReward(reward.Id, tokenRew.Value <string>("level")); } } }
//rimuove dal dizionario data della campaign tutti i dati presenti anche nelle propità //inoltre aggiunge il catalogo private void RemoveCampaignPropertyFromDataDictionary(FidelityCampaign campaign) { Dictionary <string, string> data = campaign.Data; if (data.ContainsKey("name")) { campaign.Name = data["name"]; data.Remove("name"); } if (data.ContainsKey("loyalty_scheme")) { string jsonList = data["loyalty_scheme"]; JObject loyalty_scheme = JObject.Parse(data["loyalty_scheme"]); if (loyalty_scheme.SelectToken("rewards") != null) { AddRewardsInCampaignFromToken(loyalty_scheme.SelectToken("rewards"), campaign); } campaign.Data.Remove("loyalty_scheme"); } if (data.ContainsKey("opening_hours")) { data.Remove("opening_hours"); }//TODO vedere se è interessante includerle nelle data }
public APIResult <FidelityCampaign> SendCampaignData(FidelitySettingsPart setPart, FidelityCampaign campaign) { APIResult <FidelityCampaign> result = new APIResult <FidelityCampaign>(); result.data = null; try { List <KeyValuePair <string, string> > kvpList = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("campaign_id", campaign.Id) }; string responseString = SendRequest(setPart, "campaign_rewards", kvpList); if (!string.IsNullOrWhiteSpace(responseString)) { JObject data = JObject.Parse(responseString); result.success = data.Value <string>("status").Equals("success"); if (result.success) { AddRewardsInCampaignFromToken(data.SelectToken("rewards"), campaign); result.data = campaign; result.message = "Simsol campaign data request success."; } else { result.message = data.SelectToken("errors").ToString(); } } else { result.success = false; result.message = "no response from Simsol server."; } } catch (Exception ex) { result.success = false; result.message = "exception: " + ex.Message + ";"; } return(result); }
public APIResult <bool> SendGiveReward(FidelitySettingsPart setPart, FidelityCustomer customer, FidelityReward reward, FidelityCampaign campaign) { APIResult <bool> result = new APIResult <bool>(); result.data = false; try { List <KeyValuePair <string, string> > kvpList = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("campaign_id", campaign.Id), new KeyValuePair <string, string>("code", customer.Id), new KeyValuePair <string, string>("reward_to_redeem", reward.Id), }; string responseString = SendRequest(setPart, "redeem", kvpList); if (!string.IsNullOrWhiteSpace(responseString)) { JObject data = JObject.Parse(responseString); result.success = data.Value <string>("status").Equals("success"); if (result.success) { result.data = true; result.message = "Simsol reward gived with success."; } else { result.message = "The reward level selected exceeds the points available"; } } else { result.message = "no response from Loyalzoo server."; } } catch (Exception ex) { result.message = "exception: " + ex.Message + "."; } return(result); }
public APIResult <bool> SendAddPoints(FidelitySettingsPart setPart, FidelityCustomer customer, FidelityCampaign campaign, string points) { APIResult <bool> result = new APIResult <bool>(); result.success = false; result.data = false; try { List <KeyValuePair <string, string> > kvpList = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("campaign_id", campaign.Id), new KeyValuePair <string, string>("code", customer.Id), new KeyValuePair <string, string>("amount", points), }; string responseString = SendRequest(setPart, "record_activity", kvpList); if (!string.IsNullOrWhiteSpace(responseString)) { JObject data = JObject.Parse(responseString); result.success = data.Value <string>("status").Equals("success"); if (result.success) { result.data = true; result.message = "Simsol points added with success."; } else { result.message = data.SelectToken("errors").ToString(); } } else { result.message = "no response from Simsol server."; } } catch (Exception ex) { result.message = "exception: " + ex.Message + "."; } return(result); }
public APIResult <FidelityCampaign> SendCampaignData(FidelitySettingsPart setPart, FidelityCampaign campaign) { APIResult <FidelityCampaign> result = new APIResult <FidelityCampaign>(); result.data = null; try { List <KeyValuePair <string, string> > kvpList = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("place_id", campaign.Id), new KeyValuePair <string, string>("session_id", setPart.AccountID), }; string responseString = SendRequest(setPart, APIType.merchant, "place", kvpList); if (!string.IsNullOrWhiteSpace(responseString)) { JObject data = JObject.Parse(responseString); result.success = data.Value <bool>("success"); if (result.success) { campaign.Data = this.DictionaryFromResponseToken(data.SelectToken("response")); RemoveCampaignPropertyFromDataDictionary(campaign); result.data = campaign; result.message = "Loyalzoo place data request success."; } else { result.message = data.SelectToken("response").ToString(); } } else { result.success = false; result.message = "no response from Loyalzoo server."; } } catch (Exception ex) { result.success = false; result.message = "exception: " + ex.Message + ";"; } return(result); }
/// <summary> /// Controlla se l'utente ha abbastanza punti per ricervere un regalo /// </summary> /// <param name="kvpList">Elenco dei parametri per fare le chiamate</param> /// <returns>Restituisce una stringa in formato json</returns> protected bool checkCustomerPoints(FidelitySettingsPart setPart, FidelityCustomer customer, FidelityReward reward, FidelityCampaign campaign) { APIResult <FidelityCustomer> resCustomer = this.SendCustomerDetails(setPart, customer); if (!resCustomer.success) { throw new Exception("customer not fuond"); } APIResult <FidelityCampaign> resCampaign = this.SendCampaignData(setPart, campaign); if (!resCampaign.success) { throw new Exception("campaign " + campaign.Id + " not found"); } customer = resCustomer.data; campaign = resCampaign.data; if (!campaign.Catalog.ContainsKey(reward.Id)) { throw new Exception("campaign: " + campaign.Id + " not contaign reward: " + reward.Id); } if (!customer.PointsInCampaign.ContainsKey(campaign.Id)) { throw new Exception("customer: " + customer.Username + " not have points in campaign: " + campaign.Id); } if (customer.PointsInCampaign[campaign.Id] < campaign.Catalog[reward.Id]) { return(false); } return(true); }
public APIResult <bool> SendGiveReward(FidelitySettingsPart setPart, FidelityCustomer customer, FidelityReward reward, FidelityCampaign campaign) { APIResult <bool> result = new APIResult <bool>(); result.data = false; try { List <KeyValuePair <string, string> > kvpList = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("place_id", campaign.Id), new KeyValuePair <string, string>("session_id", setPart.AccountID), new KeyValuePair <string, string>("customer_id", customer.Id), new KeyValuePair <string, string>("reward_id", reward.Id), }; if (!checkCustomerPoints(setPart, customer, reward, campaign)) { result.data = false; result.message = "Il cliente " + customer.Username + " non ha abbastanza punti per il reward: " + reward.Id + " nella campagna: " + campaign.Id + "."; return(result); } string responseString = SendRequest(setPart, APIType.merchant, "giveReward", kvpList); if (!string.IsNullOrWhiteSpace(responseString)) { JObject data = JObject.Parse(responseString); result.success = data.Value <bool>("success"); if (result.success) { result.data = true; result.message = "Loyalzoo reward gived with success."; } else { result.message = data.SelectToken("response").ToString(); } } else { result.message = "no response from Loyalzoo server."; } } catch (Exception ex) { result.message = "exception: " + ex.Message + "."; } return(result); }
public APIResult <bool> SendAddPoints(FidelitySettingsPart setPart, FidelityCustomer customer, FidelityCampaign campaign, string points) { APIResult <bool> result = new APIResult <bool>(); result.success = false; result.data = false; try { List <KeyValuePair <string, string> > kvpList = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("place_id", campaign.Id), new KeyValuePair <string, string>("session_id", setPart.AccountID), new KeyValuePair <string, string>("customer_id", customer.Id), new KeyValuePair <string, string>("points", points), }; string responseString = SendRequest(setPart, APIType.merchant, "givePoints", kvpList); if (!string.IsNullOrWhiteSpace(responseString)) { JObject data = JObject.Parse(responseString); result.success = data.Value <bool>("success"); if (result.success) { result.data = true; result.message = "Loyalzoo points added with success."; } else { result.message = data.SelectToken("response").ToString(); } } else { result.message = "no response from Loyalzoo server."; } } catch (Exception ex) { result.message = "exception: " + ex.Message + "."; } return(result); }