How To Refund Payment Using Square In ASP.NET MVC

In this article, we will learn how to Refund Payment using Square in ASP.NET Web application.

Let’s begin.

Please read this article first of all here.

Refund payment

You can refund the entire payment amount or a portion of it

C# Code Example

Open the HomeController.cshtml and add the below code in it.

     public ActionResult Index()
           return View();
      public async System.Threading.Tasks.Task<ActionResult> RefundProcessAsync()
                  client = new SquareClient.Builder()
                .AccessToken("Your Access Token")
              string idempotencyKey = NewIdempotencyKey();
              var amountMoney = new Money.Builder()

              var body = new RefundPaymentRequest.Builder(
                  idempotencyKey: idempotencyKey,
                  amountMoney: amountMoney,
                  paymentId: "Your Payment Id")

              var result = await client.RefundsApi.RefundPaymentAsync(body: body);
              return Json(new { IsSuccess = true, Message = "Refund Successfully." }, JsonRequestBehavior.AllowGet);
          catch (Exception ex)

              return Json(new
                  IsSuccess = false,
                  Message = ex.Message
              }, JsonRequestBehavior.AllowGet);
private static string NewIdempotencyKey()
          return Guid.NewGuid().ToString();

if you have any questions or issues about this article, please let me know. For More Information Here.

Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories