Example #1
0
        public ActionResult <PaymentMethod> RetrieveCustomerPaymentMethod([FromBody] RetrieveCustomerPaymentMethodRequest req)
        {
            var service       = new PaymentMethodService();
            var paymentMethod = service.Get(req.PaymentMethod);

            return(paymentMethod);
        }
Example #2
0
        public ActionResult <Stripe.PaymentMethod> RetrieveCustomerPaymentMethod([FromBody] string PaymentMethod)
        {
            var service       = new PaymentMethodService();
            var paymentMethod = service.Get(PaymentMethod);

            return(paymentMethod);
        }
        public ActionResult HandleCardPaymentComplete(StripePayment model)
        {
            StripeConfiguration.ApiKey = ConfigurationManager.AppSettings["Cashier:Stripe:Secret"];

            var paymentIntent = PaymentService.GetPaymentIntentByTransactionRef(model.TransactionReference);
            var service       = new PaymentIntentService();

            ExStripe.PaymentIntent stripePI = null;
            if (paymentIntent.MotoMode == true)
            {
                //if it's a moto payment, we need to create the payment intent from
                var servicePM     = new PaymentMethodService();
                var paymentMethod = servicePM.Get(model.StripePaymentIntentId);
                var piCreate      = new PaymentIntentCreateOptions
                {
                    Amount               = (long)paymentIntent.Amount * 100,
                    Currency             = paymentIntent.Currency,
                    Description          = paymentIntent.Description,
                    Confirm              = true,
                    PaymentMethod        = model.StripePaymentIntentId,
                    PaymentMethodOptions = new PaymentIntentPaymentMethodOptionsOptions
                    {
                        Card = new PaymentIntentPaymentMethodOptionsCardOptions
                        {
                            Moto = true
                        }
                    }
                };
                piCreate.Metadata = new Dictionary <string, string>
                {
                    { "TransactionReference", paymentIntent.TransactionReference }
                };
                try
                {
                    stripePI = service.Create(piCreate);
                }
                catch (StripeException ex)
                {
                    stripePI = ex.StripeError.PaymentIntent;
                }

                model.StripePaymentIntentId = stripePI.Id;
            }


            stripePI = stripePI ?? service.Get(model.StripePaymentIntentId);

            if (stripePI.Status == "succeeded" && stripePI.Metadata["TransactionReference"] == model.TransactionReference)
            {
                PaymentService.UpdatePaymentStatus(model.TransactionReference, model.StripePaymentIntentId, PaymentStatus.Succeeded);


                return(Redirect(paymentIntent.ConfirmationPageUrl));
            }

            PaymentService.UpdatePaymentStatus(model.TransactionReference, model.StripePaymentIntentId, PaymentStatus.Failed);

            return(Redirect(paymentIntent.FailurePageUrl));
        }
Example #4
0
        public ActionResult <Charge> ChargeCustomer(string sessionId)
        {
            try
            {
                // Retrieve Session

                var sessionService = new SessionService(_client);
                var session        = sessionService.Get("cs_test_c1FLnMmlumB6lwsmH0ZjgwA3F0VWfMy9idVRTysO5adsZMbCKxSti3wUx3");

                // Retrieve Customer

                var customerService = new CustomerService(_client);
                var customer        = customerService.Get(session.CustomerId);

                // Retrieve SetupIntent

                var setupIntentService = new SetupIntentService(_client);
                var setupIntent        = setupIntentService.Get(session.SetupIntentId);

                // Retrieve PaymentMethod

                var paymentMethodService = new PaymentMethodService(_client);
                var paymentMethod        = paymentMethodService.Get(setupIntent.PaymentMethodId);


                var paymentIntentOptions = new PaymentIntentCreateOptions
                {
                    Amount        = 2300,
                    Currency      = "usd",
                    Confirm       = true,
                    Customer      = customer.Id,
                    PaymentMethod = paymentMethod.Id
                };
                var paymentIntentService = new PaymentIntentService(_client);
                var intent = paymentIntentService.Create(paymentIntentOptions);



                return(Json(intent.ClientSecret));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }