コード例 #1
0
        public void Purchase(User user, ProductNames productName, string payerId)
        {
            var userData = _repository.SingleAttached(u => u.Id == user.Id);
            var product = _productService.GetProductByName(productName);

            var data = product.GetProductExecutionData();
            userData.MembershipType = data.Membership;
            userData.PaypalPayerId = payerId;
            var date = (DateTime.Now > userData.Expires) ? DateTime.Now : userData.Expires;
            switch((TimeFrameType)data.TimeFrame) {
                case TimeFrameType.Year:
                    userData.Expires = date.AddYears(data.Value);
                    break;
                case TimeFrameType.Month:
                    userData.Expires = date.AddMonths(data.Value);
                    break;
                case TimeFrameType.Day:
                    userData.Expires = date.AddDays(data.Value);
                    break;
                case TimeFrameType.Hour:
                    userData.Expires = date.AddHours(data.Value);
                    break;
            }
            _repository.FullUpdate(userData);
            _repository.Save();
            _notificationService.Purchase(user, product);
        }
コード例 #2
0
 public string Purchase(User user, Product product) {
     try {
         Mailer.Mailer.SendMail(_adminMailAddress, String.Format("[PURCHASE] for {0}. ({1}) ", user.UserName, product.Name), PurchaseMade, _mailTemplatesFolder, user);
         return Mailer.Mailer.SendMail(user.Email, String.Format("Katusha says: {0} enjoy your membership. ({1}) ", user.UserName, product.Name), PurchaseMade, _mailTemplatesFolder, user);
     } catch (Exception ex) {
         return ex.Message;
     }
 }
コード例 #3
0
 public string SetExpressCheckout(User user, Product product, string referrer = "", int quantity = 1, string billingAgreementText = "")
 {
     var request = new SetExpressCheckoutRequestType();
     PopulateSetExpressCheckoutRequestObject(request, user, product, referrer, quantity, billingAgreementText);
     var wrapper = new SetExpressCheckoutReq {SetExpressCheckoutRequest = request};
     var setEcResponse = _payPalApiService.SetExpressCheckout(wrapper, GetApiUserName());
     return setEcResponse.Token;
 }
コード例 #4
0
 public string UserRegistered(User user)
 {
     try {
         if (user.Email.ToLowerInvariant() == "*****@*****.**" || user.Email.ToLowerInvariant() == "*****@*****.**") return "";
         return Mailer.Mailer.SendMail(user.Email, "Katusha says:Welcome! You need one more step to open a new world!", MailConfirm, _mailTemplatesFolder, user);
     } catch (Exception ex) {
         return ex.Message;
     }
 }
コード例 #5
0
 public void SendMessage(User user, Conversation message, bool force = false)
 {
     if(!force)
         if (user.Gender == (byte)Sex.Male)
             if (user.Expires < DateTime.Now)
                 throw new KatushaNeedsPaymentException(user, ProductNames.MonthlyKatusha);
     message.Message = message.Message.Replace("\r\n", "<br />\r\n");
     var dbMessage = Mapper.Map<Domain.Entities.Conversation>(message);
     _conversationRepository.Add(dbMessage);
     message.Guid = dbMessage.Guid;
     var ravenMessage = Mapper.Map<Conversation>(dbMessage);
     ravenMessage.FromGuid = message.FromGuid;
     ravenMessage.FromName = message.FromName;
     ravenMessage.FromPhotoGuid = message.FromPhotoGuid;
     ravenMessage.ToGuid = message.ToGuid;
     ravenMessage.ToName = message.ToName;
     ravenMessage.ToPhotoGuid = message.ToPhotoGuid;
     _conversationRepositoryRaven.Add(ravenMessage);
     _notificationService.MessageSent(ravenMessage);
 }
コード例 #6
0
 public User CreateUser(string userName, string password, string email, object passwordQuestion, object passwordAnswer, bool isApproved, object providerUserKey, out KatushaMembershipCreateStatus status)
 {
     var existingUser = GetUser(userName);
     if (existingUser != null) { 
         status = KatushaMembershipCreateStatus.DuplicateUserName;
         return null;
     }
     //TODO: Uncomment when you want unique emails.
     //existingUser = _repository.Single(p => p.Email == email);
     //if (existingUser != null)
     //{
     //    status = KatushaMembershipCreateStatus.DuplicateEmail;
     //    return null;
     //}
     var user = new User {Email = email, Password = password, UserName = userName, Expires = DateTime.Now.AddDays(15.0), EmailValidated = isApproved, UserRole = 1};
     _repository.Add(user);
     _repository.Save();
     _notificationService.UserRegistered(user);
     status = KatushaMembershipCreateStatus.Success;
     return user;
 }
