コード例 #1
0
        private CResultCreate GetCustomerData(string customerSessionId)
        {
            try
            {
                ConfigEnv configData = GetConfigData();

                CDataCustomer customer = new CDataCustomer();
                customer.session_id = customerSessionId;

                ILoyalzooCustomer c = new Customer();
                CResultCreate     loyalzooResult = c.Me(configData, customer);

                return(loyalzooResult);
            }
            catch (Exception e)
            {
                CResultCreate exceptionData = new CResultCreate();
                exceptionData.success  = false;
                exceptionData.response = null;
                exceptionData.Errore   = new Errore {
                    success = false, response = e.Message
                };

                return(exceptionData);
            }
        }
コード例 #2
0
        public APIResult GiveReward(string rewardId)
        {
            try
            {
                APIResult result = new APIResult();

                APIResult customerIdRequest = GetCustomerSessionId();

                if (customerIdRequest.success)
                {
                    CResultCreate customerData = GetCustomerData((string)customerIdRequest.data);

                    if (customerData.success)
                    {
                        MerchantApiData merchantData = GetMerchantApiData();

                        if (merchantData.Success)
                        {
                            string customerId     = customerData.response.id.ToString();
                            int    customerPoints = customerData.response.rewards[merchantData.PlaceId];

                            ConfigEnv configData = GetConfigData();

                            MgiveReward rewardData = new MgiveReward();
                            rewardData.customer_id = customerData.response.id.ToString();
                            rewardData.place_id    = merchantData.PlaceId;
                            rewardData.session_id  = merchantData.MerchantId;
                            rewardData.reward_id   = rewardId;
                            rewardData.punteggio   = customerData.response.rewards[merchantData.PlaceId];

                            ILoyalzooMerchant m = new Merchant();
                            MResultGeneral    giveRewardResponse = m.giveReward(configData, rewardData);

                            if (giveRewardResponse.success)
                            {
                                result.success = true;
                                result.message = "";
                                result.data    = null;
                            }
                            else
                            {
                                result.success = false;
                                result.message = giveRewardResponse.Errore.response;
                                result.data    = null;
                            }
                        }
                        else
                        {
                            result.success = false;
                            result.message = merchantData.ErrorMessage;
                            result.data    = null;
                        }
                    }
                    else
                    {
                        result.success = false;
                        result.message = customerData.Errore.response;
                        result.data    = null;
                    }
                }
                else
                {
                    result.success = false;
                    result.message = customerIdRequest.message;
                    result.data    = null;
                }

                return(result);
            }
            catch (Exception e)
            {
                APIResult exceptionData = new APIResult();

                exceptionData.success = false;
                exceptionData.message = e.Message;
                exceptionData.data    = null;

                return(exceptionData);
            }
        }
コード例 #3
0
        public APIResult AddPointsFromAction(string actionId, string completionPercent)
        {
            try
            {
                APIResult result = new APIResult();

                APIResult customerIdRequest = GetCustomerSessionId();

                if (customerIdRequest.success)
                {
                    CResultCreate customerData = GetCustomerData((string)customerIdRequest.data);

                    if (customerData.success)
                    {
                        string customerId = customerData.response.id.ToString();

                        MerchantApiData merchantData = GetMerchantApiData();

                        if (merchantData.Success)
                        {
                            ConfigEnv configData = GetConfigData();

                            MgivePoint givePoints = new MgivePoint();
                            givePoints.customer_id = customerId;
                            givePoints.place_id    = merchantData.PlaceId;
                            givePoints.session_id  = merchantData.MerchantId;
                            givePoints.amount      = "0";
                            givePoints.actionid    = actionId;

                            ILoyalzooMerchant           m = new Merchant();
                            MResultGivePointsFromAction loyalzooResult = m.givePointsFromAction(configData, givePoints);

                            if (loyalzooResult.success)
                            {
                                result.success = true;
                                result.message = "";
                                result.data    = new { pointsAdded = loyalzooResult.response.points_given, customerTotalPoints = loyalzooResult.response.balance };
                            }
                            else
                            {
                                result.success = false;
                                result.message = loyalzooResult.Errore.response;
                                result.data    = null;
                            }
                        }
                        else
                        {
                            result.success = false;
                            result.message = merchantData.ErrorMessage;
                            result.data    = null;
                        }
                    }
                    else
                    {
                        result.success = false;
                        result.message = customerData.Errore.response;
                        result.data    = null;
                    }
                }
                else
                {
                    result.success = false;
                    result.message = customerIdRequest.message;
                    result.data    = null;
                }

                return(result);
            }
            catch (Exception e)
            {
                APIResult exceptionData = new APIResult();

                exceptionData.success = false;
                exceptionData.message = e.Message;
                exceptionData.data    = null;

                return(exceptionData);
            }
        }
コード例 #4
0
        public APIResult AddPoints(int numPoints)
        {
            try
            {
                APIResult result = new APIResult();

                APIResult customerIdRequest = GetCustomerSessionId();

                if (customerIdRequest.success)
                {
                    CResultCreate customerData = GetCustomerData((string)customerIdRequest.data);

                    if (customerData.success)
                    {
                        string customerId = customerData.response.id.ToString();

                        MerchantApiData merchantData = GetMerchantApiData();

                        if (merchantData.Success)
                        {
                            ConfigEnv configData = GetConfigData();

                            MgivePoint givePoints = new MgivePoint();
                            givePoints.customer_id = customerId;
                            givePoints.place_id    = merchantData.PlaceId;
                            givePoints.session_id  = merchantData.MerchantId;
                            givePoints.amount      = numPoints.ToString();

                            ILoyalzooMerchant m = new Merchant();
                            MResultGeneral    loyalzooResult = m.givePointsFromAmount(configData, givePoints);

                            if (loyalzooResult.success)
                            {
                                result.success = true;
                                result.message = "";
                                result.data    = null;
                            }
                            else
                            {
                                result.success = false;
                                result.message = loyalzooResult.Errore.response;
                                result.data    = null;
                            }
                        }
                        else
                        {
                            result.success = false;
                            result.message = merchantData.ErrorMessage;
                            result.data    = null;
                        }
                    }
                    else
                    {
                        result.success = false;
                        result.message = customerData.Errore.response;
                        result.data    = null;
                    }
                }
                else
                {
                    result.success = false;
                    result.message = customerIdRequest.message;
                    result.data    = null;
                }

                return(result);
            }
            catch (Exception e)
            {
                APIResult exceptionData = new APIResult();

                exceptionData.success = false;
                exceptionData.message = e.Message;
                exceptionData.data    = null;

                return(exceptionData);
            }
        }
コード例 #5
0
        public APIResult GetCustomerDetails()
        {
            try
            {
                APIResult result = new APIResult();

                APIResult customerIdRequest = GetCustomerSessionId();

                if (customerIdRequest.success)
                {
                    CResultCreate customerData = GetCustomerData((string)customerIdRequest.data);

                    if (customerData.success)
                    {
                        Dictionary <string, int> placeList = new Dictionary <string, int>();

                        if (customerData.response.rewards != null)
                        {
                            foreach (KeyValuePair <string, int> item in customerData.response.rewards)
                            {
                                MResultPlace placeRequest = GetPlaceData(item.Key);
                                if (placeRequest.success)
                                {
                                    placeList.Add(placeRequest.response.name, item.Value);
                                }
                            }
                        }

                        customerData.response.rewards = placeList;

                        result.success = true;
                        result.message = "";
                        result.data    = customerData.response;
                    }
                    else
                    {
                        result.success = false;
                        result.message = customerData.Errore.response;
                        result.data    = null;
                    }
                }
                else
                {
                    result.success = false;
                    result.message = customerIdRequest.message;
                    result.data    = null;
                }

                return(result);
            }
            catch (Exception e)
            {
                APIResult exceptionData = new APIResult();

                exceptionData.success = false;
                exceptionData.message = e.Message;
                exceptionData.data    = null;

                return(exceptionData);
            }
        }
コード例 #6
0
        public APIResult CreateLoyalzooAccount(LoyalzooUserPart loyalzooPart, string username, string email)
        {
            try
            {
                APIResult result = new APIResult();

                if (loyalzooPart != null && !String.IsNullOrWhiteSpace(username) && !String.IsNullOrWhiteSpace(email))
                {
                    if (String.IsNullOrWhiteSpace(loyalzooPart.LoyalzooUsername) && String.IsNullOrWhiteSpace(loyalzooPart.LoyalzooPassword) && String.IsNullOrWhiteSpace(loyalzooPart.CustomerSessionId))
                    {
                        ConfigEnv configData = GetConfigData();

                        CDataCustomer customerData = new CDataCustomer();
                        customerData.first_name = username;
                        customerData.email      = email;
                        customerData.username   = username;
                        customerData.password   = Membership.GeneratePassword(12, 4);

                        ILoyalzooCustomer customer        = new Customer();
                        CResultCreate     creationRequest = customer.Create(configData, customerData);

                        if (creationRequest.success)
                        {
                            loyalzooPart.LoyalzooUsername  = creationRequest.response.username;
                            loyalzooPart.CustomerSessionId = creationRequest.response.session_id;
                            loyalzooPart.LoyalzooPassword  = Convert.ToBase64String(_encryptionService.Encode(Encoding.UTF8.GetBytes(customerData.password)));

                            result.success = true;
                            result.data    = creationRequest.response;
                            result.message = "";
                        }
                        else
                        {
                            result.success = false;
                            result.message = creationRequest.Errore.response;
                            result.data    = null;
                        }
                    }
                    else
                    {
                        return new APIResult {
                                   success = false, data = null, message = "There is already some Loyalzoo data associated to the user. If you want to register a new account, delete the existing Loyalzoo data and then call this method again (any previous data associated to the user will be lost)."
                        }
                    };
                }
                else
                {
                    return new APIResult {
                               success = false, data = null, message = "The user is not configured to use Loyalzoo."
                    }
                };

                return(result);
            }
            catch (Exception e)
            {
                APIResult exceptionData = new APIResult();

                exceptionData.success = false;
                exceptionData.message = e.Message;
                exceptionData.data    = null;

                return(exceptionData);
            }
        }