public OpenpayAPI( string api_key, string merchant_id,bool production = false) { this.httpClient = new OpenpayHttpClient(api_key, merchant_id, production); CustomerService = new CustomerService(this.httpClient); CardService = new CardService(this.httpClient); BankAccountService = new BankAccountService(this.httpClient); ChargeService = new ChargeService(this.httpClient); PayoutService = new PayoutService(this.httpClient); TransferService = new TransferService(this.httpClient); FeeService = new FeeService(this.httpClient); PlanService = new PlanService(this.httpClient); SubscriptionService = new SubscriptionService(this.httpClient); OpenpayFeesService = new OpenpayFeesService(this.httpClient); WebhooksService = new WebhookService (this.httpClient); }
public bool UserPay(StripeModel stripeModel, string userId) { var shopingCardOfUser = this.db.ShopingCards.Where(c => c.UserId == userId).FirstOrDefault(); var sumOfPay = this.db.ProductShopingCard.Where(c => c.ShopingCardId == shopingCardOfUser.Id); var emailOnUser = this.db.Users.Where(c => c.Id == userId).Select(c => c.Email).FirstOrDefault(); ; var customers = new CustomerService(); var charges = new ChargeService(); var customer = customers.Create(new CustomerCreateOptions { Email = emailOnUser, Source = stripeModel.StripeToken }); var charge = charges.Create(new ChargeCreateOptions { Amount = 500, Description = "Test PaymentBG", Currency = "BGN", Customer = customer.Id, ReceiptEmail = emailOnUser, Metadata = new Dictionary <string, string>() { { "OrderID", "111" }, { "PostCode", "LEE111" } } }); if (charge.Status == "succeeded") { string BalanceTransactionId = charge.BalanceTransactionId; return(true); } return(false); }
private async Task <Charge> GetCharges(string stripeEmail, string stripeToken) { var customers = new CustomerService(); var charges = new ChargeService(); var customer = await customers.CreateAsync(new CustomerCreateOptions { Email = stripeEmail, Source = stripeToken }); var charge = await charges.CreateAsync(new ChargeCreateOptions { Amount = _paymentDetails.Amount * 100, //stripe takes amounts in cents, multiply by 100 to bring it to the right amount; Description = "Payment to SparkAuto garage", Currency = "usd", Customer = customer.Id }); return(charge); }
public ActionResult Create(Pay pay) { // Set your secret key: remember to change this to your live secret key in production // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_vqtwGU271Ml4ScydIJWVoCzs00FnajUr49"; //create customer var customerOptions = new CustomerCreateOptions { Description = pay.CardName, Source = pay.StripeToken, Email = pay.Email, Metadata = new Dictionary <string, string>() { { "Phone Number", pay.Phone } } }; var customerService = new CustomerService(); Customer customer = customerService.Create(customerOptions); long totalPrice = (long)Math.Truncate(decimal.Parse(Request.Form["totalPrice"]) * 100m); var createOptions = new ChargeCreateOptions { Amount = totalPrice, Currency = "myr", Customer = customer.Id }; var service = new ChargeService(); Charge charge = service.Create(createOptions); var model = new ChargeViewModel(); model.ChargeId = charge.Id; model.CustomerId = charge.CustomerId; return(View("OrderStatus", model)); }
public async Task <IActionResult> MakePayment(IFormCollection collection, double paymentAmount, Models.Order order) { StripeConfiguration.ApiKey = APIKeys.StripeSecretKey; var options = new ChargeCreateOptions { Amount = (long)paymentAmount * 100, Currency = "usd", Source = "tok_visa", Description = "My First Test Charge (created for API docs)", }; var service = new ChargeService(); service.Create(options); var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); Models.Order payForOrder = db.Orders.OrderByDescending(o => o.OrderId).FirstOrDefault(); payForOrder.PaymentAmount += paymentAmount; db.Orders.Update(payForOrder); await db.SaveChangesAsync(); return(RedirectToAction("CheckoutComplete")); }
public IActionResult Details(string stripeToken) { OrderHeader orderHeader = _unitOfWork.OrderHeader.GetFirstOrDefault(u => u.Id == OrderVM.OrderHeader.Id, includeProperties: "ApplicationUser"); if (stripeToken != null) { //process the payment var options = new ChargeCreateOptions { Amount = Convert.ToInt32(orderHeader.OrderTotal * 100), Currency = "usd", Description = "Order ID : " + orderHeader.Id, Source = stripeToken }; var service = new ChargeService(); Charge charge = service.Create(options); if (charge.Id == null) { orderHeader.PaymentStatus = SD.PaymentStatusRejected; } else { orderHeader.TransactionId = charge.Id; } if (charge.Status.ToLower() == "succeeded") { orderHeader.PaymentStatus = SD.PaymentStatusApproved; orderHeader.PaymentDate = DateTime.Now; } _unitOfWork.Save(); } return(RedirectToAction("Details", "Order", new { id = orderHeader.Id })); }
// Uses Stripe to Make Payment bool MakePayment(string token, int orderId, string desc, List <CartItem> cart) { // Set your secret key: remember to change this to your live secret key in production // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.SetApiKey(Data._stripeSercret); //// Token is created using Checkout or Elements! //// Get the payment token submitted by the form: //var token = model.Token; // Using ASP.NET MVC var options = new ChargeCreateOptions { Amount = (int)(GetTotal(cart) * 100), Currency = "usd", Description = desc, SourceId = token, Metadata = new Dictionary <string, string>() { { "OrderId", orderId.ToString() } } }; // Charge Card var service = new ChargeService(); Charge charge; try { charge = service.Create(options); } catch (StripeException ex) { lbError.Text = "There was an error with your payment. If your payment information seems correct, contact your " + "cardholder directly by phone to solve the issue. Reason: " + ErrorStripe(ex); return(false); // Exit } if (charge.Status != "succeeded") { lbError.Text = "There was an error with your payment information"; return(false); } // Return True return(true); }
public PaymentGatewayResponse CheckOutTwoCheckOut(ChargeAuthorizeServiceOptions charge) { TwoCheckoutConfig.SellerID = ConfigurationManager.AppSettings["TwoCheckOutSellerId"]; TwoCheckoutConfig.PrivateKey = ConfigurationManager.AppSettings["TwoCheckOutPrivateKey"];; TwoCheckoutConfig.Sandbox = true; var _res = new PaymentGatewayResponse(); try { var Charge = new ChargeService(); var result = Charge.Authorize(charge); _res.amount = result.total; _res.refNo = result.transactionId.ToString(); _res.responseStatus = result.responseCode; _res.message = result.responseMsg; if (charge.total == result.total) { _res.PaymentStatus = "paid"; } else if (charge.total > result.total) { _res.PaymentStatus = "partial"; } return(_res); } catch (Exception ex) { _res.responseStatus = "failed"; _res.message = ex.Message; return(_res); } }
public ActionResult UsePreloadedCard() //We can pass whatever we need here since current order can always be called { Models.Customer currentCustomer = GetLoggedInCustomer(); Models.Order currentOrder = db.Orders.FirstOrDefault(o => o.OrderId == currentCustomer.CurrentOrderId); StripeConfiguration.ApiKey = (APIKeys.StripeApiKey); // `source` is obtained with Stripe.js; see https://stripe.com/docs/payments/accept-a-payment-charges#web-create-token var options = new ChargeCreateOptions { Amount = Convert.ToInt64(currentOrder.OrderPrice * 100), Currency = "usd", Customer = currentCustomer.CustomerStripeId, Description = "Order for " + currentCustomer.FirstName + " " + currentCustomer.lastName, }; var service = new ChargeService(); Charge charge = service.Create(options); var model = new Cart(); model.ChargeId = charge.Id; return(RedirectToAction("UniqueIdScreen")); }
public Charge HandleCharge(TokenModel model, string PlanId) { var customers = new CustomerService(); var charges = new ChargeService(); var plan = GetPlans().FirstOrDefault(x => x.Id == PlanId); var customer = customers.Create(new CustomerCreateOptions { Email = model.email, SourceToken = model.id }); var charge = charges.Create(new ChargeCreateOptions { Amount = plan.Amount, Description = $"//productname {plan.Nickname}", Currency = "aud", CustomerId = customer.Id }); return(charge); }
public IActionResult Charge(string stripeEmail, string stripeToken) { 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 = 500, Description = "Sample Charge", Currency = "usd", CustomerId = customer.Id }); // ADD Content to Sponsered Section return(RedirectToAction("GetSponsor")); }
public ResultAndMessage ChargeCustomerToAccount(string BuyerCustId, string VendorAcctId, string StripeKey, decimal purchaseAmount, decimal smFee) { ResultAndMessage result = new ResultAndMessage(); // setting up the card var charge = new ChargeCreateOptions { // always set these properties ( ??? old Stripe comments - do we put amount in two places now??[see just below] Amount = purchaseAmount.ToPennies(), Currency = "usd", Description = "simple-market purchase", // set this property if using a customer Customer = BuyerCustId, // fund receiver Destination = new ChargeDestinationCreateOptions() { Account = VendorAcctId, Amount = purchaseAmount.ToPennies() }, // set this if you have your own application fees // (you must have your application configured first within Stripe) ApplicationFeeAmount = smFee.ToPennies() }; var chargeService = new ChargeService(); Charge stripeCharge = chargeService.Create(charge); result.success = true; return(result); }
//controller za payment public IActionResult OnPost(string stripeEmail, string stripeToken) { var customers = new CustomerService(); var charges = new ChargeService(); var CartOrder = new GetOrder(HttpContext.Session, _ctx).Do(); var customer = customers.Create(new CustomerCreateOptions { Email = stripeEmail, Source = stripeToken }); var charge = charges.Create(new ChargeCreateOptions { Amount = CartOrder.GetTotalCharge(), Description = "Shop Purchase", Currency = "eu", Customer = customer.Id }); return(RedirectToPage("/Index")); }
public async Task <StripeIdResponse> CreateCharge(string source, decimal amount, string description) { var chargeService = new ChargeService(); var charge = await chargeService.CreateAsync(new ChargeCreateOptions { SourceId = source, Amount = ConvertToStripePrice(amount), Description = description, Currency = VenusConsts.Currency, Capture = true }); if (!charge.Paid) { throw new UserFriendlyException(L("PaymentCouldNotCompleted")); } return(new StripeIdResponse { Id = charge.Id }); }
public async Task <IActionResult> Charge(string stripeEmail, string stripeToken) { ApplicationUser user = await this.userManager.GetUserAsync(this.User); AllOrdersByUserIdListViewModel viewModel = new AllOrdersByUserIdListViewModel { Orders = this.ordersService.GetAllByUserId <AllOrdersByUserIdViewModel>(user.Id), }; var customers = new CustomerService(); var charges = new ChargeService(); var customer = customers.Create(new CustomerCreateOptions { Email = stripeEmail, Source = stripeToken, }); var charge = charges.Create(new ChargeCreateOptions { Amount = (int)viewModel.Orders.Sum(o => o.CoursePrice) * 100, Description = "Sample Charge", Currency = "usd", Customer = customer.Id, }); foreach (var course in viewModel.Orders.Select(o => o.CourseId)) { await this.coursesService.EnrollAsync(course, user.Id); } foreach (var course in viewModel.Orders.Select(o => o.CourseId)) { await this.ordersService.DeleteAsync(course, user.Id); } return(this.Redirect($"/Courses/AllByUser/{user.Id}")); }
// Pattybranch added these for the stripe: New Method to take in 2 parameters in order to process the payment public IActionResult Charge(string stripeEmail, string stripeToken) { var customers = new CustomerService(); var charges = new ChargeService(); List <Watch> UserCart = HttpContext.Session.GetObjectFromJson <List <Watch> >("UserCart"); double CartAmount = 0; foreach (var w in UserCart) { CartAmount += w.Price; } var customer = customers.Create(new CustomerCreateOptions { Email = stripeEmail, Source = stripeToken }); var charge = charges.Create(new ChargeCreateOptions { Amount = Convert.ToInt64(CartAmount), Description = "Test Payment", Currency = "usd", Customer = customer.Id }); Console.WriteLine("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$444"); Console.WriteLine(charge.Amount); if (charge.Status == "succeeded") { string BalanceTransactionId = charge.BalanceTransactionId; return(View()); } else { } return(View()); }
public override ApiInfo GetStatus(Order order, IDictionary <string, string> settings) { try { order.MustNotBeNull("order"); settings.MustNotBeNull("settings"); settings.MustContainKey("mode", "settings"); settings.MustContainKey(settings["mode"] + "_secret_key", "settings"); var apiKey = settings[settings["mode"] + "_secret_key"]; ConfigureStripe(apiKey); // See if we have a payment intent ID to work from var paymentIntentId = order.Properties["stripePaymentIntentId"]; if (!string.IsNullOrWhiteSpace(paymentIntentId)) { var paymentIntentService = new PaymentIntentService(); var paymentIntentGetOptions = new PaymentIntentGetOptions(); var paymentIntent = paymentIntentService.Get(paymentIntentId, paymentIntentGetOptions); return(new ApiInfo(GetTransactionId(paymentIntent), GetPaymentState(paymentIntent))); } // No payment intent, so look for a charge ID if (!string.IsNullOrWhiteSpace(order.TransactionInformation.TransactionId)) { var chargeService = new ChargeService(); var charge = chargeService.Get(order.TransactionInformation.TransactionId); return(new ApiInfo(GetTransactionId(charge), GetPaymentState(charge))); } } catch (Exception exp) { LoggingService.Instance.Error <Stripe>("Stripe(" + order.OrderNumber + ") - GetStatus", exp); } return(null); }
public IActionResult Charge(string stripeEmail, string stripeToken) { var customers = new CustomerService(); var charges = new ChargeService(); var Amount = TempData["total"]; var order = TempData["orderId"]; var custmr = TempData["cust"]; var customer = customers.Create(new CustomerCreateOptions { Email = stripeEmail, SourceToken = stripeToken }); var charge = charges.Create(new ChargeCreateOptions { Amount = 500, Description = "Sample Charge", Currency = "usd", CustomerId = customer.Id }); Payments payment = new Payments(); { payment.StripePaymentId = charge.PaymentMethodId; payment.PaymentAmount = Convert.ToInt32(Amount); payment.DateOfPayment = System.DateTime.Now; payment.CardLastDigit = Convert.ToInt32(charge.PaymentMethodDetails.Card.Last4); payment.OrderId = Convert.ToInt32(order); payment.CustomerId = Convert.ToInt32(custmr); }; _context.Add <Payments>(payment); _context.Payments.Add(payment); _context.SaveChanges(); return(RedirectToAction("Invoice", "Cart")); }
public void PayOrder(PayViewModel payViewModel) { payViewModel.Total *= 100; var customers = new CustomerService(); var charges = new ChargeService(); var customer = customers.Create(new CustomerCreateOptions { Email = payViewModel.Email, Source = payViewModel.Token, }); var charge = charges.Create(new ChargeCreateOptions { Amount = payViewModel.Total, Description = "Test customer for [email protected]", Currency = "usd", Customer = customer.Id, ReceiptEmail = payViewModel.Email, Metadata = new Dictionary <string, string>() { { "OrderId", "111" }, { "Postcode", "LEE111" }, } }); if (charge.Status == "succeeded") { payViewModel.Total /= 100; payViewModel.Status = charge.Status; payViewModel.Created = charge.Created; payViewModel.BalanceTransactionId = charge.BalanceTransactionId; _orderService.Add(payViewModel); } else { throw new System.Exception($"{charge.FailureMessage}"); } }
public IActionResult PayOrder(string stripeEmail, string stripeToken) { var customerService = new CustomerService(); var chargeService = new ChargeService(); string userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var order = this._shoppingCartService.getShoppingCartInfo(userId); var customer = customerService.Create(new CustomerCreateOptions { Email = stripeEmail, Source = stripeToken }); var charge = chargeService.Create(new ChargeCreateOptions { Amount = (Convert.ToInt32(order.TotalPrice) * 100), Description = "EShop Application Payment", Currency = "usd", Customer = customer.Id }); if (charge.Status == "succeeded") { var result = this.Order(); if (result) { return(RedirectToAction("Index", "ShoppingCart")); } else { return(RedirectToAction("Index", "ShoppingCart")); } } return(RedirectToAction("Index", "ShoppingCart")); }
public IActionResult Processing(string stripeToken, string stripeEmail) { StripeConfiguration.ApiKey = "sk_test_ZxgfYV4PJz2m3gWvKXWFHxmv00XtyoLItH"; Dictionary <string, string> Metadata = new Dictionary <string, string>(); Metadata.Add("Product", "RubberDuck"); Metadata.Add("Quantity", "10"); var options = new ChargeCreateOptions { Amount = amount, Currency = "USD", Description = "Buying 10 rubber ducks", Customer = createCust("sk_test_ZxgfYV4PJz2m3gWvKXWFHxmv00XtyoLItH").Id,//i added //SourceId = stripeToken, ReceiptEmail = stripeEmail, Metadata = Metadata }; var service = new ChargeService(); Charge charge = service.Create(options); return(View()); }
public string CreatePayment(CreatePaymentModel model) { var NewCreditCardToken = storeCreditCardCommand.StoreCreditCard(new CreatePaymentModel() { Number = model.Number, ExpireMonth = model.ExpireMonth, ExpireYear = model.ExpireYear, Cvv = model.Cvv }); var myCharge = new ChargeCreateOptions { Amount = model.Money * 100, Currency = "usd", Source = NewCreditCardToken }; var chargeService = new ChargeService(); var stripeCharge = chargeService.Create(myCharge); return(stripeCharge.Status); }
public IActionResult Charge(string stripeEmail, string stripeToken) { var customers = new CustomerService(); var charges = new ChargeService(); var customer = customers.Create(new CustomerCreateOptions { Email = stripeEmail, Source = stripeToken }); var charge = charges.Create(new ChargeCreateOptions { Amount = 500,//charge in cents Description = "Sample Charge", Currency = "usd", Customer = customer.Id }); // further application specific code goes here return(View()); }
public ActionResult Create(string stripeToken) { try { StripeConfiguration.SetApiKey("sk_test_V9RzTIp0ZmbZ9jahRGcKukuj00hdQHoMb2"); var options = new ChargeCreateOptions { Amount = 2000, Currency = "dkk", Description = "Charge for [email protected]", SourceId = stripeToken // obtained with Stripe.js, }; var service = new ChargeService(); Charge charge = service.Create(options); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public override ApiInfo GetStatus(Order order, IDictionary <string, string> settings) { try { order.MustNotBeNull("order"); settings.MustNotBeNull("settings"); settings.MustContainKey("mode", "settings"); settings.MustContainKey(settings["mode"] + "_secret_key", "settings"); var apiKey = settings[settings["mode"] + "_secret_key"]; var chargeService = new ChargeService(apiKey); var charge = chargeService.Get(order.TransactionInformation.TransactionId); return(new ApiInfo(charge.Id, GetPaymentState(charge))); } catch (Exception exp) { LoggingService.Instance.Error <Stripe>("Stripe(" + order.OrderNumber + ") - GetStatus", exp); } return(null); }
//function used to charge the customer private void ChargeCustomer(string paymentToken, decimal RentTotal, string email) { //defined api key to identify one self to strip StripeConfiguration.ApiKey = "sk_test_wGglOzyHYIB92w1Pv5LAUtTD00pF5tUIbg"; var options = new ChargeCreateOptions() { //specifies the amount to charge Amount = Convert.ToInt64(RentTotal * 100), //specifies currency Currency = "USD", //specifies customer credit card Source = paymentToken, //also sents customers email to strip for additional identification Metadata = new Dictionary <string, string>() { { "CustomerEmail", email } } }; //charges the customer var service = new ChargeService(); Charge charge = service.Create(options); }
public async Task <IEnumerable <TransactionDTO> > Execute(PaymentModel payment) { var customer = await _paymentRepository.GetLastTransaction(payment.OrderId); var service = new ChargeService(); var orderInfo = new PaymentModel { UserId = customer.UserId, VendorId = customer.VendorId, OrderId = customer.OrderId, Amount = customer.Amount }; if (!customer.TransactionType.ToUpper().Equals(PaymentServiceConstants.PaymentType.Auth.ToString().ToUpper())) { throw new Exception("Server can not find auth transaction");//TODO: треба ще ексепшин хендлінг } var transaction = await _retryHelper.RetryIfThrown(async() => { var result = await service.CaptureAsync(customer.ExternalId, null); return(_mappingProvider.GetMappingOperation(PaymentServiceConstants.PaymentMappingType.Stripe_Succeeded) .Map(PaymentServiceConstants.PaymentType.Capture, orderInfo, result, result.Created)); }, PaymentServiceConstants.PaymentType.Capture, orderInfo, PaymentServiceConstants.isSucceeded.Succeeded); return(await _paymentRepository.CreateTransactions(transaction)); }
public IActionResult Create(string stripeToken, int Id) { List <ShoppingBasketItem> basket = SessionHelper.GetObjectFromJson <List <ShoppingBasketItem> >(HttpContext.Session, "basket"); double d = GetTotal(); var chargeOptions = new ChargeCreateOptions() { Amount = (long)d * 100, Currency = "ron", Source = stripeToken, }; var service = new ChargeService(); Charge charge = service.Create(chargeOptions); if (charge.Status == "succeeded") { return(View("Success")); } return(View("Failure")); }
public ActionResult Charge(string stripeEmail, string stripeToken) { var customers = new CustomerService(); var charges = new ChargeService(); var customer = customers.Create(new CustomerCreateOptions { Email = stripeEmail, Source = stripeToken }); var charge = charges.Create(new ChargeCreateOptions { Amount = 50, Description = "Verification Payment", Currency = "usd", Customer = customer.ToString() }); if (charge.Status == "succeeded") { string BalanceTransactionId = charge.BalanceTransactionId; } return(View()); }
public IActionResult Charge(string stripeEmail, string stripeToken, Bill bill) { var customers = new CustomerService(); var charges = new ChargeService(); var customer = customers.Create(new CustomerCreateOptions { Email = stripeEmail, Source = stripeToken }); long totalAmount = Convert.ToInt64(bill.TotalAmount); var charge = charges.Create(new ChargeCreateOptions { Amount = (totalAmount * 100),//charge in cents Description = "The Common Room Bill Payment", Currency = "usd", Customer = customer.Id }); // further application specific code goes here return(View()); }
public IActionResult Charge(string stripeEmail, string stripeToken) { 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 = 500, Description = "Sample Charge", Currency = "usd", CustomerId = customer.Id }); _context.Events.Where(e => e.Id == (string)TempData["EventId1"]).Single().Premium = 1; _context.SaveChanges(); return(View("ChargeConfirmation")); }