Inheritance: Stripe.StripeService
Esempio n. 1
0
        /// <summary>
        ///     Implements <see cref="IStripeService.RefundCharge"/>
        /// </summary>
        public bool RefundCharge(string chargeId)
        {
            StripeRefundService refundService = new StripeRefundService();

            try
            {
                StripeRefund refund = refundService.Create(chargeId);

                return refund.Amount > 0;
            }
            catch (StripeException ex)
            {
                string message;
                StripeExceptionType type;

                if (ex.StripeError.ErrorType == "card_error")
                {
                    message = $"{ex.Message}. This occured while refunding payment. " + 
                        "Please contact customer support.";
                    type = StripeExceptionType.CardError;
                }
                else if (ex.HttpStatusCode == HttpStatusCode.Unauthorized)
                {
                    // Note: We want to log this as it means we don't have a valid API key
                    Debug.WriteLine("Stripe API Key is Invalid");
                    Debug.WriteLine(ex.Message);

                    type = StripeExceptionType.ApiKeyError;
                    message = "An error occurred while refunding payment. " +
                        "Please contact customer support.";
                }
                else
                {
                    type = StripeExceptionType.UnknownError;
                    message = "An error occurred while refunding payment. " +
                        "Please contact customer support.";
                }

                throw new StripeServiceException(message, type, ex);
            }
        }