Beispiel #1
0
        public PaymentIntentServiceTest(
            StripeMockFixture stripeMockFixture,
            MockHttpClientFixture mockHttpClientFixture)
            : base(stripeMockFixture, mockHttpClientFixture)
        {
            this.service = new PaymentIntentService(this.StripeClient);

            this.cancelOptions = new PaymentIntentCancelOptions
            {
            };

            this.captureOptions = new PaymentIntentCaptureOptions
            {
                AmountToCapture = 123,
            };

            this.confirmOptions = new PaymentIntentConfirmOptions
            {
                ReceiptEmail = "*****@*****.**",
            };

            this.createOptions = new PaymentIntentCreateOptions
            {
                Amount             = 1000,
                Currency           = "usd",
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },
                TransferData = new PaymentIntentTransferDataOptions
                {
                    Amount      = 100,
                    Destination = "acct_123",
                },
            };

            this.listOptions = new PaymentIntentListOptions
            {
                Limit = 1,
            };

            this.updateOptions = new PaymentIntentUpdateOptions
            {
                Metadata = new Dictionary <string, string>
                {
                    { "key", "value" },
                },
            };
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public PaymentIntentServiceTest(MockHttpClientFixture mockHttpClientFixture)
            : base(mockHttpClientFixture)
        {
            this.service = new PaymentIntentService();

            this.cancelOptions = new PaymentIntentCancelOptions
            {
            };

            this.captureOptions = new PaymentIntentCaptureOptions
            {
                AmountToCapture = 123,
            };

            this.confirmOptions = new PaymentIntentConfirmOptions
            {
                SaveSourceToCustomer = true,
            };

            this.createOptions = new PaymentIntentCreateOptions
            {
                AllowedSourceTypes = new List <string>
                {
                    "card",
                },
                Amount       = 1000,
                Currency     = "usd",
                TransferData = new PaymentIntentTransferDataOptions
                {
                    Amount      = 100,
                    Destination = "acct_123",
                }
            };

            this.listOptions = new PaymentIntentListOptions
            {
                Limit = 1,
            };

            this.updateOptions = new PaymentIntentUpdateOptions
            {
                Metadata = new Dictionary <string, string>
                {
                    { "key", "value" },
                },
            };
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public async Task <bool> CapturePaymentIntentAsync(string paymentIntentId, MailAddress receiptEmail)
        {
            var paymentService = new PaymentIntentService();

            //add the receipt email
            var emailRes = await AddIntentReceiptEmail(paymentIntentId, receiptEmail);

            var options = new PaymentIntentCaptureOptions()
            {
                StatementDescriptorSuffix = "NowLeave.com"
            };

            try
            {
                var res = await paymentService.CaptureAsync(paymentIntentId, options, GetRequestOptions());

                return(res.Status.Equals("succeeded", StringComparison.InvariantCultureIgnoreCase));
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        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);
        }