コード例 #1
0
        private string ProcessWebhookRequest(Order order, HttpRequest request, IDictionary <string, string> settings)
        {
            var apiKey        = settings[settings["mode"] + "_secret_key"];
            var webhookSecret = settings[settings["mode"] + "_webhook_secret"];

            ConfigureStripe(apiKey);

            var stripeEvent = GetWebhookStripeEvent(request, webhookSecret);

            if (stripeEvent.Type == "payment_intent.amount_capturable_updated")  // Occurs when payments are not auto captured and funds are authorized
            {
                var paymentIntent = (PaymentIntent)stripeEvent.Data.Object.Instance;

                FinalizeOrUpdateOrder(order, paymentIntent);
            }
            else if (stripeEvent.Type.StartsWith("charge."))
            {
                var charge = (Charge)stripeEvent.Data.Object.Instance;

                if (!string.IsNullOrWhiteSpace(charge.PaymentIntentId))
                {
                    var paymentIntentService    = new PaymentIntentService();
                    var paymentIntentGetOptions = new PaymentIntentGetOptions {
                    };
                    var paymentIntent           = paymentIntentService.Get(charge.PaymentIntentId, paymentIntentGetOptions);

                    FinalizeOrUpdateOrder(order, paymentIntent);
                }
            }

            return(null);
        }
コード例 #2
0
        public void GetWithClientSecret()
        {
            var options = new PaymentIntentGetOptions
            {
                ClientSecret = "pi_client_secret_123",
            };
            var intent = this.service.Get(PaymentIntentId, options);

            this.AssertRequest(HttpMethod.Get, "/v1/payment_intents/pi_123");
            Assert.NotNull(intent);
            Assert.Equal("payment_intent", intent.Object);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        async void placeOrder(object sender, System.EventArgs e)
        {
            var request = new HttpRequestMessage();

            request.RequestUri = new Uri("http://10.0.2.2:5000/api/v1/payment");

            request.Method = HttpMethod.Get;
            var client = new HttpClient();
            MultipartFormDataContent requestContent = new MultipartFormDataContent();
            StringContent            amountContent  = new StringContent("9923", Encoding.UTF8);

            requestContent.Add(amountContent, "amount");
            request.Content = requestContent;


            HttpResponseMessage response = await client.SendAsync(request);

            StripeConfiguration.ApiKey = "pk_test_j5YImiDFgybfafp8HuEkn6Ou00JtFKI0s9";

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                HttpContent content        = response.Content;
                var         responseString = await content.ReadAsStringAsync();

                var messageObj    = JsonConvert.DeserializeObject <message>(responseString);
                var client_secret = messageObj.client_secret;

                var service    = new PaymentIntentService();
                var getOptions = new PaymentIntentGetOptions
                {
                    ClientSecret = client_secret
                };
                PaymentIntent paymentIntent = service.Get(messageObj.id, getOptions);

                //var creditCardOptions = new CreditCardOptions
                //{
                //    Number = "4000 0000 0000 9995",
                //    Cvc = "333",
                //    ExpMonth = 02,
                //    ExpYear = 24,

                //};

                var paymentMethodCardCreateOption = new PaymentMethodCardCreateOptions {
                    //Insufficiant fund
                    //Number = "4000000000009995",
                    //Payment Succeed
                    //Number = "4242424242424242",
                    //Payment Require Authentication
                    //Number = "4000002500003155",
                    Number   = CreditCardNumber.Text,
                    Cvc      = CVC.Text,
                    ExpMonth = long.Parse(ExpMonth.Text),
                    ExpYear  = long.Parse(ExpYear.Text),
                };

                //var paymentMethodDataOption = new PaymentIntentPaymentMethodDataOptions
                //{
                //    Card = paymentMethodCardCreateOption,
                //    Type = "card",

                //};
                List <String> methodTypes = new List <String>();
                methodTypes.Add("pm_card_visa");
                var confirmOptions = new PaymentIntentConfirmOptions
                {
                    //PaymentMethod = "pm_card_visa",
                    PaymentMethodData = paymentMethodDataOption,

                    ClientSecret = client_secret,
                };
                try
                {
                    var status = service.Confirm(messageObj.id, confirmOptions);
                    if (status.Status == "succeeded")
                    {
                        await DisplayAlert("Request Sent!", "Our customer service will reach out to you in 3-5 bussiness days", "OK");
                    }
                    else
                    {
                        await DisplayAlert("Failed", "Please try another card", "OK");
                    }
                }
                catch (Exception)
                {
                    await DisplayAlert("Failed", "Please try another card", "OK");
                }


                //Console.WriteLine(status.Status);
            }
        }