Implement billing features

If you want your app to utilize QuickBooks Online billing features, set up this basic billing implementation.

Step 1: Learn about basic accounting implementations

For your app’s implementations, make sure you pre-create entities so your app can reference them in transactions.

Transactions in QuickBooks frequently need to reference common entities like account, taxcode, and customer. If you have pre-created versions of common objects and entities, all your app needs to do is reference their IDs while creating transactions like invoices and bills.

If these entities don’t already exist, the transactions your app creates won’t have anything to reference. Referenced entities can’t be created on the fly within a transaction.

Step 2: Code the billing implementation

This implementation generally does the following:


Billing implementations

.NET

Java

PHP

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//Initialize OAuth2RequestValidator and ServiceContext
ServiceContext serviceContext = base.IntializeContext(realmId);
DataService dataService = new DataService(serviceContext);

//add Vendor
Vendor vendor = new Vendor();
vendor.DisplayName = "DisplayName_" + Guid.NewGuid().ToString("N");
Vendor vendorAdded = dataService.Add<Vendor>(vendor);

//add Bill
Bill bill = new Bill();
bill.VendorRef = new ReferenceType() {Value = vendorAdded.Id};
bill.APAccountRef = new ReferenceType() {Value = liabilityAccount.Id}; //query or add account

List<Line> lineList = new List<Line>();
Line line = new Line();
line.Amount = new Decimal(100.00);
line.AmountSpecified = true;
line.DetailType = LineDetailTypeEnum.AccountBasedExpenseLineDetail;
line.DetailTypeSpecified = true;

AccountBasedExpenseLineDetail detail = new AccountBasedExpenseLineDetail();
detail.AccountRef = new ReferenceType {Value = expenseAccount.Id}; //query or add account
line.AnyIntuitObject = detail;
lineList.Add(line);
bill.Line = lineList.ToArray();
Bill billadded = dataService.Add<Bill>(bill);

//make BillPayment
BillPayment billPayment = new BillPayment();
billPayment.VendorRef = new ReferenceType() {Value = vendorAdded.Id};

billPayment.PayType = BillPaymentTypeEnum.Check;
billPayment.PayTypeSpecified = true;
CheckPayment checkPayment = new CheckPayment();
checkPayment.AcctNum = "AcctNum" + Guid.NewGuid().ToString("N").Substring(0, 5);
checkPayment.BankName = "BankName" + Guid.NewGuid().ToString("N").Substring(0, 5);
checkPayment.CheckNum = "CheckNum" + Guid.NewGuid().ToString("N").Substring(0, 5);
checkPayment.NameOnAcct = "Name" + Guid.NewGuid().ToString("N").Substring(0, 5);
checkPayment.Status = "Status" + Guid.NewGuid().ToString("N").Substring(0, 5);
billPaymentCheck.CheckDetail = checkPayment;
billPayment.TotalAmt = 300;
billPayment.TotalAmtSpecified = true;

List<Line> lineList = new List<Line>();
Line line1 = new Line();
line1.Amount = billadded.TotalAmt;
line1.AmountSpecified = true;
List<LinkedTxn> LinkedTxnList1 = new List<LinkedTxn>();
LinkedTxn linkedTxn1 = new LinkedTxn();
linkedTxn1.TxnId = billadded.Id;
linkedTxn1.TxnType = TxnTypeEnum.Bill.ToString();
LinkedTxnList1.Add(linkedTxn1);
line1.LinkedTxn = LinkedTxnList1.ToArray();
lineList.Add(line1);
billPayment.Line = lineList.ToArray();
BillPayment billPaymentAdded = dataService.Add<BillPayment>(billPayment);

//add VendorCredit
VendorCredit vendorCredit = new VendorCredit();
vendorCredit.VendorRef = new ReferenceType() {Value = vendorAdded.Id};
vendorCredit.APAccountRef = new ReferenceType() {Value = liabilityAccount.Id};
List<Line> lineList = new List<Line>();
Line line = new Line();
line.Amount = new Decimal(100.00);
line.AmountSpecified = true;
line.DetailType = LineDetailTypeEnum.AccountBasedExpenseLineDetail;
line.DetailTypeSpecified = true;
line.AnyIntuitObject = new AccountBasedExpenseLineDetail() {
AccountRef = new ReferenceType() { Value = expenseAccount.Id }
};
lineList.Add(line);
vendorCredit.Line = lineList.ToArray();
VendorCredit vendorcreditAdded = dataService.Add<VendorCredit>(vendorCredit);
Tip: Some methods, like creating or querying accounts, are omitted in the sample for brevity. Visit our GitHub to see the complete code.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//create oauth object
OAuth2Authorizer oauth = new OAuth2Authorizer(accessToken);
//create context
Context context = new Context(oauth, ServiceType.QBO, realmId);
//create DataService
DataService service = new DataService(context);

//add vendor
Vendor vendor = new Vendor();
vendor.setDisplayName(RandomStringUtils.randomAlphanumeric(8));
Vendor savedVendor = service.add(vendor);

//add bill
Bill bill = new Bill();
bill.setVendorRef(createRef(savedVendor));

Account liabilityAccount = getLiabilityBankAccount(service); //query or create liability account
bill.setAPAccountRef(createRef(liabilityAccount));

