-
Notifications
You must be signed in to change notification settings - Fork 0
/
quickbooks_example.dart
201 lines (175 loc) · 5.6 KB
/
quickbooks_example.dart
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import 'dart:io';
import 'package:quickbooks/entities/entity.export.dart';
import 'package:quickbooks/environment/environment.export.dart';
import 'package:quickbooks/services/quickbooks_tax_rates.service.dart';
import 'package:quickbooks/services/services.export.dart';
/// Note that to run this example, you must have your environment variables set
void main() async {
var tokens = await oauthConnectExample();
await getCompanyExample(tokens);
await getCustomersExample(tokens);
await getCategoriesExample(tokens);
await getProductsExample(tokens);
await getInvoicesExample(tokens);
await getPaymentsExample(tokens);
await getAccountsExample(tokens);
await getPurchasesExample(tokens);
await getVendorsExample(tokens);
await getTaxRatesExample(tokens);
}
/// Example of how to use the oauth connection with Quickbooks.
///
/// If you don't provide the needed values, it will take it from environment variables.
Future<QuickbooksOauth2Tokens> oauthConnectExample(
{String? clientId,
String? clientSecret,
String? redirectUri,
bool? isProduction}) async {
//Init of the Oauth2 service
var service = QuickbooksOauth2Service(
clientId: clientId ?? QuickbooksEnvironment.clientId,
clientSecret: clientSecret ?? QuickbooksEnvironment.clientSecret,
redirectUrl: redirectUri ?? QuickbooksEnvironment.redirectUri,
isProduction: isProduction ?? QuickbooksEnvironment.isProduction,
);
String authUrl = await service.getAuthUrl();
// Prints the connection instructions in the console and
// gets the informations from the console entry
print('Please connect on the link below:\n');
print(authUrl);
print(
"\nAfter connecting, enter the code in the console. It is in que query parameters.");
print("The code:");
String? code = stdin.readLineSync();
print('You entered: $code');
print("Now, enter the realmId. It is also in the query parameters.");
print("The realmId:");
String? realmId = stdin.readLineSync();
print('You entered: $realmId');
print("Retrieving data");
// Gets the tokens from Quickbooks
QuickbooksOauth2Tokens value =
await service.getTokens(authorizationCode: code ?? "", realmId: realmId);
print('Oauth2 tokens');
print(value);
print('');
return value;
}
/// Gets and prints all the customers
Future getCustomersExample(QuickbooksOauth2Tokens tokens) async {
var accessToken = tokens.accessToken;
var service = QuickbooksCustomerService();
var value = await service.getAll(
accessToken: accessToken,
companyId: tokens.companyId!,
);
print('Customers');
print(value);
print('');
}
/// Gets and prints all the categories
Future getCategoriesExample(QuickbooksOauth2Tokens tokens) async {
var accessToken = tokens.accessToken;
var service = QuickbooksCategoriesService();
var value = await service.getAll(
accessToken: accessToken,
companyId: tokens.companyId!,
);
print('Categories');
print(value);
print('');
}
/// Gets and prints your company
Future getCompanyExample(QuickbooksOauth2Tokens tokens) async {
var accessToken = tokens.accessToken;
var service = QuickbooksCompanyService();
var value =
await service.get(accessToken: accessToken, companyId: tokens.companyId!);
print('Company');
print(value);
print('');
}
/// Gets and prints all the invoices
Future getInvoicesExample(QuickbooksOauth2Tokens tokens) async {
var accessToken = tokens.accessToken;
var service = QuickbooksInvoiceService();
var value = await service.getAll(
accessToken: accessToken,
companyId: tokens.companyId!,
);
print('Invoices');
print(value);
print('');
}
/// Gets and prints all the payments
Future getPaymentsExample(QuickbooksOauth2Tokens tokens) async {
var accessToken = tokens.accessToken;
var service = QuickbooksPaymentService();
var value = await service.getAll(
accessToken: accessToken,
companyId: tokens.companyId!,
);
print('Payments');
print(value);
print('');
}
/// Gets and prints all the products
Future getProductsExample(QuickbooksOauth2Tokens tokens) async {
var accessToken = tokens.accessToken;
var service = QuickbooksProductsService();
var value = await service.getAll(
accessToken: accessToken,
companyId: tokens.companyId!,
);
print('Products');
print(value);
print('');
}
/// Gets and prints all the accounts
Future getAccountsExample(QuickbooksOauth2Tokens tokens) async {
var accessToken = tokens.accessToken;
var service = QuickbooksAccountsService();
var value = await service.getAll(
accessToken: accessToken,
companyId: tokens.companyId!,
);
print('Accounts');
print(value);
print('');
}
/// Gets and prints all the purchases
Future getPurchasesExample(QuickbooksOauth2Tokens tokens) async {
var accessToken = tokens.accessToken;
var service = QuickbooksPurchasesService();
var value = await service.getAll(
accessToken: accessToken,
companyId: tokens.companyId!,
);
print('Purchases');
print(value);
print('');
}
/// Gets and prints all the vendors
Future getVendorsExample(QuickbooksOauth2Tokens tokens) async {
var accessToken = tokens.accessToken;
var service = QuickbooksVendorsService();
var value = await service.getAll(
accessToken: accessToken,
companyId: tokens.companyId!,
);
print('Vendors');
print(value);
print('');
}
/// Gets and prints all the tax rates
Future getTaxRatesExample(QuickbooksOauth2Tokens tokens) async {
var accessToken = tokens.accessToken;
var service = QuickbooksTaxRatesService();
var value = await service.getAll(
accessToken: accessToken,
companyId: tokens.companyId!,
);
print('Tax Rates');
print(value);
print('');
}