Search code examples
c#quickbooksquickbooks-online

Get the Payment method name from QuickBooks Online


The Payment information from QuickBooks online will only returns the PaymentMethodRef reference property with ID.

How can i get the payment method name, when requesting for the payment information from QBOE ?

For reference, added the code below.

Here the _paymentList[i].PaymentMethodRef.name is always empty and only it will have the _paymentList[i].PaymentMethodRef.id.

ServiceContext serviceContext = getServiceContext(companyID, operatorID);
          QueryService<Item> itemQueryService = new QueryService<Item>(serviceContext);
          DataService service = new DataService(serviceContext);
          Batch batch = service.CreateNewBatch();
          ServiceQBOnline_Payment Payment_info;

         batch.Add("select * from Payment where Id In " + TxnIds + " ORDERBY id startPosition " + BatchStartIdx + " MaxResults 100", "bID1");
         batch.Execute();


 intuitBatchResponse queryCustomerResponse = batch["bID1"];

 if (queryCustomerResponse.ResponseType == ResponseType.Query)
   {

    List<Payment> _paymentList = queryCustomerResponse.Entities.ToList().ConvertAll(item => item as Payment);         
    Response.PaymentExportSuccessList = new List<ServiceQBOnline_Payment>();

  for (int i = 0; i < _paymentList.Count; i++)
  {         
    Payment_info.PaymentMethod = _paymentList[i].PaymentMethodRef == null ? "" : _paymentList[i].PaymentMethodRef.name;
    Response.PaymentExportSuccessList.Add(Payment_info);
 }

Solution

  • Query the PaymentMethod list to get the full details:

    Example from the docs:

    SAMPLE QUERY
    select * from PaymentMethod
    

    You'll get something like this back:

    {
      "PaymentMethod": {
        "Name": "Diners Club",
        "Active": true,
        "Type": "CREDIT_CARD",
        "domain": "QBO",
        "sparse": false,
        "Id": "7",
        "SyncToken": "0",
        "MetaData": {
          "CreateTime": "2014-09-11T14:42:05-07:00",
          "LastUpdatedTime": "2014-09-11T14:42:05-07:00"
        }
      },
      "time": "2015-07-24T15:29:33.401-07:00"
    }