How To Get Payments From Quickbooks Online Using C#

In this article, we will learn how to get payment from Quickbooks online in .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.

  • First, we have to create a ServiceContext with Auth tokens and realmId.
  • For that, we need access token and realmId
  • For getting payments, we have to define a QueryService object.
  • QueryService object needs a ServiceContext object as parameter.
  • So we have to create a Quickbooks QueryService using ServiceContext.
  • Here we are getting all payments from Quickbooks online, code is as below.
public ActionResult GetAllPayment()
{
  List<Payment> PaymentList = new List<Payment>();
  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;

    // Create a QuickBooks QueryService using ServiceContext
    QueryService<Payment> querySvc = new QueryService<Payment>(serviceContext);
    PaymentList = querySvc.ExecuteIdsQuery("SELECT * FROM Payment").ToList();

    return View(PaymentList);
  }
  catch (IdsException ex)
  {
    return View(PaymentList);
  }
  catch (Exception ex)
  {
    return View(PaymentList);
  }
}
  • We will get all the payment list in the PaymentList object.
  • View Code 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>
        </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>
            </tr>
        }

    </table>
</div>
  • We can also write a query according to our requirements, as like below
string EXISTING_PAYMENT_QUERYBYID = string.Format("select * from Payment where id = '{0}'", "157");
Payment objPaymentFound = queryService.ExecuteIdsQuery(EXISTING_PAYMENT_QUERYBYID).FirstOrDefault<Payment>();
  • it will return payment by id.
  • We will get a payment which id=”157” in the objPaymentFound object.

So that’s how we can get “payment” or query “payment”  from Quickbooks online.

Output:

4 Comments

  1. mayank

    how to get payment accourding invoices…can u help me?

    0
    0
    Reply
    1. mayank

      SELECT * FROM Payment where CustomerRef = ’66’

      0
      0
      Reply
  2. naved

    I need to get payement data customer name or date wise please suggest what i do for that.

    0
    0
    Reply
  3. Isuru

    These Tutorials are very helpful to me. But I am strugling with a problem reguarding get payment data relavant to the payment method.
    How we can get data relavant to the payment method which is done through checks? Payment method is not querrible.

    Thanks

    0
    0
    Reply

Submit a Comment

Your email address will not be published.

Subscribe

Select Categories