コード例 #1
0
        public string Refund(string toggleRefund)
        {   //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
            //sk_test_51Gzaa1HAh8lBnQxza9cOAzY7LbfgQ4FWX2sYqiuHsoVWJg4mNDppueQkAVd0XIPU4GhcrNBca8aemNgr24m4jDv200ooFw0Bhz
            StripeConfiguration.ApiKey = "sk_test_51Gzaa1HAh8lBnQxza9cOAzY7LbfgQ4FWX2sYqiuHsoVWJg4mNDppueQkAVd0XIPU4GhcrNBca8aemNgr24m4jDv200ooFw0Bhz";
            var msg = "";

            if (toggleRefund == "refund")
            {
                var refunds       = new RefundService();
                var refundOptions = new RefundCreateOptions
                {
                    PaymentIntent = "pi_1GzxFMHAh8lBnQxzpA2OSATN"
                };
                var refund = refunds.Create(refundOptions);
                msg = "Payment refunded successfully";
            }

            else if (toggleRefund == "cancelRefund")
            {
                var service = new PaymentIntentService();
                var options = new PaymentIntentCancelOptions {
                };
                var intent  = service.Cancel("pi_1GzxFMHAh8lBnQxzpA2OSATN", options);
                msg = "Payment refund cancelled";
            }
            //ViewBag.message = msg;
            return(msg);
        }
コード例 #2
0
        public async Task <bool> ReleasePaymentIntentAsync(string paymentIntentId)
        {
            var paymentService = new PaymentIntentService();
            var options        = new PaymentIntentCancelOptions()
            {
                CancellationReason = "abandoned"
            };
            var res = await paymentService.CancelAsync(paymentIntentId, options, GetRequestOptions());

            return(res.Status.Equals("canceled"));
        }
コード例 #3
0
        public PaymentIntent Cancel(string paymentId,
                                    string userId,
                                    long orderId,
                                    long transactionId,
                                    Guid correlationId)
        {
            var service = new PaymentIntentService();
            var options = new PaymentIntentCancelOptions {
            };

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

            return(intent);
        }
コード例 #4
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" },
                },
            };
        }
コード例 #5
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" },
                },
            };
        }
コード例 #6
0
        public override ApiInfo CancelPayment(Order order, IDictionary <string, string> settings)
        {
            try
            {
                order.MustNotBeNull("order");
                settings.MustNotBeNull("settings");
                settings.MustContainKey("mode", "settings");
                settings.MustContainKey(settings["mode"] + "_secret_key", "settings");

                // Try canceling the payment intent
                var stripePaymentIntentId = order.Properties["stripePaymentIntentId"];
                if (!string.IsNullOrWhiteSpace(stripePaymentIntentId))
                {
                    var apiKey = settings[settings["mode"] + "_secret_key"];

                    ConfigureStripe(apiKey);

                    var service = new PaymentIntentService();
                    var options = new PaymentIntentCancelOptions();
                    var intent  = service.Cancel(stripePaymentIntentId, options);

                    return(new ApiInfo(GetTransactionId(intent), GetPaymentState(intent)));
                }

                // If there is a transaction ID (a charge) then it's too late to cancel
                // so we just attempt to refund it
                if (order.TransactionInformation.TransactionId != null)
                {
                    return(RefundPayment(order, settings));
                }
            }
            catch (Exception exp)
            {
                LoggingService.Instance.Error <Stripe>("Stripe(" + order.OrderNumber + ") - RefundPayment", exp);
            }

            return(null);
        }