Esempio n. 1
0
        public void AddOrder(BpiOrder order)
        {
            //  GET SUBSCRIPTION NAME FROM SUBSCRIPTION ID
            var subType = new TypeService().GetSubscriptionTypeById(int.Parse(order.PlanName));
            order.PlanName = subType.SubscriptionTypeName;

            new PaymentGateway().CreateTransaction(order);
        }
Esempio n. 2
0
        /*
         *         [Required]
        [Display(Name = "Card Number")]
        public string CardNumber { get; set; }

        [Required]
        [Display(Name = "CVV")]
        public string Cvv { get; set; }

        [Required]
        [Display(Name = "Expiration Month")]
        public string ExpirationMonth { get; set; }

        [Required]
        [Display(Name = "Expiration Year")]
        public string ExpirationYear { get; set; }
        */
        public BpiOrder AddOrder()
        {
            BpiOrder order = new BpiOrder()
            {
                Amount = 1000M,
                CardHolderFirstName = CardHolderFirstName,
                CardHolderLastName = CardHolderLastName,
                CreditCardNumber = CreditCardNumber,
                Cvv = Cvv,
                ExpirationMonth = ExpirationMonth,
                ExpirationYear = ExpirationYear
            };

            return BlipShipServices.SubscriberService.AddOrder(order);
        }
Esempio n. 3
0
        public BpiSubscriber AddSubscriber(
            string firstName, 
            string lastName, 
            string userName, 
            string password, 
            string companyName, 
            int companyTypeId, 
            string terms,             
            string cardholderName, 
            string cardholderZip, 
            string cardNumber, 
            string cvv, 
            string expiryMonth, 
            string expiryYear)
        {
            ////  STEP 1: ADD TO SUBSCRIBER TABLE
            ////  MAKE INACTIVE SO THEY CANT LOGIN
            ////  THEY NEED TO BE APPROVED FIRST
            ////  SET SUBSCRIBERTYPEID = 1 [BpiSubscriber]
            IGenericBlipShip<Subscriber> subscriberRepo = GetGenericBlipShipRepository<Subscriber>();
            Subscriber newSubscriber = new Subscriber()
            {
                AddedOn = DateTime.Now,
                FirstName = firstName,
                FullName = firstName + " " + lastName,
                IsActive = false,
                LastName = lastName,
                LastUpdatedOn = DateTime.Now,
                Password = password,
                SubscriberTypeId = 1,
                UserName = userName,
                GatewayCustomerId = ""
            };

            subscriberRepo.Add(newSubscriber);

            ////  STEP 3: ADD THE COMPANY
            ////  ALL ITEMS SHOULD BE PASSED IN
            IGenericBlipShip<SubscriberCompany> compRepo = GetGenericBlipShipRepository<SubscriberCompany>();
            SubscriberCompany newCompany = new SubscriberCompany()
            {
                CompanyName = companyName,
                CompanyTypeId = companyTypeId,
                SubscriberId = newSubscriber.SubscriberId
            };

            compRepo.Add(newCompany);

            ////    STEP 4: ADD THE SUBSCRIPTION
            var newSubscription = AddSubscription(newSubscriber.SubscriberId, companyTypeId, terms, companyTypeId == 1 ? companyName : "");

            BpiSubscriptionType subscriptionType = new BpiSubscriptionType();

            switch (companyTypeId) {
                case 1:
                    subscriptionType = GetSubscriptionByInstitution(companyName).Where(x => x.IsYearly == (terms.Contains(Constants.TERMS_ANNUAL) ? true : false)).FirstOrDefault();
                    break;
                case 3:
                    subscriptionType = GetSubsciptionForConsultant().Where(x => x.IsYearly == (terms.Contains(Constants.TERMS_ANNUAL) ? true : false)).FirstOrDefault();
                    break;
            }

            ////    STEP 5: ADD THE ORDER TO THE GATEWAY
            ////    THE RETURNS THE GATEWAY USER ID WHICH NEEDS TO BE SAVED TO SUBSCRIBER TABLE
            var order = new BpiOrder
            {
                Amount = (decimal)subscriptionType.ChargeAmount,
                CardHolderFirstName = cardholderName,
                CreditCardNumber = cardNumber,
                Cvv = cvv,
                ExpirationMonth = expiryMonth,
                ExpirationYear = expiryYear,
                PlanName = subscriptionType.SubscriptionTypeName,
                CardholderPostalCode = cardholderZip
            };

            new PaymentGateway().CreateTransaction(order);

            newSubscriber.GatewayCustomerId = order.GatewayCustomerId;
            subscriberRepo.Attach(newSubscriber);

            return Mapper.DynamicMap<BpiSubscriber>(newSubscriber);

            #region commented code

            ////  STEP 2: ADD THE ADDRESS
            ////  FILL IN THE COUNTRY TYPE INFO
            ////  FILL IN THE ADDRESS TYPE INFO
            ////  SET ADDRESSTYPEID = 1 [Billing]
            ////IRepository<SubscriberAddress> addressRepo = GetGenericBlipShipRepository<SubscriberAddress>();
            ////SubscriberAddress newAddress = new SubscriberAddress() {
            ////    AddedOn = DateTime.Now,
            ////    AddressLine1 = subscriber.Address.AddressLine1,
            ////    AddressLine2 = subscriber.Address.AddressLine2 ?? string.Empty,
            ////    AddressTypeId = 1,
            ////    City = subscriber.Address.City,
            ////    CountryTypeId = subscriber.Address.CountryId,
            ////    IsActive = true,
            ////    LastUpdatedOn = DateTime.Now,
            ////    StateProvince = subscriber.Address.StateProvince,
            ////    ZipPostal = subscriber.Address.ZipPostal,
            ////    SubscriberId = newSubscriber.SubscriberId
            ////};

            ////addressRepo.Add(newAddress);

            ////newSubscriber.SubscriberAddresses.Add(newAddress);

            //newSubscriber.SubscriberCompanies.Add(newCompany);

            ////  STEP 4: ADD THE JOB TYPE
            ////  ALL ITEMS SHOULD BE PASSED IN
            //IRepository<SubscriberJobFunction> jobRepo = GetGenericBlipShipRepository<SubscriberJobFunction>();
            //SubscriberJobFunction newJob = new SubscriberJobFunction() {
            //    JobFunctionTypeId = subscriber.JobType,
            //    SubscriberId = newSubscriber.SubscriberId
            //};

            //jobRepo.Add(newJob);

            //newSubscriber.SubscriberJobFunctions.Add(newJob);

            ////  STEP 5: ADD THE PHONENUMBER
            ////  SET PHONETYPEID = 1 [Work - Cell]
            //IRepository<SubscriberPhone> phoneRepo = GetGenericBlipShipRepository<SubscriberPhone>();
            //SubscriberPhone newPhone = new SubscriberPhone() {
            //    PhoneNumber = subscriber.PhoneNumber,
            //    PhoneTypeId = 1,
            //    SubscriberId = newSubscriber.SubscriberId
            //};

            //phoneRepo.Add(newPhone);

            //newSubscriber.SubscriberPhones.Add(newPhone);

            ////  STEP 6: ADD THE SUBSCRIPTION
            ////  GET THE CONFIG FOR A FREETRIAL [SubscriptionType = 5]
            ////  ADD THE SUBSCRIPTION BUT DONT ACTIVATE IT
            //IGenericBlipShip<Subscription> subscRepo = GetGenericBlipShipRepository<Subscription>();
            //Subscription newSubscription = new Subscription()
            //{
            //    AddedOn = DateTime.Now,
            //    ApiKey = Guid.NewGuid(),
            //    FriendlyName = newSubscriber.FullName,
            //    IsActive = false,
            //    LastUpdatedOn = DateTime.Now,
            //    SubscriberId = newSubscriber.SubscriberId,
            //    SubscriptionTypeId = 5,
            //    GatewaySubscriptionId = subscriber.SubscriptionModel.GatewaySubscriptionId
            //};

            //subscRepo.Add(newSubscription);

            ////  STEP 7: ADD THE FEATURES
            ////  GET ALL THE FEATURES FROM THE CONFIG FOR THE SPECIFIC SUBSCRIPTION
            ////  USE FREETRIAL CONFIG [SubscriptionType = 5]
            //IRepository<SubscriptionTypeConfig> configRepo = GetGenericBlipShipRepository<SubscriptionTypeConfig>();
            //List<int> featureIds = configRepo.Find(x => x.IsActive && x.SubscriptionTypeId == 5).Select(x => x.FeatureTypeId).ToList();

            //IRepository<SubscriptionFeature> subFeatRepo = GetGenericBlipShipRepository<SubscriptionFeature>();

            //foreach (var featureId in featureIds) {
            //    subFeatRepo.Add(new SubscriptionFeature() {
            //        AddedOn = DateTime.Now,
            //        FeatureTypeId = featureId,
            //        IsActive = true,
            //        LastUpdateOn = DateTime.Now,
            //        SubscriptionId = newSubscription.SubscriptionId
            //    });
            //}

            ////  [TODO] RETURN THE FULLY POPULATED BPISUBSCRIBER
            ////  UNNECESSARY RIGHT NOW BECAUSE THEY MUST BE APPROVED BY ADMIN
            //BpiSubscriber returnSubscriber = new BpiSubscriber();
            #endregion
        }
Esempio n. 4
0
        public void CreateTransaction(BpiOrder order)
        {
            CustomerRequest request = new CustomerRequest()
            {
                FirstName = order.CardHolderFirstName,
                LastName = order.CardHolderLastName,
                CreditCard = new CreditCardRequest()
                {
                    BillingAddress = new CreditCardAddressRequest{
                        PostalCode = order.CardholderPostalCode
                    },
                    Number = order.CreditCardNumber,
                    ExpirationMonth = order.ExpirationMonth,
                    ExpirationYear = order.ExpirationYear,
                    CVV = order.Cvv,
                    CardholderName = order.CardHolderFirstName
                }
            };

            Result<Customer> result = BraintreeConstants.Gateway.Customer.Create(request);

            //TransactionRequest request = new TransactionRequest
            //{
            //    Amount = order.Amount,
            //    CreditCard = new TransactionCreditCardRequest
            //    {
            //        Number = order.CreditCardNumber,
            //        CVV = order.Cvv,
            //        ExpirationMonth = order.ExpirationMonth,
            //        ExpirationYear = order.ExpirationYear
            //    },
            //    Options = new TransactionOptionsRequest
            //    {
            //        SubmitForSettlement = true
            //    }
            //};

            //Result<Transaction> result = BraintreeConstants.Gateway.Transaction.Sale(request);

            if (result.IsSuccess())
            {
                var customer = result.Target;
                order.GatewayCustomerId = customer.Id;

                string paymentMethodToken = customer.CreditCards[0].Token;

                SubscriptionRequest subRequest = new SubscriptionRequest()
                {
                    PaymentMethodToken = paymentMethodToken,
                    PlanId = order.PlanName
                };

                Result<Subscription> subResult = BraintreeConstants.Gateway.Subscription.Create(subRequest);

                order.GatewaySubscriptionId = subRequest.Id;
                //order.Message = subResult.Target.Status.ToString();
            }
            else {

            }
        }