Line line1 = new Line();
line1.setAmount(new BigDecimal("30.00"));
line1.setDetailType(LineDetailTypeEnum.ACCOUNT_BASED_EXPENSE_LINE_DETAIL);
AccountBasedExpenseLineDetail detail = new AccountBasedExpenseLineDetail();
Account account = getExpenseBankAccount(service); //query or create expense account
ReferenceType expenseAccountRef = createRef(account);
detail.setAccountRef(expenseAccountRef);
line1.setAccountBasedExpenseLineDetail(detail);
List<Line> lines1 = new ArrayList<Line>();
lines1.add(line1);
bill.setLine(lines1);
bill.setTotalAmt(new BigDecimal("30.00"));
Bill savedBill = service.add(bill);

//make bill payment
BillPayment billPayment = new BillPayment();
billPayment.setVendorRef(savedBill.getVendorRef());

Line line1 = new Line();
line1.setAmount(new BigDecimal("30"));
List<LinkedTxn> linkedTxnList1 = new ArrayList<LinkedTxn>();
LinkedTxn linkedTxn1 = new LinkedTxn();
linkedTxn1.setTxnId(savedBill.getId());
linkedTxn1.setTxnType(TxnTypeEnum.BILL.value());
linkedTxnList1.add(linkedTxn1);
line1.setLinkedTxn(linkedTxnList1);
List<Line> lineList = new ArrayList<Line>();
lineList.add(line1);
billPayment.setLine(lineList);

BillPaymentCheck billPaymentCheck = new BillPaymentCheck();
Account bankAccount = getCheckBankAccount(service); //query or create bank account
billPaymentCheck.setBankAccountRef(createRef(bankAccount));
billPaymentCheck.setCheckDetail(getCheckPayment());
billPayment.setCheckPayment(billPaymentCheck);
billPayment.setPayType(BillPaymentTypeEnum.CHECK);
billPayment.setTotalAmt(new BigDecimal("30"));
service.add(billPayment);

//add vendor credit
VendorCredit vendorCredit = new VendorCredit();
vendorCredit.setVendorRef(createRef(savedVendor));

Account account = getLiabilityBankAccount(service); //query or create liability account
vendorCredit.setAPAccountRef(createRef(account));

Line line1 = new Line();
line1.setAmount(new BigDecimal("30.00"));
line1.setDetailType(LineDetailTypeEnum.ACCOUNT_BASED_EXPENSE_LINE_DETAIL);
AccountBasedExpenseLineDetail detail = new AccountBasedExpenseLineDetail();
Account expenseAccount = getExpenseBankAccount(service); //query or create expense account
detail.setAccountRef(createRef(expenseAccount));
line1.setAccountBasedExpenseLineDetail(detail);
List<Line> lines1 = new ArrayList<Line>();
lines1.add(line1);
vendorCredit.setLine(lines1);
VendorCredit savedVendorCredit = service.add(vendorCredit);
Tip: Some methods, like creating or querying accounts, are omitted in the sample for brevity. Visit our GitHub to see the complete code.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
      //create dataservice
      $dataService->updateOAuth2Token($accessToken);

      //add Vendor
      $vendorRequestObj = Vendor::create(["DisplayName" => $vendorName . getGUID()]);
      $vendorResponseObj = $dataService->Add($vendorRequestObj);

      //add Bill
      $billCreate = Bill::create([
      "VendorRef" =>["value" =>$vendorRequestObj>Id],
      "Line" =>
         [
         [
            "Id" => "1",
            "Amount" => 200.00,
            "DetailType" => "AccountBasedExpenseLineDetail",
            "AccountBasedExpenseLineDetail" =>["AccountRef" =>["value" => $accountExpenseRef->Id]]
         ]
         ]
      ]);
      $bill = $dataService->Add($billCreate);

      //make BillPayment
      $billPayMentCreate = BillPayment::create([
      "VendorRef" =>["value" =>$vendorRequestObj>Id],
      "PayType" => "Check",
      "CheckPayment" => ["BankAccountRef" => ["value" => $bankaccountRef->Id]],
      "TotalAmt" => 200.00,
      "Line" => [
         [
            "Amount" => 200.00,
            "LinkedTxn" => [["TxnId" => $bill->Id]]
         ]
         ]
      ]);
      $billPayment = $dataService->Add($billPayMentCreate);

      //add VendorCredit
      $vendorCreditCreate= VendorCredit::create([
      "VendorRef" =>["value" =>$vendorRequestObj>Id],
      "TotalAmt" => 90.00,
      "Line" => [
            [
            "Amount" => 90.00,
            "DetailType" => "AccountBasedExpenseLineDetail",
            "AccountBasedExpenseLineDetail" =>["AccountRef" =>["value" =>$bankaccountRef->Id]]
            ]
      ]
      ]);
      $vendorCredit = $dataService->Add($vendorCreditCreate);
?>
Tip: Some methods, like creating or querying accounts, are omitted in the sample for brevity. Visit our GitHub to see the complete code.
Step 3: Set up other basic implementations

Depending on what basic QuickBooks features you want your app to utilize, you can set up other basic accounting implementations: