Ejemplo n.º 1
0
        public async Task <StripeCard> CreateCardAsync(string customerId, StripeCardCreateOptions options, string apiKey)
        {
            var cardService = new StripeCardService(apiKey);
            var card        = cardService.Create(customerId, options);

            return(card);
        }
Ejemplo n.º 2
0
        public bool CreateCardDetails()
        {
            try
            {
                SourceCard card = new SourceCard();
                card.Number          = this.Number;
                card.ExpirationYear  = this.ExpirationYear;
                card.ExpirationMonth = this.ExpirationMonth;
                card.Cvc             = this.Cvv;
                card.Name            = this.Name;
                StripeCardService       cardService = new StripeCardService(Params.stripeApiKey);
                StripeCardCreateOptions cardoption  = new StripeCardCreateOptions();
                cardoption.SourceCard = card;
                var cardinfo = cardService.Create(this.CustomerId, cardoption);
                if (!string.IsNullOrEmpty(cardinfo.Id))
                {
                    this.CardId = cardinfo.Id;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(false);
        }
Ejemplo n.º 3
0
    public object CreateCard(string cardNo, string cardType)
    {
        var cardOpt = new StripeCardCreateOptions()
        {
            SourceToken = cardType
        };

        return((new StripeCardService()).Create(cardNo, cardOpt));
    }
        public void CreateCard(string customerId, string tokenId)
        {
            var myCard = new StripeCardCreateOptions();

            myCard.SourceToken = tokenId;

            var        cardService = new StripeCardService();
            StripeCard stripeCard  = cardService.Create(customerId, myCard); // optional isRecipient
        }
        private StripeCard CreateCard(string tokenId, string customerId)
        {
            var myCard = new StripeCardCreateOptions
            {
                SourceToken = tokenId
            };

            var        cardService = new StripeCardService();
            StripeCard stripeCard  = cardService.Create(customerId, myCard); // optional isRecipient

            return(stripeCard);
        }
Ejemplo n.º 6
0
        private StripeCard AddCardToStripe(CreditCard card, string stripeCustomerId)
        {
            var options = new StripeCardCreateOptions
            {
                Card = new StripeCreditCardOptions
                {
                    TokenId = card.StripeToken
                }
            };

            return(_cardService.Create(stripeCustomerId, options));
        }
        public Task <DomainCard> AddAsync(DomainCardCreateOptions options)
        {
            return(Task.Run(() =>
            {
                try
                {
                    StripeCardCreateOptions createOptions =
                        _mapper.Map <DomainCardCreateOptions, StripeCardCreateOptions>(options);

                    StripeCard card = _service.Create(options.CustomerId, createOptions);
                    return Task.FromResult(_mapper.Map <StripeCard, DomainCard>(card));
                }
                catch (StripeException e)
                {
                    throw new BillingException(string.Format("Failed to register card in billing system for customer {0}: {1}", options.CustomerId, e));
                }
            }));
        }
Ejemplo n.º 8
0
        public ActionResult AddCustomer(string stripeEmail, string stripeToken)
        {
            //create customer with stripeToken
            var myCustomer = new StripeCustomerCreateOptions();

            myCustomer.Email       = stripeEmail;
            myCustomer.SourceToken = stripeToken;

            //get customerID
            var            customerService = new StripeCustomerService();
            StripeCustomer stripeCustomer  = customerService.Create(myCustomer);

            stripeCustomerId = stripeCustomer.Id;

            //get cardId from stripeCustomer
            cardId = stripeCustomer.DefaultSourceId;

            //get card information from cardId
            var myCard = new StripeCardCreateOptions();

            myCard.SourceToken = cardId;

            var        cardService = new StripeCardService();
            StripeCard stripeCard  = cardService.Get(stripeCustomerId, cardId);


            //save the customerID, cardID, CC4, company name, expiry object into the database
            string   customerID = stripeCustomer.Id;
            string   cardID     = stripeCustomer.DefaultSourceId;
            string   cc4        = stripeCard.Last4;
            string   company    = stripeCard.Brand;
            int      month      = Convert.ToInt32(stripeCard.ExpirationMonth);
            int      year       = Convert.ToInt32(stripeCard.ExpirationYear);
            DateTime expiry     = new DateTime(year, month, 1);

            var currentUserID = User.Identity.GetUserId();

            this.Edit((String)currentUserID, customerID, cardID, cc4, company, expiry);
            TempData["notice"] = "Card successfully added!";
            return(RedirectToAction("Index", "Manage"));
        }
Ejemplo n.º 9
0
        public async Task ExecuteAsync(UserId userId, string customerId, string tokenId, UserType userType)
        {
            userId.AssertNotNull("userId");
            customerId.AssertNotNull("customerId");
            tokenId.AssertNotNull("tokenId");

            var apiKey = this.apiKeyRepository.GetApiKey(userType);

            var cardCreateOptions = new StripeCardCreateOptions {
                Source = new StripeSourceOptions {
                    TokenId = tokenId,
                }
            };
            var card = await this.stripeService.CreateCardAsync(customerId, cardCreateOptions, apiKey);

            var customerUpdateOptions = new StripeCustomerUpdateOptions {
                DefaultSource = card.Id
            };

            await this.stripeService.UpdateCustomerAsync(customerId, customerUpdateOptions, apiKey);
        }
Ejemplo n.º 10
0
        public StripeCard AddCustomerPaymentMethod(string sStripeCustomerId, string sStripeToken)
        {
            try
            {
                StripeConfiguration.SetApiKey(ConfigurationManager.AppSettings["stripeApi_LiveKey"]);

                var cardOptions = new StripeCardCreateOptions()
                {
                    SourceToken = sStripeToken
                };

                var        cardService = new StripeCardService();
                StripeCard card        = cardService.Create(sStripeCustomerId, cardOptions);

                return(card);
            }
            catch (Exception ex)
            {
                oLogger.LogData("METHOD: AddCustomerPaymentMethod; ERROR: TRUE; EXCEPTION: " + ex.Message + "; INNER EXCEPTION: " + ex.InnerException + "; STACKTRACE: " + ex.StackTrace);
                throw;
            }
        }
Ejemplo n.º 11
0
        private StripeCard AddCardToStripe(CreditCard card, string stripeCustomerId)
        {
            var options = new StripeCardCreateOptions
            {
                SourceCard = new SourceCard
                {
                    Number          = card.CardNumber,
                    ExpirationMonth = card.ExpirationMonth,
                    ExpirationYear  = card.ExpirationYear,
                    AddressCountry  = card.AddressCountry,
                    AddressLine1    = card.AddressLine1,
                    AddressLine2    = card.AddressLine2,
                    AddressCity     = card.AddressCity,
                    AddressState    = card.AddressState,
                    AddressZip      = card.AddressZip,
                    Name            = card.Name,
                    Cvc             = card.Cvc,
                }
            };

            return(_cardService.Create(stripeCustomerId, options));
        }
        public StripeCardServiceTest()
        {
            this.service = new StripeCardService();

            this.createOptions = new StripeCardCreateOptions()
            {
                SourceToken = "tok_123",
            };

            this.updateOptions = new StripeCardUpdateOptions()
            {
                Metadata = new Dictionary <string, string>()
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new StripeCardListOptions()
            {
                Limit = 1,
            };
        }
Ejemplo n.º 13
0
        public async Task WhenStripeModeIsTest_ItShouldCreateACustomer()
        {
            this.apiKeyRepository.Setup(v => v.GetApiKey(UserType.TestUser)).Returns(TestKey);

            var expectedCardCreateOptions = new StripeCardCreateOptions {
                Source = new StripeSourceOptions {
                    TokenId = TokenId
                }
            };
            var card = new StripeCard {
                Id = CardId
            };

            this.stripeService.Setup(v => v.CreateCardAsync(
                                         CustomerId,
                                         It.Is <StripeCardCreateOptions>(
                                             x => JsonConvert.SerializeObject(x, Formatting.None) == JsonConvert.SerializeObject(expectedCardCreateOptions, Formatting.None)),
                                         TestKey))
            .ReturnsAsync(card);


            var expectedCustomerUpdateOptions = new StripeCustomerUpdateOptions {
                DefaultSource = CardId
            };

            this.stripeService.Setup(v => v.UpdateCustomerAsync(
                                         CustomerId,
                                         It.Is <StripeCustomerUpdateOptions>(
                                             x => JsonConvert.SerializeObject(x, Formatting.None) == JsonConvert.SerializeObject(expectedCustomerUpdateOptions, Formatting.None)),
                                         TestKey))
            .Returns(Task.FromResult(0))
            .Verifiable();

            await this.target.ExecuteAsync(UserId, CustomerId, TokenId, UserType.TestUser);

            this.stripeService.Verify();
        }
Ejemplo n.º 14
0
        // sk_test_E01Kh96YOzRtkhD5wItn8CDd portal api

        public async Task <Dictionary <bool, string> > ProcessCustomerCard(Models.Card card, int amount, string email)
        {
            Dictionary <bool, string> result;
            var customerId = await CheckCustomerHasStripeAccnt(email);

            if (!string.IsNullOrEmpty(customerId))
            {
                StripeToken stripeToken = new StripeToken();

                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                StripeConfiguration.SetApiKey(StripeClientConstants.ApiKey);

                var tokenOptions = new StripeTokenCreateOptions()
                {
                    Card = new StripeCreditCardOptions()
                    {
                        Number          = card.Number,
                        ExpirationYear  = card.ExpiryYear,
                        ExpirationMonth = card.ExpiryMonth,
                        Cvc             = card.CVC,
                        Name            = card.Name
                    }
                };
                var tokenService = new StripeTokenService();
                try
                {
                    stripeToken = tokenService.Create(tokenOptions, new StripeRequestOptions()
                    {
                        ApiKey = Stripe.StripeClient.DefaultPublishableKey
                    });
                    var cardOptions = new StripeCardCreateOptions()
                    {
                        SourceToken = stripeToken.Id,
                    };

                    var        cardService = new StripeCardService();
                    StripeCard newCard     = cardService.Create(customerId, cardOptions, new StripeRequestOptions()
                    {
                        ApiKey = _stripeSecretTestkey
                    });
                    return(result = await ChargeCustomerCard(customerId, amount, newCard.Id));
                }
                catch (StripeException e)
                {
                    return(result = new Dictionary <bool, string>()
                    {
                        { false, e.Message }
                    });
                }
            }
            else
            {
                StripeToken stripeToken = new StripeToken();

                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                StripeConfiguration.SetApiKey(StripeClientConstants.ApiKey);

                var tokenOptions = new StripeTokenCreateOptions()
                {
                    Card = new StripeCreditCardOptions()
                    {
                        Number          = card.Number,
                        ExpirationYear  = card.ExpiryYear,
                        ExpirationMonth = card.ExpiryMonth,
                        Cvc             = card.CVC,
                        Name            = card.Name
                    }
                };
                var tokenService = new StripeTokenService();
                try
                {
                    stripeToken = tokenService.Create(tokenOptions, new StripeRequestOptions()
                    {
                        ApiKey = Stripe.StripeClient.DefaultPublishableKey
                    });
                }
                catch (StripeException e)
                {
                    return(result = new Dictionary <bool, string>()
                    {
                        { false, e.Message }
                    });
                }
                try
                {
                    var customerOptions = new StripeCustomerCreateOptions()
                    {
                        Email       = email,
                        SourceToken = stripeToken.Id,
                    };

                    var            customerService = new StripeCustomerService();
                    StripeCustomer customer        = customerService.Create(customerOptions, new StripeRequestOptions()
                    {
                        ApiKey = _stripeSecretTestkey
                    });
                    return(result = await ChargeCustomerCard(customer.Id, amount, stripeToken.StripeCard.Id));
                }
                catch (StripeException e)
                {
                    return(result = new Dictionary <bool, string>()
                    {
                        { false, e.Message }
                    });
                }
            }
            return(result = new Dictionary <bool, string>());
        }
Ejemplo n.º 15
0
        public async Task <ActionResult> ChargeSaveCustomer(SubscriptionModel model)
        {
            var subscriptionBA     = new Subscription();
            var serialization      = new Serialization();
            var status             = false;
            var HashCriteria       = new Hashtable();
            var actualCriteria     = string.Empty;
            var HashCriteriaPlan   = new Hashtable();
            var actualCriteriaPlan = string.Empty;
            var userID             = Convert.ToString(SessionController.UserSession.UserId);
            var subscriptionModel  = new SubscriptionModel();

            subscriptionModel.CardType            = GetPaymentCardType();
            subscriptionModel.ExpirationYearList  = GetExpirationYear();
            subscriptionModel.ExpirationMonthList = GetExpirationMonth();
            if (model.RoleID == 2)
            {
                ViewBag.SubscriptionTitle = "Find unlimited investment opportunities for $399 per month.";
            }
            else if (model.RoleID == 3)
            {
                ViewBag.SubscriptionTitle = "List unlimited investment opportunities for $399 per month.";
            }

            //Remove fields form model because these are required fieldsand we are not using these fields on paywall
            ModelState.Remove("State");
            ModelState.Remove("BillingAddress");
            ModelState.Remove("Zip");
            ModelState.Remove("City");
            if (!ModelState.IsValid)
            {
                return(PartialView("_PaymentSubscriptionPopup", subscriptionModel));
            }
            //Check if the user is already a custome ron stripe or not?
            var customer_ID = Convert.ToString(SessionController.UserSession.CustomerID);

            if (customer_ID != null && customer_ID != "")
            {
                if (model.Token != null)
                {
                    //For existing customer create new card
                    var cardOptions = new StripeCardCreateOptions()
                    {
                        SourceToken = model.Token
                    };

                    var        cardService = new StripeCardService();
                    StripeCard card        = cardService.Create(customer_ID, cardOptions);
                }
                else
                {
                    return(PartialView("_PaymentSubscriptionPopup", subscriptionModel));
                }
                model.CustomerID = customer_ID;
            }
            else
            {
                // 1. Create customer in stripe
                if (model.Token != null)
                {
                    var customerID = await CreateCustomer(model.Token);

                    model.CustomerID = customerID;
                    SessionController.UserSession.CustomerID = model.CustomerID;
                }
                else
                {
                    return(PartialView("_PaymentSubscriptionPopup", subscriptionModel));
                }
            }
            // 2. Get the plans from the Plans table
            HashCriteriaPlan.Add("ID", model.subscriptionOption.ID.ToString());
            actualCriteriaPlan = serialization.SerializeBinary((object)HashCriteriaPlan);

            var result              = subscriptionBA.GetPlanDetails(actualCriteriaPlan);
            var subscriptionPlans   = (SubscriptionPlans)(serialization.DeSerializeBinary(Convert.ToString(result)));
            var planID              = model.subscriptionOption.ID;
            var subscription_PlanID = subscriptionPlans.SubscriptionPlanID;
            var amount              = subscriptionPlans.Amount;

            // 3. subscription aginst that plan
            var subscriptionService = new StripeSubscriptionService();
            var stripeSubscription  = subscriptionService.Create(model.CustomerID, subscription_PlanID);

            //4. Make the payment
            model.Amount = amount;

            var chargeId = await ProcessPayment(model);

            if (chargeId != null)
            {
                DateTime billingDate = DateTime.Now;
                // 5. Save detals in the subscription table with amount and token of charge
                HashCriteria.Add("Token", model.Token);
                HashCriteria.Add("UserID", userID);
                HashCriteria.Add("Amount", model.Amount);
                HashCriteria.Add("BillingDate", Convert.ToString(billingDate.ToString("dd/MM/yyyy")));
                HashCriteria.Add("CustomerID", model.CustomerID);
                HashCriteria.Add("PlanID", planID);
                HashCriteria.Add("SubscriptionID", stripeSubscription.Id);
                HashCriteria.Add("ChargeID", chargeId);

                actualCriteria = serialization.SerializeBinary((object)HashCriteria);

                var subscriptionstatus = subscriptionBA.SaveSubscriptionData(actualCriteria);
                var subscriptionID     = Convert.ToInt64(serialization.DeSerializeBinary(Convert.ToString(subscriptionstatus)));

                if (subscriptionID > 0)
                {
                    // 6. Update the user role as Investor/Broker
                    status = UpdateUserRole(model.RoleID);
                    //Make the user flag as paid
                    SessionController.UserSession.IsPaid = true;
                    if (model.RoleID == 2)
                    {
                        Synoptek.SessionController.UserSession.RoleType = "Investor";
                    }
                    else if (model.RoleID == 3)
                    {
                        Synoptek.SessionController.UserSession.RoleType = "Broker";
                    }

                    //initialize userAuthModel
                    LoginController loginController = new LoginController();
                    var             loginBA         = new Login();
                    LoginModel      loginModel      = new LoginModel();
                    HashCriteria.Add("UserName", SessionController.UserSession.EmailAddress);
                    actualCriteria = serialization.SerializeBinary((object)HashCriteria);
                    var rec = loginBA.ValidateLogin(actualCriteria);
                    var loginModelDetails = (LoginModel)(serialization.DeSerializeBinary(Convert.ToString(rec)));

                    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie, DefaultAuthenticationTypes.ExternalCookie);

                    var userSession = loginController.Authenticate(loginModelDetails);
                    if (userSession != null)
                    {
                        var identity = new ClaimsIdentity(AuthenticationHelper.CreateClaim(userSession,
                                                                                           userSession.UserRole),
                                                          DefaultAuthenticationTypes.ApplicationCookie
                                                          );
                        AuthenticationManager.SignIn(new AuthenticationProperties()
                        {
                            AllowRefresh = true,
                            IsPersistent = true,
                            ExpiresUtc   = DateTime.UtcNow.AddHours(1)
                        }, identity);
                    }

                    if (model.RoleID == 2)
                    {
                        return(RedirectToAction("Investor", "Dashboard"));
                    }
                    if (model.RoleID == 3)
                    {
                        return(RedirectToAction("Broker", "Dashboard"));
                    }
                }
            }
            return(PartialView("_PaymentSubscriptionPopup", subscriptionModel));
        }