Stripe.StripeRefundService.Create C# (CSharp) Method

Create() public method

public Create ( string chargeId, Stripe.StripeRefundCreateOptions createOptions = null, Stripe.StripeRequestOptions requestOptions = null ) : Stripe.StripeRefund
chargeId string
createOptions Stripe.StripeRefundCreateOptions
requestOptions Stripe.StripeRequestOptions
return Stripe.StripeRefund
        public virtual StripeRefund Create(string chargeId, StripeRefundCreateOptions createOptions = null, StripeRequestOptions requestOptions = null)
        {
            return Mapper<StripeRefund>.MapFromJson(
                Requestor.PostString(this.ApplyAllParameters(createOptions, $"{Urls.Charges}/{chargeId}/refunds", false),
                SetupRequestOptions(requestOptions))
            );
        }

Usage Example

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);
            }
        }