コード例 #7
0
        public string ReadMessage(User user, long profileId, Guid messageGuid, bool force = false)
        {
            if (user.Gender == (byte)Sex.Male)
                if (user.Expires < DateTime.Now)
                    throw new KatushaNeedsPaymentException(user, ProductNames.MonthlyKatusha);


            var readTime = DateTime.Now;
            var ravenMessage = _conversationRepositoryRaven.SingleAttached(p => p.Guid == messageGuid && p.ToId == profileId);
            if (ravenMessage == null) return "";
            ravenMessage.ReadDate = readTime;
            _conversationRepositoryRaven.FullUpdate(ravenMessage);

            var message = _conversationRepository.SingleAttached(p => p.Guid == messageGuid && p.ToId == profileId);
            if (message == null) return "";
            message.ReadDate = readTime;
            _conversationRepository.FullUpdate(message);

            _notificationService.MessageRead(ravenMessage);
            return message.Message;
        }
コード例 #8
0
 public string SiteDeployed(User user)
 {
     return Mailer.Mailer.SendMail(user.Email, "Katusha says: Site deployed @" + DateTime.Now, "@model MS.Katusha.Domain.Entities.User\r\n<h1>@Model.UserName</h1>", _mailTemplatesFolder, user);
 }
コード例 #9
0
 public KatushaNotAllowedException(Profile profile, User user, string message)
     : base("NotAllowed", message, null)
 {
     Profile = profile;
     User = user;
 }
コード例 #10
0
        private void PopulateSetExpressCheckoutRequestObject(SetExpressCheckoutRequestType request, User user, Product product, string referrer,  int quantity, string billingAgreementText = "")
        {
            const string zero = "0.00";
            var orderTotal = 0.0;
            var itemTotal = 0.0;

            // Each payment can include requestDetails about multiple items
            // This example shows just one payment item
            if (quantity < 1) throw new Exception("Insufficient quantity");
            var itemDetails = new PaymentDetailsItemType {
                Name = product.Name,
                Amount = new BasicAmountType(MSKatushaCurrencyCode, product.Amount), 
                Quantity = quantity, 
                //ItemCategory = ItemCategoryType.PHYSICAL,
                Tax = new BasicAmountType(MSKatushaCurrencyCode, product.Tax), 
                Description = product.Description,
            };
            itemTotal += (Double.Parse(itemDetails.Amount.value) * quantity);

            orderTotal += Double.Parse(itemDetails.Tax.value);
            orderTotal += itemTotal;

            var paymentDetails = new PaymentDetailsType {
                ShippingTotal = new BasicAmountType(MSKatushaCurrencyCode, zero), 
                OrderDescription = MSKatushaorderDescription, 
                PaymentAction = PaymentActionCodeType.SALE,
                ItemTotal = new BasicAmountType(MSKatushaCurrencyCode, itemTotal.ToString(CultureInfo.InvariantCulture)),
                Custom = product.FriendlyName + "|" +(referrer ?? ""),
            };
            orderTotal += Double.Parse(paymentDetails.ShippingTotal.value);
            paymentDetails.OrderTotal = new BasicAmountType(MSKatushaCurrencyCode, orderTotal.ToString(CultureInfo.InvariantCulture));
            paymentDetails.PaymentDetailsItem.Add(itemDetails);


            var ecDetails = new SetExpressCheckoutRequestDetailsType {
                ReturnURL = _settings.ReturnUrl, 
                CancelURL = _settings.CancelUrl, 
                BuyerEmail = user.Email, 
                AddressOverride = "0", 
                NoShipping = "1", 
                SolutionType = SolutionTypeType.SOLE, 
                BuyerDetails = new BuyerDetailsType {BuyerId = user.Guid.ToString(), BuyerRegistrationDate = user.CreationDate.ToString("s"), BuyerUserName = user.UserName},
                cppHeaderImage = MSKatushaImageUrl,
                BrandName = MSKatushaBrandName
                //PageStyle = pageStyle.Value,
                //cppHeaderBorderColor = cppheaderbordercolor.Value,
                //cppHeaderBackColor = cppheaderbackcolor.Value,
                //cppPayflowColor = cpppayflowcolor.Value,
            };
            ecDetails.PaymentDetails.Add(paymentDetails);

            if (!String.IsNullOrWhiteSpace(billingAgreementText)) {
                var baType = new BillingAgreementDetailsType(BillingCodeType.MERCHANTINITIATEDBILLINGSINGLEAGREEMENT) { BillingAgreementDescription = billingAgreementText };
                ecDetails.BillingAgreementDetails.Add(baType);
            }
            request.SetExpressCheckoutRequestDetails = ecDetails;

            /*
                        //if (insuranceTotal.Value != "" && !double.Parse(insuranceTotal.Value).Equals(0.0)) {
                        //    paymentDetails.InsuranceTotal = new BasicAmountType(MSKatushaCurrencyCode, zero);
                        //    paymentDetails.InsuranceOptionOffered = "true";
                        //    orderTotal += Double.Parse(insuranceTotal.Value);
                        //}
                        //if (handlingTotal.Value != "") {
                        //    paymentDetails.HandlingTotal = new BasicAmountType(MSKatushaCurrencyCode, handlingTotal.Value);
                        //    orderTotal += Double.Parse(handlingTotal.Value);
                        //}
                        //if (taxTotal.Value != "") {
                        //    paymentDetails.TaxTotal = new BasicAmountType(MSKatushaCurrencyCode, taxTotal.Value);
                        //    orderTotal += Double.Parse(taxTotal.Value);
                        //}
                        //if (shippingName.Value != "" && shippingStreet1.Value != ""
                        //    && shippingCity.Value != "" && shippingState.Value != ""
                        //    && shippingCountry.Value != "" && shippingPostalCode.Value != "") {
                        //    AddressType shipAddress = new AddressType();
                        //    shipAddress.Name = shippingName.Value;
                        //    shipAddress.Street1 = shippingStreet1.Value;
                        //    shipAddress.Street2 = shippingStreet2.Value;
                        //    shipAddress.CityName = shippingCity.Value;
                        //    shipAddress.StateOrProvince = shippingState.Value;
                        //    shipAddress.Country = (CountryCodeType)
                        //        Enum.Parse(typeof(CountryCodeType), shippingCountry.Value);
                        //    shipAddress.PostalCode = shippingPostalCode.Value;
                        //    ecDetails.PaymentDetails[0].ShipToAddress = shipAddress;
                        //}
             * */
        }
コード例 #11
0
 public CheckoutPaymentResult DoExpressCheckoutPayment(User user, string token, string payerId)
 {
     var getEcResponse = _GetExpressCheckoutDetails(token);
     CheckoutStatus status;
     if (!Enum.TryParse(getEcResponse.GetExpressCheckoutDetailsResponseDetails.CheckoutStatus, true, out status))
         return new CheckoutPaymentResult {Errors = new List<string> {"NOCHECKOUTSTATUS"}};
     if (status == CheckoutStatus.PaymentActionNotInitiated) {
         user.PaypalPayerId = payerId;
         var request = new DoExpressCheckoutPaymentRequestType();
         var requestDetails = new DoExpressCheckoutPaymentRequestDetailsType {Token = token, PayerID = payerId, PaymentAction = PaymentActionCodeType.SALE};
         request.DoExpressCheckoutPaymentRequestDetails = requestDetails;
         requestDetails.PaymentDetails = getEcResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
         var wrapper = new DoExpressCheckoutPaymentReq {DoExpressCheckoutPaymentRequest = request};
         var doEcResponse = _payPalApiService.DoExpressCheckoutPayment(wrapper, GetApiUserName());
         var custom = getEcResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails[0].Custom.Split('|');
         var result = new CheckoutPaymentResult {
             BillingAgreementId = doEcResponse.DoExpressCheckoutPaymentResponseDetails.BillingAgreementID,
             PaymentStatus = doEcResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentStatus.ToString(),
             PendingReason = doEcResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PendingReason.ToString(),
             TransactionId = doEcResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID,
             ProductName = (ProductNames) Enum.Parse(typeof (ProductNames), custom[0], true),
             Referrer = custom[1],
             Errors = new List<string>(),
         };
         if (doEcResponse.Ack.Equals(AckCodeType.FAILURE) || (doEcResponse.Errors != null && doEcResponse.Errors.Count > 0)) {
             foreach (var error in doEcResponse.Errors)
                 result.Errors.Add(error.LongMessage);
         } else {
             _userService.Purchase(user, result.ProductName, payerId);
         }
         return result;
     } return new CheckoutPaymentResult { Errors = new List<string> { status.ToString() } };
 }
コード例 #12
0
 public CheckoutDetailResult GetExpressCheckoutDetails(User user, string token)
 {
     try {
         var response = _GetExpressCheckoutDetails(token);
         CheckoutStatus status;
         if (!Enum.TryParse(response.GetExpressCheckoutDetailsResponseDetails.CheckoutStatus, true, out status))
             return new CheckoutDetailResult {Errors = new List<string> {"NOCHECKOUTSTATUS"}};
         var result = new CheckoutDetailResult { CheckoutStatus = status, Errors = new List<string>(), };
         if (response.Ack.Equals(AckCodeType.FAILURE) || (response.Errors != null && response.Errors.Count > 0)) {
             foreach (var error in response.Errors)
                 result.Errors.Add(error.LongMessage);
         } else {
             var custom = response.GetExpressCheckoutDetailsResponseDetails.PaymentDetails[0].Custom.Split('|');
             result.Referrer = custom[1];
             result.ProductName = (ProductNames) Enum.Parse(typeof (ProductNames), custom[0], true);
         }
         return result;
     } catch (KatushaProductNameNotFoundException) {
         return new CheckoutDetailResult { Errors = new List<string> { "PRODUCTNOTFOUND" } };
     }
 }
コード例 #13
0
 public KatushaNeedsPaymentException(User user, ProductNames product)
     : base("NeedsPayment", "Katusha needs payment, sorry", null)
 {
     User = user;
     Product = product;
 }
コード例 #14
0
 public void UpdateUser(User user) { _repository.FullUpdate(user); }