Beispiel #1
0
        /// <summary>
        /// Reload UserWallet via Credit Card
        /// </summary>
        /// <param name="context">DBContext of Model to be used</param>
        /// <param name="wallet">UserWallet to be loaded</param>
        /// <param name="transaction">CreditCardReloadTransaction filled up with the ff properties filled up: Amount, Date</param>
        /// <param name="cardInfo">Credit Card information</param>
        /// <returns></returns>
        public RespCreateWalletLoad ReloadWalletViaCreditCard(IPTV2Entities context, UserWallet wallet, CreditCardReloadTransaction transaction, CreditCardInfo cardInfo)
        {
            RespCreateWalletLoad result = null;

            InitializeServiceClient();

            try
            {
                // validate credit card information
                cardInfo.Validate();
                if (!cardInfo.IsValid)
                {
                    throw new GomsInvalidCreditCardException();
                }

                // validate user
                GomsException validationResult = UserValidation(context, wallet.UserId);
                if (!(validationResult is GomsSuccess))
                {
                    throw validationResult;
                }
                var user = context.Users.Find(wallet.UserId);

                // validate the wallet
                validationResult = WalletValidation(context, user, wallet.WalletId);
                if (!(validationResult is GomsSuccess))
                {
                    throw validationResult;
                }

                // validate transaction
                if (transaction == null)
                {
                    throw new GomsInvalidTransactionException();
                }
                else
                {
                    if ((transaction.Amount <= 0) || (transaction.Date == null))
                        throw new GomsInvalidTransactionException();
                }

                // prepare request
                // set transaction wallet
                user.Transactions.Add(transaction);
                transaction.UserWallet = wallet;
                transaction.Currency = wallet.Currency;

                var req = new ReqCreateWalletLoad
                {
                    UID = ServiceUserId,
                    PWD = ServicePassword,
                    Email = user.EMail,
                    CustomerId = (int)user.GomsCustomerId,
                    ServiceId = (int)user.GomsServiceId,
                    SubsidiaryId = (int)user.GomsSubsidiaryId,
                    WalletId = (int)transaction.UserWallet.GomsWalletId,
                    OrderType = 1,
                    // PhoenixId = transaction.TransactionId,
                    PhoenixId = (int)(DateTime.Now.Ticks - int.MaxValue),
                    LoadAmountLocalCurrency = (double)transaction.Amount,
                    //CurrencyId = (int)context.Currencies.Find(user.Country.CurrencyCode).GomsId
                    CCName = cardInfo.Name,
                    CCNumber = cardInfo.Number,
                    CCSecurityCode = cardInfo.CardSecurityCode,
                    CCExpiry = cardInfo.ExpiryDate,
                    CCPostalCode = cardInfo.PostalCode,
                    CCStreet = cardInfo.StreetAddress
                };

                var paymentMethod = context.GomsPaymentMethods.FirstOrDefault(p => (p.GomsSubsidiaryId == user.GomsSubsidiaryId) && (p.Name == cardInfo.CardTypeString));

                if (paymentMethod == null)
                {
                    throw new GomsCreditCardTypeInvalidException();
                }

                req.PaymentMethod = paymentMethod.PaymentMethodId;

                var log = new GomsLogs() { email = user.EMail, phoenixid = req.PhoenixId };
                try
                {
                    var startTime = DateTime.Now;
                    result = _serviceClient.CreateWalletLoad(req);
                    var endTime = DateTime.Now;
                    var timeDifference = endTime - startTime;

                    if (result.IsSuccess)
                    {
                        transaction.Reference = result.TransactionId.ToString();
                        transaction.GomsTransactionId = result.TransactionId;
                        transaction.GomsTransactionDate = DateTime.Now;
                        transaction.UserWallet.Balance += transaction.Amount;
                        transaction.UserWallet.LastUpdated = DateTime.Now;
                        context.SaveChanges();
                        log.gomstransactionid = result.TransactionId;
                        log.message = String.Format("{0} - {1}", result.IsSuccess, result.StatusMessage);
                        log.transactionid = transaction.TransactionId;
                        log.transactiondate = transaction.GomsTransactionDate.Value.ToString("yyyy-MM-dd hh:mm:ss");
                    }
                }
                catch (Exception e)
                {
                    log.message = e.Message;
                    LogToGigya("glogs", log);
                    throw new GomsServiceCallException(e.Message);
                }
                finally
                {
                    LogToGigya("glogs", log);
                }
            }
            catch (GomsException e)
            {
                result = new RespCreateWalletLoad { IsSuccess = false, StatusCode = e.StatusCode, StatusMessage = e.StatusMessage };
            }
            return (result);
        }
Beispiel #2
0
        public RespValidateCreditCard ValidateCreditCard(IPTV2Entities context, System.Guid userId, CreditCardPaymentTransaction transaction, CreditCardInfo cardInfo, int FreeTrialConvertedDays)
        {
            RespValidateCreditCard result = null;

            InitializeServiceClient();

            try
            {
                // validate credit card information
                cardInfo.Validate();
                if (!cardInfo.IsValid)
                {
                    throw new GomsInvalidCreditCardException();
                }

                // Validate User
                GomsException validationResult = UserValidation(context, userId);
                if (!(validationResult is GomsSuccess))
                {
                    throw validationResult;
                }
                var user = context.Users.Find(userId);

                if (transaction == null)
                {
                    throw new GomsInvalidTransactionException();
                }
                else
                {
                    // check purchase items
                    if ((transaction.Purchase == null) || (transaction.Purchase.PurchaseItems.Count() <= 0))
                    {
                        throw new GomsInvalidTransactionException();
                    }
                }

                var paymentMethod = context.GomsPaymentMethods.FirstOrDefault(p => (p.GomsSubsidiaryId == user.GomsSubsidiaryId) && (p.Name == cardInfo.CardTypeString));
                if (paymentMethod == null)
                {
                    throw new GomsCreditCardTypeInvalidException();
                }

                var req = new ReqValidateCreditCard
                {
                    UID = ServiceUserId,
                    PWD = ServicePassword,
                    Email = user.EMail,
                    CustomerId = (int)user.GomsCustomerId,
                    ServiceId = (int)user.GomsServiceId,
                    SubsidiaryId = (int)user.GomsSubsidiaryId,
                    OrderType = 2,
                    PhoenixId = (int)(DateTime.Now.Ticks - int.MaxValue),
                    CurrencyId = (int)context.Currencies.Find(user.Country.CurrencyCode).GomsId,
                    CCName = cardInfo.Name,
                    CCNumber = cardInfo.Number,
                    CCSecurityCode = cardInfo.CardSecurityCode,
                    CCExpiry = cardInfo.ExpiryDate,
                    CCPostalCode = cardInfo.PostalCode,
                    CCStreet = cardInfo.StreetAddress,
                    PaymentMethod = paymentMethod.PaymentMethodId,
                    CCType = GetGomsCreditCardType(cardInfo.CardType),
                };

                // build order items

                OrderItem[] oi = new OrderItem[transaction.Purchase.PurchaseItems.Count()];
                int i = 0;
                foreach (var item in transaction.Purchase.PurchaseItems)
                {
                    // look for user's entitlment of purchased product
                    Entitlement userEntitlement = Entitlement.GetUserProductEntitlement(context, userId, item.ProductId);
                    DateTime startDate = DateTime.Now;
                    if (userEntitlement != null)
                        startDate = userEntitlement.EndDate > DateTime.Now ? userEntitlement.EndDate : DateTime.Now;
                    var newEndDate = getEntitlementEndDate(item.SubscriptionProduct.Duration, item.SubscriptionProduct.DurationType, startDate);

                    /**** EARLY BIRD ****/
                    if (FreeTrialConvertedDays > 0)
                        newEndDate = newEndDate.AddDays(FreeTrialConvertedDays);

                    oi[i] = new OrderItem
                    {
                        ItemId = (int)item.SubscriptionProduct.GomsProductId,
                        Quantity = (int)item.SubscriptionProduct.GomsProductQuantity,
                        AmountLocalCurrency = (double)item.Price,
                        EndDate = newEndDate.ToString("MM/dd/yyyy"),
                        StartDate = startDate.ToString("MM/dd/yyyy"),
                    };
                    if (item.RecipientUserId != userId)
                    {
                        req.OrderType = 3;
                        User recipient = context.Users.Find(item.RecipientUserId);
                        if (recipient == null)
                        {
                            throw new GomsInvalidRecipientException();
                        }
                        if (!recipient.IsGomsRegistered)
                        {
                            //var registerResult = RegisterUser(context, item.RecipientUserId);
                            var registerResult = RegisterUser2(context, item.RecipientUserId);
                            if (!registerResult.IsSuccess)
                            {
                                throw new GomsRegisterUserException(registerResult.StatusMessage);
                            }
                        }
                        req.Recipient = (int)recipient.GomsCustomerId;
                        req.RecipientServiceId = (int)recipient.GomsServiceId;
                    }
                    i++;
                }
                req.OrderItems = oi;
                var log = new GomsLogs() { email = user.EMail, phoenixid = req.PhoenixId };
                try
                {


                    // _serviceClient.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(5);
                    var startTime = DateTime.Now;
                    result = _serviceClient.ValidateCreditCard(req);
                    var endTime = DateTime.Now;
                    var timeDifference = endTime - startTime;

                    if (result.IsSuccess)
                    {
                        transaction.Reference += "-" + result.TransactionId.ToString();
                        transaction.GomsTransactionId = result.TransactionId;
                        transaction.GomsTransactionDate = DateTime.Now;
                        user.Transactions.Add(transaction);
                        log.transactionid = transaction.TransactionId;
                        log.transactiondate = transaction.GomsTransactionDate.Value.ToString("yyyy-MM-dd hh:mm:ss");
                    }
                    else
                    {
                        log.transactionid = 0;
                        log.transactiondate = String.Empty;
                        //log.message = String.Format("{0} - {1}", result.IsSuccess, result.StatusMessage);
                    }

                    log.message = String.Format("{0} - {1}", result.IsSuccess, result.StatusMessage);
                    log.statuscode = result.StatusCode;
                    log.statusmessage = result.StatusMessage;
                    log.issuccess = result.IsSuccess;
                    log.gomstransactionid = result.TransactionId;
                }
                catch (Exception e)
                {
                    log.message = e.Message;
                    LogToGigya("glogs", log);
                    throw new GomsServiceCallException(e.Message);

                }
                finally
                {
                    LogToGigya("glogs", log);
                }
            }
            catch (GomsException e)
            {
                result = new RespValidateCreditCard { IsSuccess = false, StatusCode = e.StatusCode, StatusMessage = e.StatusMessage };
            }

            return (result);
        }
Beispiel #3
0
        public RespResendTVEActivationCode ResendTVEActivationCode(string TFCtvEmailAddress, string MacAddressOrSmartCard, string AccountNumber, string LastName)
        {

            RespResendTVEActivationCode result = null;

            InitializeServiceClient();

            try
            {

                var PhoenixId = (int)(DateTime.Now.Ticks - int.MaxValue);
                var req = new ReqResendTVEActivationCode
                {
                    UID = ServiceUserId,
                    PWD = ServicePassword,
                    Email = TFCtvEmailAddress,
                    MacAddressOrSmartCard = MacAddressOrSmartCard,
                    AccountNumber = AccountNumber,
                    LastName = LastName
                };
                var log = new GomsLogs() { email = TFCtvEmailAddress, phoenixid = PhoenixId };
                try
                {
                    // _serviceClient.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(5);
                    var startTime = DateTime.Now;
                    result = _serviceClient.ResendTVEActivationCode(req);
                    var endTime = DateTime.Now;
                    var timeDifference = endTime - startTime;

                    if (result.IsSuccess)
                    {
                        var registDt = DateTime.Now;

                        log.transactionid = PhoenixId;
                        log.transactiondate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                    }
                    else
                    {
                        log.transactionid = 0;
                        log.transactiondate = String.Empty;
                    }

                    log.message = String.Format("{0} - {1}", result.IsSuccess, result.StatusMessage);
                    log.statuscode = result.StatusCode;
                    log.statusmessage = result.StatusMessage;
                    log.issuccess = result.IsSuccess;
                    log.gomstransactionid = PhoenixId;
                }
                catch (Exception e)
                {
                    log.message = e.Message;
                    LogToGigya("glogs", log);
                    throw new GomsServiceCallException(e.Message);

                }
                finally
                {
                    LogToGigya("glogs", log);
                }
            }
            catch (GomsException e)
            {
                result = new RespResendTVEActivationCode { IsSuccess = false, StatusCode = e.StatusCode, StatusMessage = e.StatusMessage };
            }

            return (result);

        }
Beispiel #4
0
        //private Entitlement getUserProductEntitlement(IPTV2Entities context, System.Guid userId, int productId)
        //{
        //    var user = context.Users.Find(userId);
        //    if (user == null)
        //    {
        //        throw new Exception(String.Format("Invalid user ID {0}", userId));
        //    }

        //    var product = context.Products.Find(productId);
        //    if (product == null)
        //    {
        //        throw new Exception(String.Format("Invalid product ID {0}", productId));
        //    }

        //    // look for user's entitlement of purchased product
        //    Entitlement userEntitlement = null;
        //    if (product is PackageSubscriptionProduct)
        //    {
        //        var pProduct = (PackageSubscriptionProduct)product;
        //        foreach (var p in pProduct.Packages)
        //        {
        //            userEntitlement = user.PackageEntitlements.FirstOrDefault(pp => pp.PackageId == p.PackageId);
        //        }
        //    }
        //    else if (product is ShowSubscriptionProduct)
        //    {
        //        var sProduct = (ShowSubscriptionProduct)product;
        //        foreach (var s in sProduct.Categories)
        //        {
        //            userEntitlement = user.ShowEntitlements.FirstOrDefault(ss => ss.CategoryId == s.CategoryId);
        //        }

        //    }
        //    else if (product is EpisodeSubscriptionProduct)
        //    {
        //        var eProduct = (EpisodeSubscriptionProduct)product;
        //        foreach (var e in eProduct.Episodes)
        //        {
        //            userEntitlement = user.EpisodeEntitlements.FirstOrDefault(ee => ee.EpisodeId == e.EpisodeId);
        //        }

        //    }
        //    else
        //    {
        //        throw new Exception(String.Format("Invalid product type for product Id {0}-{1}.", product.ProductId, product.Name));
        //    }

        //    return (userEntitlement);
        //}

        private void LogToGigya(string type, GomsLogs data)
        {
            try
            {
                string method = "gcs.setObjectData";
                LogModel model = new LogModel() { type = type, data = data };
                string obj = JsonConvert.SerializeObject(model);
                GSRequest req = new GSRequest(GSapikey, GSsecretkey, method, new GSObject(obj), true);
                GSResponse resp = req.Send();
            }
            catch (Exception) { }
        }
Beispiel #5
0
        public RespClaimTVE ClaimTVEverywhere(IPTV2Entities context, Guid userId, TfcEverywhereTransaction transaction, string MacAddressOrSmartCard, string AccountNumber, string ActivationCode)
        {
            RespClaimTVE result = null;

            InitializeServiceClient();

            try
            {

                // Validate User
                GomsException validationResult = UserValidation(context, userId);
                if (!(validationResult is GomsSuccess))
                {
                    throw validationResult;
                }
                var user = context.Users.Find(userId);

                if (transaction == null)
                {
                    throw new GomsInvalidTransactionException();
                }
                else
                {
                    //if ((transaction.GomsTFCEverywhereServiceId == null))
                    //{
                    //    throw new GomsInvalidTransactionException();
                    //}
                }
                var PhoenixId = (int)(DateTime.Now.Ticks - int.MaxValue);
                var req = new ReqClaimTVE
                {
                    UID = ServiceUserId,
                    PWD = ServicePassword,
                    Email = user.EMail,
                    CustomerId = (int)user.GomsCustomerId,
                    TFCTVCustomerId = (int)user.GomsCustomerId,
                    TFCTVServiceId = (int)user.GomsServiceId,
                    MacAddressOrSmartCard = MacAddressOrSmartCard,
                    AccountNumber = AccountNumber,
                    ActivationCode = ActivationCode
                };
                var log = new GomsLogs() { email = user.EMail, phoenixid = PhoenixId };
                try
                {
                    // _serviceClient.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(5);
                    var startTime = DateTime.Now;
                    result = _serviceClient.ClaimTVE(req);
                    var endTime = DateTime.Now;
                    var timeDifference = endTime - startTime;

                    if (result.IsSuccess)
                    {
                        var registDt = DateTime.Now;
                        transaction.Reference += "-" + result.GomsTransactionId.ToString();
                        transaction.GomsTransactionId = result.GomsTransactionId;
                        transaction.GomsTransactionDate = registDt;
                        transaction.GomsTFCEverywhereSubscriptionId = result.TFCTVSubId.ToString();
                        transaction.GomsTFCEverywhereServiceId = result.TFCServiceId.ToString();
                        transaction.GomsTFCEverywhereStartDate = registDt;
                        transaction.GomsTFCEverywhereEndDate = Convert.ToDateTime(result.ExpiryDate);
                        transaction.GomsRemarks = null;
                        //user.Transactions.Add(transaction);
                        //context.SaveChanges();

                        log.transactionid = transaction.TransactionId;
                        log.transactiondate = transaction.GomsTransactionDate.Value.ToString("yyyy-MM-dd hh:mm:ss");
                    }
                    else
                    {
                        log.transactionid = 0;
                        log.transactiondate = String.Empty;
                    }

                    log.message = String.Format("{0} - {1}", result.IsSuccess, result.StatusMessage);
                    log.statuscode = result.StatusCode;
                    log.statusmessage = result.StatusMessage;
                    log.issuccess = result.IsSuccess;
                    log.gomstransactionid = result.GomsTransactionId;
                }
                catch (Exception e)
                {
                    log.message = e.Message;
                    LogToGigya("glogs", log);
                    throw new GomsServiceCallException(e.Message);

                }
                finally
                {
                    LogToGigya("glogs", log);
                }
            }
            catch (GomsException e)
            {
                result = new RespClaimTVE { IsSuccess = false, StatusCode = e.StatusCode, StatusMessage = e.StatusMessage };
            }

            return (result);
        }