In this article, I will explain to you how to get “payment” as PDF and download it 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.
We will download payment pdf by payment ID.
For that, we have to get a “payment” form Quickbooks Online and call GetPdf function. it will return a byte array of pdf, we have to convert byte array to a pdf file and return pdf file to a user.
Below are a few steps to get “payment” as PDF,
public FileResult GetPaymentPdfById(string PaymentID) { byte[] PaymentPdfByteArray; 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); //it will return Byte Array of pdf PaymentPdfByteArray = dataService.GetPdf<Payment>(objPaymentFound); if (PaymentPdfByteArray != null) { //This is for unique name format like-"INVOICE-148-11_05_2019114648". var CurrentDate = DateTime.Now; var FileName = string.Format("{0}-{1}-{2}{3}{4}{5}{6}", "PAYMENT", PaymentID, CurrentDate.ToString("MM/dd/yyyy"), CurrentDate.ToString("HH"), CurrentDate.ToString("mm"), CurrentDate.ToString("ss"), ".pdf"); return File(PaymentPdfByteArray, "application/pdf", FileName); } } return null; } catch (IdsException ex) { return null; } catch (Exception ex) { return null; } }
You can set a download link in the list view of the payments. if you don’t know how to get payments from Quickbooks Online you can find it here.
@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> </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> </tr> } </table> </div>
OUTPUT:
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular