Beispiel #1
0
        public async Task <IActionResult> InitiateStripePayment()
        {
            // Load the session booking
            var sessionBooking = HttpContext.Session.Get <Booking>("Booking");

            if (sessionBooking == null)
            {
                HttpContext.Session.Set("Booking", new Booking());
                sessionBooking = HttpContext.Session.Get <Booking>("Booking");
            }

            // Load the session booking's spots for the displaying of information
            sessionBooking = await _bookingService.LoadSpots(sessionBooking);

            // Convert from BookingLines to Stripe's SessionLineItemOptions class
            var sessionLines = ConvertBookingLinesToSessionLines(bookingLines: sessionBooking.BookingLines);

            // Set up Stripe's payment session options
            var options = new SessionCreateOptions
            {
                BillingAddressCollection = "required",
                PaymentMethodTypes       = new List <string>
                {
                    "card",
                },
                LineItems  = sessionLines,
                Mode       = "payment",
                SuccessUrl = Url.ActionLink("SaveBooking", "BookingFlow"),
                CancelUrl  = Url.ActionLink("ShoppingCart", "BookingFlow"),
            };
            var     service = new SessionService();
            Session session = service.Create(options);

            return(Json(new { id = session.Id }));
        }
Beispiel #2
0
        public SessionCreateOptions CreateRechargeSession(int userId, decimal Amount)
        {
            try
            {
                var options = new SessionCreateOptions
                {
                    PaymentMethodTypes = new List <string>
                    {
                        "card",
                    },
                    LineItems  = CreateRecharge(userId, Amount),
                    Mode       = "payment",
                    SuccessUrl = "https://localhost:44320/Recharge/Payment/Success?session_id={CHECKOUT_SESSION_ID}",
                    //SuccessUrl = "https://valhallaplanet.art/Recharge/Payment/Success?session_id={CHECKOUT_SESSION_ID}",
                    //CancelUrl = "https://valhallaplanet.art/Recharge/Payment/Cancel?session_id={CHECKOUT_SESSION_ID}",
                    CancelUrl = "https://localhost:44320/Recharge/Payment/Cancel?session_id={CHECKOUT_SESSION_ID}",
                };

                return(options);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public async Task <Session> CreateSessionAsync(string customerId, string accountId, string itemName, string itemDescription, decimal amount, decimal applicationFee, string successUrl, string cancelUrl)
        {
            var options = new SessionCreateOptions
            {
                Customer           = customerId,
                PaymentMethodTypes = new List <string> {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions> {
                    new SessionLineItemOptions {
                        Name        = itemName,
                        Description = itemDescription,
                        Amount      = (long)(amount * 100),
                        Currency    = "usd",
                        Quantity    = 1,
                    },
                },
                PaymentIntentData = new SessionPaymentIntentDataOptions
                {
                    Description          = itemName,
                    SetupFutureUsage     = "off_session",
                    ApplicationFeeAmount = (long)(applicationFee * 100),
                    //TransferData = new Stripe.Checkout.SessionPaymentIntentDataOptions
                    //{
                    //    Destination = accountId,
                    //}
                },
                SuccessUrl = successUrl,
                CancelUrl  = cancelUrl
            };

            var service = new  SessionService();

            return(await service.CreateAsync(options));
        }
Beispiel #4
0
        public Session CreateSession(StripeModel model)
        {
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        PriceData = new SessionLineItemPriceDataOptions
                        {
                            UnitAmount  = model.AmountAsLong,
                            Currency    = model.LocalisedCurrencyThreeLetters.ToLower(),
                            ProductData = new SessionLineItemPriceDataProductDataOptions
                            {
                                Name = model.Description,
                            },
                        },
                        Quantity = 1,
                    },
                },
                Mode       = "payment",
                SuccessUrl = model.SuccessUrl,
                CancelUrl  = model.CancelUrl
            };
            var service = new SessionService();

            return(service.Create(options));
        }
Beispiel #5
0
        public ActionResult CreateCheckoutSession()
        {
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card"
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        PriceData = new SessionLineItemPriceDataOptions
                        {
                            UnitAmount  = 100,
                            Currency    = "usd",
                            ProductData = new SessionLineItemPriceDataProductDataOptions
                            {
                                Name = "T-shirt"
                            },
                        },
                        Quantity = 1,
                    }
                },
                Mode       = "payment",
                SuccessUrl = "https://www.betterfrosting.com/about",
                CancelUrl  = "https://www.betterfrosting.com/"
            };

            var     service = new SessionService();
            Session session = service.Create(options);

            return(new JsonResult(new { id = session.Id }));
        }
Beispiel #6
0
        public async Task <IActionResult> Get()
        {
            StripeConfiguration.ApiKey = "sk_test_very_secret_should_come_from_azure_key_vault"; //Get it from your stripe dashboard

            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                    "ideal"
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        Name        = $"Pants with 3 legs",
                        Description = $"Pants for those who have 3 legs",
                        Amount      = 100, // 1 euro
                        Currency    = "eur",
                        Quantity    = 1
                    }
                },
                SuccessUrl = "https://localhost:5001/success?session_id={CHECKOUT_SESSION_ID}",
                CancelUrl  = "https://localhost:5001/failed"
            };

            var     service = new SessionService();
            Session session = await service.CreateAsync(options);

            return(Ok(session.Id));
        }
Beispiel #7
0
        public Session GetStripeSession()
        {
            StripeConfiguration.ApiKey = "sk_test_ujFk5C8DtykdgFolICYfbSKV00w0VhwNIu";
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card"
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        Name        = "Sang",
                        Description = "En sang sammensat af valgte lydklip",
                        Amount      = 29900,
                        Currency    = "dkk",
                        Quantity    = 1
                    }
                },

                SuccessUrl = Url.Action("Success", "Home", null, Request.Scheme),
                CancelUrl  = Url.Action("Index", "Home", null, Request.Scheme)
            };


            var service = new SessionService();


            return(service.Create(options));
        }
Beispiel #8
0
        private string GetStripeSessionId(int amount)
        {
            StripeConfiguration.SetApiKey("sk_test_908vWm5ejJGpuZ7AIpcyFfMh00DY9KOyeQ");

            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string> {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions> {
                    new SessionLineItemOptions {
                        Name        = "TechScreen360",
                        Description = "Candidate Screening",
                        Amount      = amount,
                        Currency    = "usd",
                        Quantity    = 1,
                    },
                },
                SuccessUrl = "https://www.techscreen360.com/Payment/Success",
                CancelUrl  = "https://www.techscreen360.com/Payment/Error",
            };

            var     service = new SessionService();
            Session session = service.Create(options);

            return(session.Id);
        }
        private Session CreateCheckoutSession(String priceId, String customerId)
        {
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        Price    = priceId,
                        Quantity = 1
                    },
                },
                Mode       = "subscription",
                SuccessUrl = DashboardUrl(),
                CancelUrl  = DashboardUrl(),
                Customer   = customerId,
            };

            var     service = new SessionService();
            Session session = service.Create(options);

            return(session);
        }
Beispiel #10
0
        public ActionResult CreateCheckoutSession()
        {
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                    "bacs_debit"
                },
                Mode       = "setup",
                Customer   = "cus_IDM9E5oSmBOkRA",
                SuccessUrl = "http://localhost:55333",
                CancelUrl  = "http://localhost:55333",
                Metadata   = new Dictionary <string, string>
                {
                }
            };

            var service = new SessionService();

            try
            {
                Session session = service.Create(options);
                return(Json(new { id = session.Id }));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public async Task <IActionResult> Charge(int bookingId)
        {
            long usdCurrency = (long)(await unitOfWork.BookingRepo.Find(b => b.BookingId == bookingId)).Price;
            var  domain      = configuration["Domain"];
            var  options     = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        PriceData = new SessionLineItemPriceDataOptions
                        {
                            UnitAmount  = 100 * usdCurrency,
                            Currency    = "usd",
                            ProductData = new SessionLineItemPriceDataProductDataOptions
                            {
                                Name = "Stubborn Attachments",
                            },
                        },
                        Quantity = 1,
                    },
                },
                Mode       = "payment",
                SuccessUrl = domain + "/Payment/OrderSuccess?session_id={CHECKOUT_SESSION_ID}&bookingId=" + bookingId,
                CancelUrl  = domain + "/MyBookings/Index",
            };
            var     service = new SessionService();
            Session session = service.Create(options);

            return(Json(new { id = session.Id }));
        }
        public async Task <IActionResult> CreateCheckoutSession()
        {
            // Create new Checkout Session for the order
            // Other optional params include:
            //  [billing_address_collection] - to display billing address details on the page
            //  [customer] - if you have an existing Stripe Customer ID
            //  [customer_email] - lets you prefill the email input in the form
            //  [automatic_tax] - to automatically calculate sales tax, VAT and GST in the checkout page
            //  For full details see https:#stripe.com/docs/api/checkout/sessions/create

            //  ?session_id={CHECKOUT_SESSION_ID} means the redirect will have the session ID set as a query param
            var options = new SessionCreateOptions
            {
                SuccessUrl = $"{this.options.Value.Domain}/success.html?session_id={{CHECKOUT_SESSION_ID}}",
                CancelUrl  = $"{this.options.Value.Domain}/canceled.html",
                Mode       = "payment",
                LineItems  = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        Quantity = long.Parse(Request.Form["quantity"]),
                        Price    = this.options.Value.Price,
                    },
                },
                // AutomaticTax = new SessionAutomaticTaxOptions { Enabled = true },
            };

            var service = new SessionService(this.client);
            var session = await service.CreateAsync(options);

            Response.Headers.Add("Location", session.Url);
            return(new StatusCodeResult(303));
        }
        public async Task<CreateCheckoutSessionResponse> CreateCheckoutSession([FromBody] CreateCheckoutSessionRequest req)
        {
            // Create new Checkout Session for the order
            // Other optional params include:
            //  [billing_address_collection] - to display billing address details on the page
            //  [customer] - if you have an existing Stripe Customer ID
            //  [customer_email] - lets you prefill the email input in the form
            //  For full details see https:#stripe.com/docs/api/checkout/sessions/create

            //  ?session_id={CHECKOUT_SESSION_ID} means the redirect will have the session ID set as a query param
            var options = new SessionCreateOptions
            {
                SuccessUrl = $"{this.options.Value.Domain}/success.html?session_id={{CHECKOUT_SESSION_ID}}",
                CancelUrl = $"{this.options.Value.Domain}/canceled.html",
                PaymentMethodTypes = new List<string> { "card" },
                Mode = "payment",
                LineItems = new List<SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        Quantity = req.Quantity,
                        Price = this.options.Value.Price,
                    },
                },
            };

            var service = new SessionService(this.client);
            var session = await service.CreateAsync(options);

            return new CreateCheckoutSessionResponse
            {
                SessionId = session.Id,
            };
        }
Beispiel #14
0
        public async Task <IActionResult> BuyAsync()
        {
            StripeConfiguration.ApiKey = "sk_test_p9SPI9sPLAegWEXL6fZ5MIDm009gl2HLo5";

            var options = new SessionCreateOptions {
                PaymentMethodTypes = new List <string> {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions> {
                    new SessionLineItemOptions {
                        Name        = "T-shirt",
                        Description = "Comfortable cotton t-shirt",
                        Amount      = 500,
                        Currency    = "usd",
                        Quantity    = 1,
                    },
                },
                PaymentIntentData = new SessionPaymentIntentDataOptions {
                    CaptureMethod = "manual",
                },
                SuccessUrl = "https://example.com/success",
                CancelUrl  = "https://example.com/cancel",
            };

            var     service = new SessionService();
            Session session = service.Create(options);

            return(Ok(session));
        }
Beispiel #15
0
        public async Task <string> CreatePayment(MemberModel member, PaymentModel payment, string successUrl, string cancelUrl)
        {
            StripeConfiguration.ApiKey = payment.ApiSecretKey;

            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        Name        = payment.Title,
                        Description = payment.Description,
                        Amount      = (int)(payment.Amount * 100),
                        Currency    = payment.CurrencyCode,
                        Quantity    = 1
                    },
                },
                CustomerEmail = member.Email,
                SuccessUrl    = successUrl,
                CancelUrl     = cancelUrl
            };

            var     service = new SessionService();
            Session session = await service.CreateAsync(options);

            return(session.Id);
        }
Beispiel #16
0
        async Task <string> IPaymentSessionFactory.CreateSubscriptionSession(string returnUrlBase, string customerId, IEnumerable <string> productIds, Dictionary <string, string> subscriptionMetadata)
        {
            var sessService            = new SessionService();
            var sessionCreationOptions = new SessionCreateOptions()
            {
                Customer  = customerId,
                Mode      = "subscription",
                LineItems = (from prod in productIds
                             select new SessionLineItemOptions()
                {
                    Price = prod,
                    Quantity = 1
                }).ToList(),
                SubscriptionData = new SessionSubscriptionDataOptions()
                {
                    Metadata = subscriptionMetadata
                },
                PaymentMethodTypes = new List <string>()
                {
                    "card"
                },
                SuccessUrl = returnUrlBase + "?result=success&session_id={CHECKOUT_SESSION_ID}",
                CancelUrl  = returnUrlBase + "?result=cancel"
            };

            var session = await sessService.CreateAsync(sessionCreationOptions);

            return(session.Id);
        }
Beispiel #17
0
        private Session GetCreateSession(SessionLineItemPriceDataOptions priceData, string user, string successUrl, string cancelUrl)
        {
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card"
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        PriceData = priceData,
                        Quantity  = 1,
                    }
                },
                Metadata = new Dictionary <string, string>
                {
                    { "SessionCreated", DateTime.UtcNow.ToString() },
                    { "Product", priceData?.Product },
                    { "ProductName", priceData?.ProductData?.Name }
                },
                ClientReferenceId = user,
                Mode       = "payment",
                SuccessUrl = successUrl,
                CancelUrl  = cancelUrl,
            };
            var     service = new SessionService();
            Session session = service.Create(options);

            return(session);
        }
Beispiel #18
0
        // GET: Payments
        public ActionResult Index()
        {
            // 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 = "sk_test_Ecr51dB2P6POTJ0dtUr48frT00NrTbCQzP";

            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string> {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    //Products
                    new SessionLineItemOptions {
                        Name        = "Rent",
                        Description = "Monthly Rent Payment",
                        Amount      = 600,
                        Currency    = "usd",
                        Quantity    = 1,
                    },
                },
                SuccessUrl = "https://example.com/success?session_id={CHECKOUT_SESSION_ID}",
                CancelUrl  = "https://example.com/cancel",
            };

            var     service = new SessionService();
            Session session = service.Create(options);

            return(View(session));
        }
Beispiel #19
0
        public ActionResult <string> CreateCheckoutSession([FromBody]  int Quantity)
        {
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "bacs_debit",
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        Price    = StripeOptions.Price,
                        Quantity = 1,
                    },
                },
                Mode = "payment",
                PaymentIntentData = new SessionPaymentIntentDataOptions
                {
                    SetupFutureUsage = "off_session",
                },

                SuccessUrl = StripeOptions.Domain + "/success.html?session_id={CHECKOUT_SESSION_ID}",
                CancelUrl  = StripeOptions.Domain + "/canceled.html",
            };

            var     service = new SessionService();
            Session session = service.Create(options);

            return(session.Id);
        }
        public async Task <CreateSessionResult> Handle(CreateSessionRequest request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = _options.Value.PaymentMethodTypes,
                SubscriptionData   = new SessionSubscriptionDataOptions
                {
                    Items = new List <SessionSubscriptionDataItemOptions>
                    {
                        new SessionSubscriptionDataItemOptions
                        {
                            Plan = request.Model.PlanId
                        }
                    },
                    DefaultTaxRates = _options.Value.TaxIds
                },
                SuccessUrl = "https://example.com/success?session_id={CHECKOUT_SESSION_ID}",
                CancelUrl  = "https://example.com/cancel"
            };
            var session = await _sessionService.CreateAsync(options, null, cancellationToken);

            CreateSessionResult result = new CreateSessionResult(session);

            return(result);
        }
Beispiel #21
0
        public async Task <BillingReference> CreateSession(Customer customer, string priceBillingId)
        {
            var opts = new SessionCreateOptions {
                PaymentMethodTypes = new List <string> {
                    "card"
                },
                Customer        = customer.BillingReference.BillingId,
                SetupIntentData = new SessionSetupIntentDataOptions()
                {
                    Metadata = new Dictionary <string, string> {
                        { "customer_id", customer.BillingReference.BillingId },
                    }
                },
                Mode       = "setup",
                SuccessUrl = config.SuccessUrl,
                CancelUrl  = config.CancelUrl
            };

            if (customer.Subscription != null)
            {
                opts.SetupIntentData.Metadata.Add("subscription_id", customer.Subscription.BillingReference.BillingId);
            }

            var session = await sessionService.CreateAsync(opts);

            return(BillingReference.CheckoutSession(session.Id));
        }
Beispiel #22
0
        public async Task <IActionResult> CreateSession(Guid id)
        {
            var trip = await _context.Trip.FindAsync(id);

            if (trip == null)
            {
                return(NotFound());
            }
            var options = new SessionCreateOptions
            {
                SuccessUrl         = $"https://localhost:5001/Trips/PaymentSuccess/{trip.TripId}/",
                CancelUrl          = $"https://localhost:5001/Trips/SignUp/{trip.TripId}",
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        Currency = "NZD",
                        Name     = trip.Name,
                        Amount   = (long)(trip.Price * 100),
                        Quantity = 1,
                    }
                },
                Mode = "payment",
            };
            var service = new SessionService();
            var session = service.Create(options);

            return(new JsonResult(new {
                Id = session.Id,
            }));
        }
Beispiel #23
0
        public async Task <string> CreateSession(List <StoreModel.Checkout.OrderItem> orderItems)
        {
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string> {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions> {
                    new SessionLineItemOptions {
                        Name        = "T-shirt",
                        Description = "Comfortable cotton t-shirt",
                        Amount      = 500,
                        Currency    = "usd",
                        Quantity    = 1,
                    },
                },
                SuccessUrl = "https://example.com/success?session_id={CHECKOUT_SESSION_ID}",
                CancelUrl  = "https://example.com/cancel",
            };

            var service = new SessionService();

            Session session = await service.CreateAsync(options).ConfigureAwait(false);

            return(session.Id);
        }
Beispiel #24
0
        public static Session CreateSession(string priceId)
        {
            StripeConfiguration.ApiKey = key;
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    // products
                    new SessionLineItemOptions
                    {
                        Price    = priceId ?? "price_1IeipfHIhuPseqDM21xFFUeJ",
                        Quantity = 1,
                    },
                },

                Mode       = "subscription",
                SuccessUrl = "https://localhost:44309/AdminSubscription/Success?session_id={CHECKOUT_SESSION_ID}", //websit,stripe will redirect to this
                CancelUrl  = "https://localhost:44309/AdminSubscription/Index",
            };
            var     service = new SessionService();
            Session session = service.Create(options);

            return(session);
        }
        public ActionResult Create()
        {
            var domain  = "http://localhost:3000/checkout";
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        PriceData = new SessionLineItemPriceDataOptions
                        {
                            UnitAmount  = 2000,
                            Currency    = "pln",
                            ProductData = new SessionLineItemPriceDataProductDataOptions
                            {
                                Name = "Stubborn Attachments",
                            },
                        },
                        Quantity = 1,
                    },
                },
                Mode       = "payment",
                SuccessUrl = domain + "?success=true",
                CancelUrl  = domain + "?canceled=true",
            };
            var     service = new SessionService();
            Session session = service.Create(options);

            return(Json(new { id = session.Id }));
        }
        public string CreatePaymentSession(Currency currency, int amount)
        {
            StripeConfiguration.ApiKey = _apiKey;

            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string> {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions> {
                    new SessionLineItemOptions {
                        Name        = "Donation",
                        Description = "A donation to keep the service running",
                        Amount      = amount,
                        Currency    = currency.IsoCode,
                        Quantity    = 1,
                    },
                },
                SuccessUrl = _successUrl,
                CancelUrl  = _cancelUrl,
            };

            var service = new SessionService();
            var session = service.Create(options);

            _logger.Log(LogLevel.Information, $"Payment Session [{session.Id}] created. Currency [{currency.IsoCode}], Amount [{amount}]");
            return(session.Id);
        }
Beispiel #27
0
        public SessionCreateOptions PrepareSession(BasketModel basket, decimal wallet, Barayand.DAL.Interfaces.IWalletHistoryRepository _walletrepository, int user)
        {
            try
            {
                var options = new SessionCreateOptions
                {
                    PaymentMethodTypes = new List <string>
                    {
                        "card",
                    },
                    LineItems  = AddProducts(basket, wallet, _walletrepository, user),
                    Mode       = "payment",
                    SuccessUrl = "https://localhost:44320/cart/payment/success?session_id={CHECKOUT_SESSION_ID}",
                    //SuccessUrl = "https://valhallaplanet.art/cart/payment/success?session_id={CHECKOUT_SESSION_ID}",
                    //CancelUrl = "https://valhallaplanet.art/cart/payment/cancel?session_id={CHECKOUT_SESSION_ID}",
                    CancelUrl = "https://localhost:44320/cart/payment/cancel?session_id={CHECKOUT_SESSION_ID}",
                };

                return(options);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public IHttpActionResult Create()
        {
            string        dictionaryString    = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            StringBuilder resultStringBuilder = new StringBuilder();
            var           random = new Random();

            for (int i = 0; i < 16; i++)
            {
                resultStringBuilder.Append(dictionaryString[random.Next(dictionaryString.Length)]);
                if (i == 3 || i == 7 || i == 11)
                {
                    resultStringBuilder.Append("-");
                }
            }

            var result = resultStringBuilder.ToString();

            var code = new Code()
            {
                Personal_Code = result,
                Status        = "Created",
            };

            db.Codes.Add(code);
            db.SaveChanges();

            var domain  = "http://localhost:3000/checkout";
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },

                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        PriceData = new SessionLineItemPriceDataOptions
                        {
                            UnitAmount  = 1600,
                            Currency    = "eur",
                            ProductData = new SessionLineItemPriceDataProductDataOptions
                            {
                                Name = "Code to access emailing system"
                            }
                        },
                        Quantity = 1
                    }
                },
                Mode       = "payment",
                SuccessUrl = domain + "?success=true&code=" + result,
                CancelUrl  = domain + "?success=false"
            };

            var     service = new SessionService();
            Session session = service.Create(options);

            return(Ok(session.Id));
        }
        public ActionResult CreateCheckoutSession()
        {
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        PriceData = new SessionLineItemPriceDataOptions
                        {
                            UnitAmount  = 2000,
                            Currency    = "usd",
                            ProductData = new SessionLineItemPriceDataProductDataOptions
                            {
                                Name = "T-shirt",
                            },
                        },
                        Quantity = 1,
                    },
                },
                Mode       = "payment",
                SuccessUrl = "http://localhost:5001/success",
                CancelUrl  = "http://localhost:5001/cancel",
            };

            var     service = new SessionService();
            Session session = service.Create(options);

            return(Json(new { id = session.Id }));
        }
Beispiel #30
0
        public ActionResult CreateCheckoutSession()
        {
            var customer = CreateNewCustomer();

            try

            {
                var options = new SessionCreateOptions
                {
                    PaymentMethodTypes = new List <string>
                    {
                        "card",
                    },
                    //Mode = "payment",
                    Mode       = "setup",
                    Customer   = customer.Value.Id, //"cus_IjwJcLvcrS45TD",
                    SuccessUrl = "https://example.com/success",
                    CancelUrl  = "https://example.com/cancel",
                };
                // post checkout session to stripe
                var sessionService  = new SessionService(_client);
                var checkOutSession = sessionService.Create(options);

                return(Json(checkOutSession.Id));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }