Ejemplo n.º 1
0
        public static ApiClientOneVoucherRedeemResponse GetOneVoucher(ApiClientUser user, long sequenceNumber, string voucherPin, ApiClientAcquirer acquirer)
        {
            try
            {
                var accessToken  = "";
                var refreshToken = "";
                var token        = HttpContext.Current.Application["TokenSession"] as TokenSession;
                if (token != null)
                {
                    accessToken = token.accessToken;
                    if (Convert.ToDateTime(token.ExpDate) <= DateTime.Now)
                    {
                        var refreshTokenFlash = JukeBox.BLL.ExternalApi.Voucher.GetTokenAsync();
                        accessToken  = refreshTokenFlash.access_token;
                        refreshToken = refreshTokenFlash.refresh_token;
                        var date = DateTime.Now.AddMinutes(55);
                        HttpContext.Current.Application.Remove("TokenSession");
                        var tokenSession = new TokenSession
                        {
                            accessToken  = accessToken,
                            refreshToken = refreshToken,
                            ExpDate      = date
                        };
                        HttpContext.Current.Application["TokenSession"] = tokenSession;
                    }
                }
                else
                {
                    var tokenFlash = JukeBox.BLL.ExternalApi.Voucher.GetTokenAsync();
                    accessToken  = tokenFlash.access_token;
                    refreshToken = tokenFlash.refresh_token;
                    var date         = DateTime.Now.AddMinutes(55);
                    var tokenSession = new TokenSession
                    {
                        accessToken  = accessToken,
                        refreshToken = refreshToken,
                        ExpDate      = date
                    };
                    HttpContext.Current.Application["TokenSession"] = tokenSession;
                }

                var data = JukeBox.BLL.ExternalApi.Voucher.GetApiClientOneVoucher(new ApiClientOneVoucherRedeemFilter()
                {
                    user            = user,
                    sequenceNumber  = sequenceNumber,
                    voucherPin      = voucherPin,
                    acquirer        = acquirer,
                    amountRequested = 0,
                    currency        = "ZAR"
                }, accessToken);
                return(data);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 2
0
        private ApiResponse FlashVoucherRedeem(string voucherpin, long clientId)
        {
            var response = new ApiResponse
            {
                ResponseMessage = "Failed",
                ResponseType    = -1
            };
            string ClientID = clientId.ToString();
            long   UserID   = 1;

            string trackingId   = Guid.NewGuid().ToString();
            bool   voucherState = false;

            //User Class
            string authUserName = Convert.ToString(ConfigurationManager.AppSettings["AuthUserName"]);
            string authPassWord = Convert.ToString(ConfigurationManager.AppSettings["AuthPassWord"]);

            //Acquirer Class
            string id       = Convert.ToString(ConfigurationManager.AppSettings["Id"]);
            string password = Convert.ToString(ConfigurationManager.AppSettings["Password"]);

            //Device Class
            System.Web.HttpBrowserCapabilities browserInformation = new System.Web.HttpBrowserCapabilities
            {
            };

            string channelId       = Convert.ToString(ConfigurationManager.AppSettings["ChannelId"]);
            long   appType         = Convert.ToInt64(ConfigurationManager.AppSettings["AppType"]);
            string msisdn          = Convert.ToString(ConfigurationManager.AppSettings["Msisdn"]);
            string platform        = null; // (browserInformation.Platform);
            string platformVersion = null; // (browserInformation.Version);

            string accountNumber  = Convert.ToString(ConfigurationManager.AppSettings["AccountNumber"]);
            Random random         = new Random();
            long   sequenceNumber = Convert.ToInt64(DateTime.Now.ToString("yyyyMMddHHmmssf")) + random.Next(1, 99999);


            ApiClientUser User = new ApiClientUser
            {
                authUserName       = authUserName,
                authPassWord       = authPassWord,
                purseAccountNumber = accountNumber
            };

            ApiClientAcquirer Acquirer = new ApiClientAcquirer
            {
                id        = id,
                password  = password,
                reference = ClientID
            };

            try
            {
                var reference = "Flash - Voucher";
                if (string.IsNullOrEmpty(voucherpin))
                {
                    string errorMessage = "Please enter a valid voucher code.";
                    response.ResponseMessage = errorMessage;
                }

                else
                {
                    TrackVoucher(string.Format("Tracking Id: {2} - {1} Start redeeming Flash Pin: {0}", voucherpin, clientId, trackingId));
                    var flash          = GetOneVoucher(User, sequenceNumber, voucherpin, Acquirer);
                    var flashRandValue = Convert.ToDecimal(flash.amountAuthorised) / 100;
                    if (flash.actionCode == "0000") //Activated/Success
                    {
                        TrackVoucher($"Tracking Id: {trackingId} - Flash API Success response code: {flash.actionCode} for voucher pin: {voucherpin} and Client ID: {ClientID}");
                        var updateBalance = verifyVoucher(Convert.ToInt32(clientId), voucherpin, 1, 1, 1, DateTime.Now, Convert.ToInt64(flash.transactionReference), flashRandValue, false, reference);
                        if (updateBalance != null)
                        {
                            response.ResponseMessage = "Successfull";
                            response.ResponseType    = 1;
                        }
                        else
                        {
                            string errorMessage = "An error has occurred. Please try again.";
                            response.ResponseMessage = errorMessage;
                            TrackVoucher(string.Format("Tracking Id: {3} - {2} Error redeeming Flash Pin: {0}, Reason: {1}", voucherpin, "API returned failed response", clientId, trackingId));
                            var voucher = verifyVoucher(Convert.ToInt32(clientId), voucherpin, 1, 1, 2, DateTime.Now, Convert.ToInt64(flash.transactionReference), flashRandValue, false, reference);
                        }
                    }
                    else if (flash.actionCode == "1824")
                    {
                        string errorMessage = "Voucher has already been used.";
                        response.ResponseMessage = errorMessage;
                        TrackVoucher($"Tracking Id: {trackingId} - Flash API response code: {flash.actionCode} for voucher pin: {voucherpin} and Client ID: {ClientID}");
                    }
                    else
                    {
                        string errorMessage = "Invalid 1voucher code";
                        response.ResponseMessage = errorMessage;
                        TrackVoucher($"Tracking Id: {trackingId} - Flash API response code: {flash.actionCode} for voucher pin: {voucherpin} and Client ID: {ClientID}");
                        //  verifyVoucher(Convert.ToInt32(clientId), voucherpin, 1, 1, 2, DateTime.Now, Convert.ToInt64(flash.transactionReference), flashRandValue, false, reference);
                    }
                }
            }

            catch (Exception ex)
            {
                TrackVoucher(string.Format("Tracking Id: {0} - {2} Exception, Reason: {1}", trackingId, ex.Message, clientId));
                TrackVoucher(string.Format("Tracking Id: {1} - {2} End redeeming Flash Pin: {0}", voucherpin, trackingId, clientId));
            }

            return(response);
        }