How To Send Payment From Quickbooks Online Using C#

In this blog, I will explain how to send a payment form .NET MVC web application using SDK.

Before using any Quickbooks online API we need access token, if you don’t know how to get access token then you can find it here.

We have to mention an Email address explicitly on which email address we have to send payment.

Below are a few steps to send a payment,

  • First, we have to create a ServiceContext with Auth tokens and realmId.
  • For that, we need access token and realmId
  • We have to get the payment from Quickbooks online by calling Payment order API.
  • We are querying a payment by ID.
  • For querying/get the payment we have to define QueryService
  • We need to pass the ServiceContext object into QueryService.
  • We will get payment details in objPaymentFound if there is a payment that exists with ID.
  • After that, We have to create a DataService object by passing a ServiceContext object as a parameter.
  • Now, we will check the email address in the objPaymentFound object.
  • Add objPaymentFound object and email in dataService.SendEmail<Payment>() as a parameter for sending a payment. we have to give an email on which we want to send a payment.
  • code is as below,
public ActionResult SendPaymentById(string PaymentID)
     {
         try
         {
             OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(Access_token);

             // Create a ServiceContext with Auth tokens and realmId
             ServiceContext serviceContext = new ServiceContext(RealmId, IntuitServicesType.QBO, oauthValidator);
             serviceContext.IppConfiguration.MinorVersion.Qbo = "23";
             serviceContext.IppConfiguration.BaseUrl.Qbo = QboBaseUrl;

             string EXISTING_PAYMENT_QUERYBYID = string.Format("select * from Payment where id = '{0}'", PaymentID);
             var queryService = new QueryService<Payment>(serviceContext);
             Payment objPaymentFound = queryService.ExecuteIdsQuery(EXISTING_PAYMENT_QUERYBYID).FirstOrDefault<Payment>();

             //If payment found on Quickbooks online
             if (objPaymentFound != null)
             {
                 DataService dataService = new DataService(serviceContext);

                 //we have to mention Email address explicitly, you can set ToEmail from database or somewhere else
                 String ToEmail = "tabishzrangrej.vision@gmail.com";
                 var SentPDF = dataService.SendEmail<Payment>(objPaymentFound, ToEmail);
                 ViewBag.IsSuccess = true;


             }
             return View();
         }
         catch (IdsException ex)
         {
             return View();
         }
         catch (Exception ex)
         {
             return View();
         }
     }
  • View Code is as below,
@{
    ViewBag.Title = "SendPaymentById";
}

<h2>Send Payment By Id</h2>



@if (ViewBag.IsSuccess != null && ViewBag.IsSuccess == true)
{
    <div class="row">
        <label class="label label-success"> Payment Sent Successfully </label>
    </div>
}
  • The above code will send a payment to the email.

You can also set a send email link in the list view of the payment. if you don’t know how to get payment from Quickbooks Online you can find it here.

  • View Code(cshtml) of the payment list with the Send email link is as below.
@model List<Intuit.Ipp.Data.Payment>

@{
    ViewBag.Title = "GetAllPayment";
}

<h2>Quickbooks online Payment List</h2>

<div>
    <table class="table table-bordered">
        <tr>
            <th>QBO ID</th>
            <th>Date</th>
            <th>Customer Name</th>
            <th>Total Amount</th>
            <th style="text-align:center;">Download</th>
            <th style="text-align:center;">Send Email</th>
        </tr>

        @foreach (var PaymentItem in Model)
        {
        <tr>
            <td>@PaymentItem.Id</td>
            <td>@PaymentItem.TxnDate.ToShortDateString()</td>
            <td>@PaymentItem.CustomerRef.name</td>
            <td>@PaymentItem.TotalAmt</td>
            <td style="text-align:center;"><a href="@Url.Action("GetPaymentPdfById", "Home", new { PaymentID = PaymentItem.Id })" target="_blank"><img src="~/Content/Images/downloadICON.png" height="25" width="25" /></a></td>
            <td style="text-align:center;"><a href="@Url.Action("SendPaymentById", "Home", new { PaymentID = PaymentItem.Id })" target="_blank"><img src="~/Content/Images/SendImageICON.png" height="25" width="25" /></a></td>
        </tr>
        }

    </table>
</div>
  • In the above code, on click of send email icon payment will be sent.

OUTPUT:

  • Payment List

  • View of SendPaymentById

 

Submit a Comment

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

Subscribe

Select Categories