예제 #1
0
        //Connect host stripe account so we can pay them
        public async Task <IActionResult> ConnectHostToStripe(String code)
        {
            var service = new StripeOAuthTokenService(_stripeSettingAuth.SecretKey);

            var result = service.Create(new StripeOAuthTokenCreateOptions()
            {
                Code      = code,
                GrantType = "authorization_code"
            });

            if (result.Error != null)
            {
                //error message for stripe!
                return(NotFound());
            }

            var user = await _userManager.GetUserAsync(User);

            user.ConnectHostToStripe(result.StripeUserId, result.StripePublishableKey,
                                     result.AccessToken, result.RefreshToken);

            await _userManager.UpdateAsync(user);

            return(RedirectToAction("Index", "Host"));
        }
예제 #2
0
        public ActionResult PostConnect(string code)
        {
            var stripeService      = new StripeOAuthTokenService(ConfigurationManager.AppSettings["masterMerchantSecretkey"]);
            var stripeTokenOptions = new StripeOAuthTokenCreateOptions()
            {
                Code = code, GrantType = "authorization_code", Scope = "read_write"
            };
            StripeOAuthToken response = stripeService.Create(stripeTokenOptions);

            //note, you would actually want to store these details securely against the new merchant, pass back the merchant id and look it up later
            return(Redirect("/home/index?merchantToken=" + response.AccessToken));
        }
예제 #3
0
        public OnBoardingService(IWorkContext workContext,
                                 ILogger logger,
                                 StripeConnectPaymentSettings stripeConnectPaymentSettings,
                                 IWebHelper webHelper,

                                 HttpClient httpClient,
                                 ICustomerEntityService customerEntityService)
        {
            _workContext = workContext;
            _logger      = logger;
            _stripeConnectPaymentSettings = stripeConnectPaymentSettings;
            _webHelper               = webHelper;
            _httpClient              = httpClient;
            _customerEntityService   = customerEntityService;
            _onboardingCustomers     = new ConcurrentDictionary <string, int>();
            _stripeOAuthTokenService = new StripeOAuthTokenService(_stripeConnectPaymentSettings.SecretKey);
        }
예제 #4
0
        public IActionResult StripeCallback(string code)
        {
            var service = new StripeOAuthTokenService("sk_test_FYvhtg9S58z86Idcktw6JhAg");

            var result = service.Create(new StripeOAuthTokenCreateOptions()
            {
                Code      = code,
                GrantType = "authorization_code"
            });

            var user = _brewsyContext.Users.FirstOrDefault(x => x.Id == User.GetUserId());

            user.StripeAccessToken    = result.AccessToken;
            user.StripePublishableKey = result.StripePublishableKey;
            user.StripeRefreshToken   = result.RefreshToken;
            user.StripeUserId         = result.StripeUserId;

            _brewsyContext.SaveChanges();

            return(RedirectToAction("Index", "Beers"));
        }
        public HttpResponseMessage StripeResponse()  //Int32 OwnerId
        {
            try
            {
                var log = new EventureLog();
                log.Message = "So far so good";
                log.Caller  = "StripeResponse";
                log.Status  = "Info";
                log.LogDate = System.DateTime.Now.ToLocalTime();
                db.EventureLogs.Add(log);
                db.SaveChanges();

                var queryValue = Request.RequestUri.ParseQueryString();

                if (queryValue["error_description"] != null)
                {
                    var logE = new EventureLog();
                    logE.Message = "Error Stripe Call 1: " + queryValue["error_description"];
                    logE.Caller  = "StripeResponse_ERROR";
                    logE.Status  = "ERROR";
                    logE.LogDate = System.DateTime.Now.ToLocalTime();
                    db.EventureLogs.Add(logE);
                    db.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.InternalServerError));
                }

                string code = queryValue["code"];

                log.Message = "got the code: " + code;
                log.Caller  = "StripeResponse";
                log.Status  = "Info";
                log.LogDate = System.DateTime.Now.ToLocalTime();
                db.EventureLogs.Add(log);
                db.SaveChanges();

                var stripeService      = new StripeOAuthTokenService(ConfigurationManager.AppSettings["StripeSecret"]);
                var stripeTokenOptions = new StripeOAuthTokenCreateOptions()
                {
                    Code = code, GrantType = "authorization_code"
                };
                var response = stripeService.Create(stripeTokenOptions);

                log.Caller  = "StripeResponse";
                log.Status  = "Info";
                log.LogDate = System.DateTime.Now.ToLocalTime();
                db.EventureLogs.Add(log);
                db.SaveChanges();

                if (response.Error != null)
                {
                    var logE = new EventureLog();
                    logE.Message = "Error Stripe Call 2: " + response.ErrorDescription;
                    logE.Caller  = "StripeResponse_ERROR";
                    logE.Status  = "ERROR";
                    logE.LogDate = System.DateTime.Now.ToLocalTime();
                    db.EventureLogs.Add(logE);
                    db.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.PaymentRequired));
                }

                var OwnerId = 1;  //need to pass this in from profile   mjb
                var owner   = db.Owners.FirstOrDefault(o => o.Id == OwnerId);
                owner.AccessToken          = response.AccessToken;
                owner.RefreshToken         = response.RefreshToken;
                owner.StripePublishableKey = response.PublishableKey;
                owner.StripeUserId         = response.StripeUserId;
                owner.Livemode             = response.LiveMode;
                owner.Scope = response.Scope;

                db.SaveChanges();

                return(Request.CreateResponse(HttpStatusCode.OK));

                //var resp = Request.CreateResponse(HttpStatusCode.Moved);     //would be cool to call owner again to show changes;  might be easier for javascript
                //resp.Headers.Location = new Uri("http://www.google.com");
                //return resp;
            }
            catch (Exception ex)
            {
                var logE = new EventureLog();
                logE.Message = "Error Handler: " + ex.Message;
                logE.Caller  = "StripeResponse_ERROR";
                logE.Status  = "ERROR";
                logE.LogDate = System.DateTime.Now.ToLocalTime();
                db.EventureLogs.Add(logE);
                db.SaveChanges();

                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }