public SubscriptionChangedEventHandler(SubscriptionsContext dbContext, IStripeService stripeService, IOptions <StripeSettings> settings, ILogger <SubscriptionChangedEventHandler> logger) { _dbContext = dbContext; _stripeService = stripeService; _stripeSettings = settings.Value; _logger = logger; }
public static TransactionResult StopSubscription(TransactionRequest request, StripeSettings stripeSettings, ILogger logger) { var subscriptionId = request.GetParameterAs <string>("subscriptionId"); InitStripe(stripeSettings, true); var subscriptionService = new SubscriptionService(); var subscription = subscriptionService.Cancel(subscriptionId, new SubscriptionCancelOptions()); var stopResult = new TransactionResult() { TransactionGuid = Guid.NewGuid().ToString(), ResponseParameters = new Dictionary <string, object>() { { "canceledAt", subscription.CanceledAt }, }, OrderGuid = request.Order.Guid, TransactionCurrencyCode = request.Order.CurrencyCode, }; if (subscription.Status == "canceled") { stopResult.Success = true; stopResult.NewStatus = PaymentStatus.Complete; return(stopResult); } else { logger.Log <TransactionResult>(LogLevel.Warning, "The subscription cancellation request for Order#" + stopResult.Order.Id + " by stripe failed." + subscription.StripeResponse.Content); stopResult.Success = false; stopResult.Exception = new Exception("An error occurred while processing refund"); return(stopResult); } }
public static void ConfigurePaymentSettings(this IServiceCollection services, IConfiguration configuration) { var stripeSettings = new StripeSettings(); configuration.Bind("StripeSettings", stripeSettings); services.AddSingleton <StripeSettings>(stripeSettings); }
public IActionResult Charge(string stripeEmail, string stripeToken) { StripeSettings stripe = new StripeSettings(); var key = stripe.PublishableKey; var comp = _context.Companies.Where(x => x.CreatorId == User.Identity.GetUserId()).FirstOrDefault(); var customers = new CustomerService(); var charges = new ChargeService(); var customer = customers.Create(new CustomerCreateOptions { Email = stripeEmail, SourceToken = stripeToken }); var charge = charges.Create(new ChargeCreateOptions { Amount = 1000, Description = "Sample Charge", Currency = "usd", CustomerId = customer.Id }); _context.SaveChanges(); return(RedirectToAction("ChargeConfirmation", new { id = comp.Id })); }
public static StripeCharge GetStripeChargeInfo(string stripeEmail, string stripeToken, int amount) { var customers = new StripeCustomerService(); var charges = new StripeChargeService(); var stripeSettings = new StripeSettings(); stripeSettings.ReloadStripeSettings(); StripeConfiguration.SetApiKey(stripeSettings.SecretKey); var customer = customers.Create(new StripeCustomerCreateOptions { Email = stripeEmail, SourceToken = stripeToken }); var charge = charges.Create(new StripeChargeCreateOptions { Amount = amount * 100, //charge in cents Description = "Dunkey Delivery", Currency = "usd", CustomerId = customer.Id, }); return(charge); }
public static string GetPublishableKey(StripeSettings stripeSettings) { var publishableKey = stripeSettings.EnableTestMode ? stripeSettings.TestPublishableKey : stripeSettings.PublishableKey; return(publishableKey); }
public RequestHandler(SubscriptionsContext dbContext, UserContext userContext, IStripeService stripeService, IOptions <StripeSettings> settings, ILogger <RequestHandler> logger) { _dbContext = dbContext; _userContext = userContext; _stripeService = stripeService; _logger = logger; _settings = settings.Value; }
private void LoadData() { StripeSettings settings = new StripeSettings(); settings.Merge(MyPage.MTApp.CurrentStore.Settings.PaymentSettingsGet(this.BlockId)); this.ApiKeyField.Text = settings.StripeApiKey; }
public StripeService(InvoiceService invoiceService, CustomerService customerService, SubscriptionService subscriptionService, SessionService sessionService, IOptions <ApplicationSettings> appSettings, IOptions <StripeSettings> options) { _invoiceService = invoiceService; _customerService = customerService; _subscriptionService = subscriptionService; _sessionService = sessionService; _appSettings = appSettings.Value; _settings = options.Value; }
public StripeService(IUnitOfWorkAsync unitOfWork, IOptions <AppSettings> appSettings, ILogger <StripeService> logger) { _appSettings = appSettings.Value; _stripeSettings = appSettings.Value.Stripe; _logger = logger; _personRepository = unitOfWork.RepositoryAsync <Person>(); _organizationCustomerRepository = unitOfWork.RepositoryAsync <OrganizationCustomer>(); }
private static void InitStripe(StripeSettings stripeSettings, bool secret = false) { var publishableKey = stripeSettings.EnableTestMode ? stripeSettings.TestPublishableKey : stripeSettings.PublishableKey; var secretKey = stripeSettings.EnableTestMode ? stripeSettings.TestSecretKey : stripeSettings.SecretKey; StripeConfiguration.ApiKey = !secret ? publishableKey : secretKey; }
public FakelakiController(ILogger <FakelakiController> logger, IMapper mapper, IFakelakiService fakelakiService, IUserService userService, IOptions <StripeSettings> stripeSettings) { _logger = logger; _mapper = mapper; _fakelakiService = fakelakiService; _userService = userService; _stripeSettings = stripeSettings.Value; // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = _stripeSettings.ApiKey; webhookSecret = _stripeSettings.WebhookSecret; }
private void SaveData() { StripeSettings settings = new StripeSettings(); settings.Merge(MyPage.MTApp.CurrentStore.Settings.PaymentSettingsGet(this.BlockId)); settings.StripeApiKey = this.ApiKeyField.Text.Trim(); MyPage.MTApp.CurrentStore.Settings.PaymentSettingsSet(this.BlockId, settings); MyPage.MTApp.AccountServices.Stores.Update(MyPage.MTApp.CurrentStore); }
public OrderService(IOrderRepository orderRepository, IPaymentRepository paymentRepository, IMapper mapper, IUserService userService, IOptions <StripeSettings> stripeSettings) { _orderRepository = orderRepository; _paymentRepository = paymentRepository; _mapper = mapper; _userService = userService; _stripeSettings = stripeSettings.Value; }
public override void SaveData() { var settings = new StripeSettings(); settings.Merge(HccApp.CurrentStore.Settings.PaymentSettingsGet(GatewayId)); settings.StripeApiKey = txtApiKey.Text.Trim(); settings.CurrencyCode = ddlCurrency.SelectedValue; HccApp.CurrentStore.Settings.PaymentSettingsSet(GatewayId, settings); HccApp.AccountServices.Stores.Update(HccApp.CurrentStore); }
public HomeController(IMarketForecaster marketForecaster, IOptions <StripeSettings> stripeOptions, IOptions <SendGridSettings> sendGridOptions, IOptions <TwilioSettings> twilioOptions, IOptions <WazeForecastSettings> wazeOptions) { homeVM = new HomeVM(); this._marketForecaster = marketForecaster; _stripeOptions = stripeOptions.Value; _sendGridOptions = sendGridOptions.Value; _twilioOptions = twilioOptions.Value; _wazeOptions = wazeOptions.Value; }
public UserController( IUserService userService, IMapper mapper, IOptions <AppSettings> appSettings, StripeSettings stripeSettings) { _userService = userService; _mapper = mapper; _appSettings = appSettings.Value; // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = stripeSettings.ApiKey; }
public SubscribeController(ISubscriptionService subscriptionService, ICustomerService customerService, IMailService mailService, ITemplateService templateService, ILogger <SubscribeController> nlogger, IOptions <StripeSettings> stripeSettings) { _subscriptionService = subscriptionService; _customerService = customerService; _defaultSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; _mailService = mailService; _templateService = templateService; _logger = nlogger; _stripeSettings = stripeSettings.Value; }
public BuyerAccountService( IOptions <AppSettings> appSettings, ILogger <BuyerAccountService> logger, CustomerService customerService, IServiceProvider serviceProvider, IStripeService stripeService) : base(serviceProvider) { _appSettings = appSettings.Value; _stripeSettings = appSettings.Value.Stripe; _logger = logger; _customerService = customerService; _organizationCustomerRepository = UnitOfWork.RepositoryAsync <OrganizationCustomer>(); _customerAccountRepository = UnitOfWork.RepositoryAsync <CustomerAccount>(); }
public WebhookController( CheckoutSessionCompletedEventHandler checkoutSessionCompletedEventHandler, SubscriptionChangedEventHandler subscriptionChangedHandler, InvoiceChangedEventHandler invoiceChanged, IOptions <StripeSettings> settings, IBackgroundJobClient backgroundJobQueue, ILogger <WebhookController> logger ) { _settings = settings.Value; _backgroundJobQueue = backgroundJobQueue; _checkoutSessionCompleted = checkoutSessionCompletedEventHandler; _subscriptionChanged = subscriptionChangedHandler; _invoiceChanged = invoiceChanged; _logger = logger; }
public SubscriptionsModel( UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, ILogger <RegisterModel> logger, IEmailSender emailSender, RoleManager <IdentityRole> roleManager, ApplicationDbContext db, IOptions <StripeSettings> stripeSettings) { _roleManager = roleManager; _db = db; _userManager = userManager; _signInManager = signInManager; _logger = logger; _emailSender = emailSender; _stripeSettings = stripeSettings.Value; }
public HomeController(IMarketForecaster marketForecaster, ILogger <HomeController> logger, ICreditValidator creditValidator, ApplicationDbContext context, IOptions <WazeForecastSettings> wazeForecast, IOptions <StripeSettings> stripe, IOptions <SendGridSettings> sendGrid, IOptions <TwilioSettings> twilio) { _context = context; _creditValidator = creditValidator; _marketForecaster = marketForecaster; _logger = logger; _wazeForecast = wazeForecast.Value; _stripeOptions = stripe.Value; _sendGridOptions = sendGrid.Value; _twilioOptions = twilio.Value; }
public override void LoadData() { if (ddlCurrency.Items.Count == 0) { ddlCurrency.Items.Add(new ListItem(Localization.GetString("CurrencyEmptyValue"), string.Empty)); ddlCurrency.AppendDataBoundItems = true; ddlCurrency.DataTextField = "CurrencyEnglishName"; ddlCurrency.DataValueField = "ISOCurrencySymbol"; ddlCurrency.DataSource = Currency.GetCurrencyList(); ddlCurrency.DataBind(); } var settings = new StripeSettings(); settings.Merge(HccApp.CurrentStore.Settings.PaymentSettingsGet(GatewayId)); txtApiKey.Text = settings.StripeApiKey; ddlCurrency.SelectedValue = settings.CurrencyCode; }
public WebhookController(DBContext context, IOptions <StripeSettings> settings) { _service = new CartService(context); _settings = settings.Value; }
public static TransactionResult ProcessPayment(TransactionRequest request, StripeSettings stripeSettings, ILogger logger) { InitStripe(stripeSettings); var parameters = request.Parameters; parameters.TryGetValue("cardNumber", out var cardNumber); parameters.TryGetValue("cardName", out var cardName); parameters.TryGetValue("expireMonth", out var expireMonthStr); parameters.TryGetValue("expireYear", out var expireYearStr); parameters.TryGetValue("cvv", out var cvv); var order = request.Order; //do we have a saved stripe customer id? var address = order.BillingAddressSerialized.To <Address>(); var customerId = GetCustomerId(order.User, null, address); var tokenCreateOptions = new TokenCreateOptions { Card = new CreditCardOptions { Number = cardNumber.ToString(), ExpYear = long.Parse(expireYearStr.ToString()), ExpMonth = long.Parse(expireMonthStr.ToString()), Cvc = cvv.ToString(), Name = cardName.ToString(), }, Customer = customerId }; //get token for card var tokenService = new TokenService(); var stripeToken = tokenService.Create(tokenCreateOptions); GetFinalAmountDetails(request.Amount ?? order.OrderTotal, order.CurrencyCode, address, out var currencyCode, out var finalAmount); var options = new ChargeCreateOptions { Amount = (long)(finalAmount) * 100, Currency = currencyCode, Description = stripeSettings.Description, Source = stripeToken.Id, Capture = !stripeSettings.AuthorizeOnly, Customer = customerId }; InitStripe(stripeSettings, true); var service = new ChargeService(); var charge = service.Create(options); var processPaymentResult = new TransactionResult() { ResponseParameters = new Dictionary <string, object>() { { "authorizationCode", charge.AuthorizationCode }, { "balanceTransactionId", charge.BalanceTransactionId }, { "chargeId", charge.Id } }, TransactionGuid = request.TransactionGuid, TransactionAmount = (decimal)charge.Amount / 100, TransactionCurrencyCode = charge.Currency, OrderGuid = order.Guid }; if (charge.Status == "failed") { logger.Log <TransactionResult>(LogLevel.Warning, "The payment for Order#" + order.Id + " by stripe failed." + charge.FailureMessage); processPaymentResult.Success = false; processPaymentResult.Exception = new Exception("An error occurred while processing payment"); return(processPaymentResult); } processPaymentResult.Success = true; if (charge.Status == "succeeded") { processPaymentResult.NewStatus = stripeSettings.AuthorizeOnly ? PaymentStatus.Authorized : PaymentStatus.Complete; } else { processPaymentResult.NewStatus = PaymentStatus.Pending; } return(processPaymentResult); }
public IActionResult Checkout([Bind("CustomerFirstName,CustomerLastName,UserName,Gender,Email,PhoneNumber,Country,State,ZipCode,Address,SameAddress", "Address2", "Country2", "State2", "ZipCode2", "AlternatePhoneNumber")] Customers customers, string stripeEmail, string stripeToken) { var customer = context.Customers.Where(x => x.Email == customers.Email).SingleOrDefault(); customer.CustomerFirstName = customers.CustomerFirstName; customer.CustomerLastName = customers.CustomerLastName; customer.UserName = customers.UserName; customer.Gender = customers.Gender; customer.Email = customers.Email; customer.PhoneNumber = customers.PhoneNumber; customer.Country = customers.Country; customer.State = customers.State; customer.ZipCode = customers.ZipCode; customer.Address = customers.Address; customer.SameAddress = customers.SameAddress; customer.Address2 = customers.Address2; customer.AlternatePhoneNumber = customers.AlternatePhoneNumber; customer.Country2 = customers.Country2; customer.State2 = customers.State2; customer.ZipCode2 = customers.ZipCode2; context.SaveChanges(); var amount = TempData["total"]; Orders orders = new Orders() { OrderAmount = Convert.ToSingle(amount), OrderDate = DateTime.Now, CustomerId = customer.CustomerId }; context.Orders.Add(orders); context.SaveChanges(); var cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart"); List <OrderProducts> orderProducts = new List <OrderProducts>(); for (int i = 0; i < cart.Count; i++) { OrderProducts orderProduct = new OrderProducts() { OrderId = orders.OrderId, ProductId = cart[i].Products.ProductId, Quantity = cart[i].ItemQuantity }; orderProducts.Add(orderProduct); } orderProducts.ForEach(n => context.OrderProducts.Add(n)); context.SaveChanges(); TempData["cust"] = customer.CustomerId; StripeSettings ss = new StripeSettings() { PublishableKey = stripeEmail, SecretKey = stripeToken }; context.StripeSettings.Add(ss); context.SaveChanges(); Payments p1 = new Payments() { OrderId = orders.OrderId, Amount = Convert.ToSingle(amount), PaymentDate = DateTime.Today, CardDigit = 1111, StripeSettingsId = ss.StripeSettingsId, CustomerId = customer.CustomerId, Description = "sucessfully done" }; context.Payments.Add(p1); context.SaveChanges(); return(RedirectToAction("status", "cart")); }
public StripeController(StripeSettings stripeSettings, ISettingService settingService) { _stripeSettings = stripeSettings; _settingService = settingService; }
public SimplyPayController(StripeSettings settings, IHttpContextAccessor httpContextAccessor) { this.stripeSettings = settings; this.httpContextAccessor = httpContextAccessor; }
public static void ReloadStripeSettings(this StripeSettings Me) { Me.PublishableKey = ConfigurationManager.AppSettings["StripePublishableKey"]; Me.SecretKey = ConfigurationManager.AppSettings["StripeSecretKey"]; }
public StripePaymentFlowController(StripeSettings settings, IHttpContextAccessor httpContextAccessor) { this.paymentSettings = settings; this.httpContextAccessor = httpContextAccessor; }