Payment Integrations

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()
      {
          try
          {
                  client = new SquareClient.Builder()
                .Environment(Square.Environment.Sandbox)
                .AccessToken("Your Access Token")
                .Build();
              string idempotencyKey = NewIdempotencyKey();
              var amountMoney = new Money.Builder()
            .Amount(100L)
            .Currency("USD")
            .Build();

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


              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.

Sagar Rana

Sagar Rana is a Web Developer in Vision Infotech. He has strong skills and knowledge of ASP.NET C#, ASP.NET MVC, .Net Core, Jquery, JavaScript, WEB API, React.js, ADO.Net, Entity Framework, SQL and different integration like Xero, Stripe, Zoho CRM, Square, PayTM, PayKUN, RazorPay, Quickbook Desktop etc.

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

3 years ago