//elimina dal dizionario data tutti i campi che sono gia presenti nelle propietà dal customer //inoltre aggiunge la lista dei punti acquisiti private void RemoveCustomerPropertyFromDataDictionary(FidelityCustomer customer) { Dictionary <string, string> data = customer.Data; if (data.ContainsKey("email")) { data.Remove("email"); } if (data.ContainsKey("id")) { customer.Id = data["id"]; data.Remove("id"); } if (data.ContainsKey("username")) { data.Remove("username"); } if (data.ContainsKey("password")) { data.Remove("password"); } if (data.ContainsKey("rewards")) { AddPointsInPlaceToCustomer(data["rewards"], customer); data.Remove("rewards"); } }
public virtual APIResult <FidelityCustomer> CreateFidelityAccount(FidelityUserPart fidelityPart, string username, string email, string campaignId) { if (fidelityPart != null && !String.IsNullOrWhiteSpace(username)) { FidelityCustomer customer = new FidelityCustomer(email, username, Membership.GeneratePassword(12, 4)); APIResult <FidelityCustomer> creationRequest = _sendService.SendCustomerRegistration(settingsPart, customer, campaignId); if (creationRequest.success) { fidelityPart.FidelityUsername = customer.Username; fidelityPart.FidelityPassword = Convert.ToBase64String(_encryptionService.Encode(Encoding.UTF8.GetBytes(customer.Password))); if (!string.IsNullOrWhiteSpace(customer.Id)) { fidelityPart.CustomerId = customer.Id; } } return(creationRequest); } else { return new APIResult <FidelityCustomer> { success = false, data = null, message = "The user is not configured to use " + GetProviderName() } }; }
/// <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); }
private void AddPointsCampaignToCustomer(JToken tokenCampaigns, FidelityCustomer customer) { if (tokenCampaigns.Children().Count() > 0) { foreach (JToken tokenCamp in tokenCampaigns.Children()) { customer.SetPointsCampaign(tokenCamp.Value <string>("id"), tokenCamp.Value <double>("balance")); } } }
//agginge al dizionario pointsInCampaign del customer i valori presenti nel json, //il nome del parametro è infelice, ma cosi è impostato nella response di loyalzoo. //Inoltre non vengono gestite place che invece di restituire un numero restituiscono //una lista di "non so che cosa" (vedi anche vecchio modulo) TODO private void AddPointsInPlaceToCustomer(string jsonRewards, FidelityCustomer customer) { JObject rew = JObject.Parse(jsonRewards); foreach (KeyValuePair <string, JToken> entry in rew) { string tokenVal = entry.Value.ToString(); double points; if (Double.TryParse(tokenVal, out points)) { customer.PointsInCampaign.Add(entry.Key, points); } } }
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); }
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); }
//elimina dal dizionario data tutti i campi che sono gia presenti nelle propietà dal customer //inoltre aggiunge la lista dei punti acquisiti private void RemoveCustomerPropertyFromDataDictionary(FidelityCustomer customer) { Dictionary <string, string> data = customer.Data; if (data.ContainsKey("email")) { data.Remove("email"); } if (data.ContainsKey("code")) { data.Remove("id"); } if (data.ContainsKey("customer_username")) { data.Remove("customer_username"); } //if (data.ContainsKey("rewards")) //{ // AddPointsInPlaceToCustomer(data["rewards"], customer); // data.Remove("rewards"); //} }
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); }
/// <summary> /// Ritorna l'il FidelityCustomer associato all'User autenticato su Orchard /// </summary> /// <returns>FidelityCustomer se esiste un utente autenticato, null altrimenti</returns> public virtual FidelityCustomer GetCustomerFromAuthenticatedUser() { var authenticatedUser = _authenticationService.GetAuthenticatedUser(); if (authenticatedUser != null) { FidelityUserPart fidelityPart = (FidelityUserPart)(((dynamic)authenticatedUser.ContentItem).FidelityUserPart); if (fidelityPart != null && !String.IsNullOrWhiteSpace(fidelityPart.FidelityUsername) && !String.IsNullOrWhiteSpace(fidelityPart.FidelityPassword) ) { string pass = Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(fidelityPart.FidelityPassword))); FidelityCustomer customer = new FidelityCustomer(authenticatedUser.Email, fidelityPart.FidelityUsername, pass); if (String.IsNullOrWhiteSpace(fidelityPart.CustomerId)) { fidelityPart.CustomerId = _sendService.SendCustomerDetails(settingsPart, customer).data.Id; } customer.Id = fidelityPart.CustomerId; return(customer); } } return(null); }
public APIResult <FidelityCustomer> SendCustomerRegistration(FidelitySettingsPart setPart, FidelityCustomer customer, string campaignId) { APIResult <FidelityCustomer> result = new APIResult <FidelityCustomer>(); result.data = null; try { List <KeyValuePair <string, string> > kvpList = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("customer_username", customer.Username), new KeyValuePair <string, string>("customer_password", customer.Password), new KeyValuePair <string, string>("first_name", customer.Username), new KeyValuePair <string, string>("email", customer.Email), new KeyValuePair <string, string>("campaign_id", campaignId), new KeyValuePair <string, string>("customer_action", "new"), new KeyValuePair <string, string>("card_number_generate", "10") }; string responseString = SendRequest(setPart, "record_customer", kvpList); if (!string.IsNullOrWhiteSpace(responseString)) { JObject data = JObject.Parse(responseString); result.success = data.Value <string>("status").Equals("success"); if (result.success) { customer.Id = data.SelectToken("customer").Value <string>("code"); result.data = customer; result.message = "registrazione effettuata con successo"; } 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 <FidelityCustomer> SendCustomerDetails(FidelitySettingsPart setPart, FidelityCustomer customer) { string responseString = string.Empty; APIResult <FidelityCustomer> result = new APIResult <FidelityCustomer>(); result.data = null; result.success = false; try { List <KeyValuePair <string, string> > kvpList = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("code", customer.Id), }; responseString = SendRequest(setPart, "customer_info", kvpList); if (!string.IsNullOrWhiteSpace(responseString)) { JObject data = JObject.Parse(responseString); result.success = data.Value <string>("status").Equals("success"); if (result.success) { customer.Data = this.DictionaryFromResponseToken(data.SelectToken("customer")); RemoveCustomerPropertyFromDataDictionary(customer); AddPointsCampaignToCustomer(data.SelectToken("campaigns"), customer); result.data = customer; result.message = "Simsol customer login success."; } else { result.message = data.SelectToken("errors").ToString(); } } else { result.message = "no response from Simsol server."; } } catch (Exception ex) { result.message = "Exception: " + ex.Message + " in Simsol Login."; } return(result); }
public APIResult <FidelityCustomer> SendCustomerDetails(FidelitySettingsPart setPart, FidelityCustomer customer) { return(loginCustomer(setPart, customer)); }
private APIResult <FidelityCustomer> loginCustomer(FidelitySettingsPart setPart, FidelityCustomer customer) { string responseString = string.Empty; APIResult <FidelityCustomer> result = new APIResult <FidelityCustomer>(); result.data = null; result.success = false; try { List <KeyValuePair <string, string> > kvpList = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("username", customer.Username), new KeyValuePair <string, string>("password", customer.Password), }; responseString = SendRequest(setPart, APIType.customer, "login", kvpList); if (!string.IsNullOrWhiteSpace(responseString)) { JObject data = JObject.Parse(responseString); result.success = data.Value <bool>("success"); if (result.success) { customer.Data = this.DictionaryFromResponseToken(data.SelectToken("response")); RemoveCustomerPropertyFromDataDictionary(customer); result.data = customer; result.message = "Loyalzoo customer login success."; } else { result.message = data.SelectToken("response").ToString(); } } else { result.message = "no response from Loyalzoo server."; } } catch (Exception ex) { result.message = "Exception: " + ex.Message + " in Loyalzoo Login."; } return(result); }
public APIResult <FidelityCustomer> SendCustomerRegistration(FidelitySettingsPart setPart, FidelityCustomer customer, string campaignId) //TODO campaignId non viene usato { APIResult <FidelityCustomer> result = new APIResult <FidelityCustomer>(); result.data = null; try { List <KeyValuePair <string, string> > kvpList = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("username", customer.Username), new KeyValuePair <string, string>("password", customer.Password), new KeyValuePair <string, string>("email", customer.Email), new KeyValuePair <string, string>("first_name", customer.Username)//TODO vedeere se è oggnligatorio inserire il first-name }; string responseString = SendRequest(setPart, APIType.customer, "create", kvpList); if (!string.IsNullOrWhiteSpace(responseString)) { JObject data = JObject.Parse(responseString); result.success = data.Value <bool>("success"); if (result.success) { customer.Data = this.DictionaryFromResponseToken(data.SelectToken("response")); RemoveCustomerPropertyFromDataDictionary(customer); result.data = customer; result.message = "Loyalzoo registration 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); }