-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.php
129 lines (108 loc) · 3.63 KB
/
example.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
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
<?php
/**
* Example Usage.
*
* Docs:
* API: https://developer.intuit.com/docs/api/
* API Sample Code: https://github.com/IntuitDeveloperRelations/SampleCodeSnippets/tree/master/APISampleCode/V3QBO
* SDK Docs: https://github.com/intuit/QuickBooks-V3-PHP-SDK/blob/master/README.md
*/
/**
* The `qbo_connect_initiated` hook is called when a proper authenticated connection is established.
*/
function example_qp_api_connect_iniated( $api ) {
$data_service = $api->get_qb_data_service();
$message = qp_api_get_company_info( $data_service );
$message .= qp_api_query_customer( $data_service, 'ACME Company' );
$message .= qp_api_create_customer( $data_service, array(
'BillAddr' => array(
'Line1' => '1 Infinite Loop',
'City' => 'Cupertino',
'Country' => 'USA',
'CountrySubDivisionCode' => 'CA',
'PostalCode' => '95014'
),
'Notes' => 'Test... cras justo odio, dapibus ac facilisis in, egestas eget quam.',
'GivenName' => 'Justin',
'FamilyName' => 'Sternberg',
'FullyQualifiedName' => 'Zao',
'CompanyName' => 'Zao',
'DisplayName' => 'Zao',
'PrimaryPhone' => array(
'FreeFormNumber' => '(408) 606-5775'
),
'PrimaryEmailAddr' => array(
'Address' => 'jt@example.com',
)
) );
wp_die( $message );
}
add_action( 'qbo_connect_initiated', 'example_qp_api_connect_iniated' );
function qp_api_get_company_info( $data_service ) {
$company = $data_service->get_company_info();
if ( is_wp_error( $company ) ) {
return wpautop( $company->get_error_message() );
}
$props = array();
foreach ( get_object_vars( $company ) as $prop_name => $prop_value ) {
$props[] = '<tr><td>'. print_r( $prop_name, true ) .'</td><td>'. print_r( $prop_value, true ) .'</td></tr>';
}
$message = '
<h2>Get Company Info</h2>
<table class="wp-list-table widefat">
<thead>
<tr>
<th>Connected Company Name</th>
<th>Connected Company ID</th>
</tr>
</thead>
<tbody>
<tr>
<td>'. esc_html( $company->CompanyName ) .'</td>
<td>'. esc_html( $company->Id ) .'</td>
</tr>
</tbody>
</table>
<br>
<table class="wp-list-table widefat">
<thead>
<tr>
<th>Company Property:</th>
<th>Company Property Value:</th>
</tr>
</thead>
<tbody>
'. implode( "\n", $props ) .'
</tbody>
</table>
';
return $message;
}
function qp_api_query_customer( $data_service, $company_name_to_search ) {
global $wpdb;
$query = $wpdb->prepare(
"SELECT * FROM Customer WHERE CompanyName = %s",
$company_name_to_search
);
$customers = $data_service->query( $query );
$error = $data_service->getLastError();
$message = '<h2>Query Customer: ' . $company_name_to_search . '</h2>';
if ( $error ) {
$message .= '<p>The Status code is: ' . $error->getHttpStatusCode() . '</p>';
$message .= '<p>The Helper message is: ' . $error->getOAuthHelperError() . '</p>';
$message .= '<p>The Response message is: ' . $error->getResponseBody() . '</p>';
$message .= '<p>Intuit Error Type: ' . $error->getIntuitErrorType() . '</p>';
$message .= '<p>Intuit Error Code: ' . $error->getIntuitErrorCode() . '</p>';
$message .= '<p>Intuit Error Message: ' . $error->getIntuitErrorMessage() . '</p>';
$message .= '<p>Intuit Error Detail: ' . $error->getIntuitErrorDetail() . '</p>';
} else {
$message = print_r( $customers, true );
}
return $message;
}
function qp_api_create_customer( $data_service, $customer_args ) {
$message = '<h2>Create Customer</h2>';
list( $customer, $result ) = $data_service->create_customer( $customer_args );
$message .= print_r( compact( 'customer', 'result' ), true );
return $message;
}