Exemplo n.º 1
0
        public override ApiResult CapturePayment(OrderReadOnly order, StripeCheckoutSettings settings)
        {
            // NOTE: Subscriptions aren't currently abled to be "authorized" so the capture
            // routine shouldn't be relevant for subscription payments at this point

            try
            {
                // We can only capture a payment intent, so make sure we have one
                // otherwise there is nothing we can do
                var paymentIntentId = order.Properties["stripePaymentIntentId"];
                if (string.IsNullOrWhiteSpace(paymentIntentId))
                {
                    return(null);
                }

                var secretKey = settings.TestMode ? settings.TestSecretKey : settings.LiveSecretKey;

                ConfigureStripe(secretKey);

                var paymentIntentService = new PaymentIntentService();
                var paymentIntentOptions = new PaymentIntentCaptureOptions
                {
                    AmountToCapture = AmountToMinorUnits(order.TransactionInfo.AmountAuthorized.Value),
                };
                var paymentIntent = paymentIntentService.Capture(paymentIntentId, paymentIntentOptions);

                return(new ApiResult()
                {
                    TransactionInfo = new TransactionInfoUpdate()
                    {
                        TransactionId = GetTransactionId(paymentIntent),
                        PaymentStatus = GetPaymentStatus(paymentIntent)
                    },
                    MetaData = new Dictionary <string, string>
                    {
                        { "stripeChargeId", GetTransactionId(paymentIntent) },
                        { "stripeCardCountry", paymentIntent.Charges?.Data?.FirstOrDefault()?.PaymentMethodDetails?.Card?.Country }
                    }
                });
            }
            catch (Exception ex)
            {
                Vendr.Log.Error <StripeCheckoutOneTimePaymentProvider>(ex, "Stripe - CapturePayment");
            }

            return(ApiResult.Empty);
        }
Exemplo n.º 2
0
        public PaymentIntent Capture(decimal?payAmount,
                                     string paymentId,
                                     string userId,
                                     long orderId,
                                     long transactionId,
                                     Guid correlationId)
        {
            var options = new PaymentIntentCaptureOptions
            {
                AmountToCapture = (long)(payAmount * 100)
            };
            var service = new PaymentIntentService();

            var intent = service.Capture(paymentId, options);

            return(intent);
        }
Exemplo n.º 3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            //StripeConfiguration.SetApiKey("");
            //var options = new ConnectionTokenCreateOptions { };
            //var service = new ConnectionTokenService();
            //ConnectionToken connectionToken = service.Create(options);

            Terminal.InitTerminal(Android.App.Application.Context, Com.Stripe.Stripeterminal.LogLevel.Verbose, new ConnectionTokenProvider(), new TerminalListener());
            DiscoveryConfiguration config = new DiscoveryConfiguration(0, DeviceType.Chipper2x, true);

            Terminal.Instance.DiscoverReaders(config, new DiscoveryListener(), new Callback());
            Com.Stripe.Stripeterminal.Reader reader = DiscoveryListener.readers[0];

            Terminal.Instance.ConnectReader(reader, new ReaderCallback());

            var paymentIntentService = new PaymentIntentService();
            var paymentIntentOptions = new PaymentIntentCreateOptions
            {
                Amount             = 1000,
                Currency           = "usd",
                PaymentMethodTypes = new List <string> {
                    "card_present"
                },
                CaptureMethod = "manual",
            };

            Terminal.Instance.RetrievePaymentIntent(
                paymentIntentService.Create(paymentIntentOptions).ClientSecret,
                new PaymentIntentCallback());

            Cancelable cancelable = Terminal.Instance.CollectPaymentMethod(PaymentIntentCallback.paymentIntent,
                                                                           new ReaderListener(),
                                                                           new PaymentIntentCallback());

            Terminal.Instance.ProcessPayment(PaymentIntentCallback.paymentIntent,
                                             new PaymentIntentCallback());

            var intent = paymentIntentService.Capture(PaymentIntentCallback.paymentIntent.Id, new PaymentIntentCaptureOptions());
        }
        public override ApiInfo CapturePayment(Order order, IDictionary <string, string> settings)
        {
            try
            {
                order.MustNotBeNull("order");
                settings.MustNotBeNull("settings");
                settings.MustContainKey("mode", "settings");
                settings.MustContainKey(settings["mode"] + "_secret_key", "settings");

                // We can only capture a payment intent, so make sure we have one
                // otherwise there is nothing we can do
                var paymentIntentId = order.Properties["stripePaymentIntentId"];
                if (string.IsNullOrWhiteSpace(paymentIntentId))
                {
                    return(null);
                }

                var apiKey = settings[settings["mode"] + "_secret_key"];

                ConfigureStripe(apiKey);

                var paymentIntentService = new PaymentIntentService();
                var paymentIntentOptions = new PaymentIntentCaptureOptions
                {
                    AmountToCapture = DollarsToCents(order.TransactionInformation.AmountAuthorized.Value),
                };
                var paymentIntent = paymentIntentService.Capture(paymentIntentId, paymentIntentOptions);

                return(new ApiInfo(GetTransactionId(paymentIntent), GetPaymentState(paymentIntent)));
            }
            catch (Exception exp)
            {
                LoggingService.Instance.Error <Stripe>("Stripe(" + order.OrderNumber + ") - GetStatus", exp);
            }

            return(null);
        }