|
6 | 6 | use QuickBooksOnline\API\DataService\DataService;
|
7 | 7 | use QuickBooksOnline\API\PlatformService\PlatformService;
|
8 | 8 | use QuickBooksOnline\API\Core\Http\Serialization\XmlObjectSerializer;
|
| 9 | +use QuickBooksOnline\API\Facades\Invoice; |
9 | 10 |
|
10 | 11 | // Prep Data Services
|
11 |
| -$dataService = DataService::Configure(array( |
12 |
| - 'auth_mode' => 'oauth1', |
13 |
| - 'consumerKey' => "lve2eZN6ZNBrjN0Wp26JVYJbsOOFbF", |
14 |
| - 'consumerSecret' => "fUhPIeu6jrq1UmNGXSMsIsl0JaHuHzSkFf3tsmrW", |
15 |
| - 'accessTokenKey' => "qye2etcpyquO3B1t8ydZJI8OTelqJCMiLZlY5LdX7qZunwoo", |
16 |
| - 'accessTokenSecret' => "2lEUtSEIvXf64CEkMLaGDK5rCwaxE9UvfW1dYrrH", |
17 |
| - 'QBORealmID' => "193514489870599", |
18 |
| - 'baseUrl' => "https://qbonline-e2e.api.intuit.com/" |
19 |
| -)); |
| 12 | +$dataService = DataService::Configure([ |
| 13 | + 'auth_mode' => 'oauth2', |
| 14 | + 'ClientID' => "Q0fXL014zAv3wzmlhwXMEHTrKepfAshCRjztEu58ZokzCD5T7D", |
| 15 | + 'ClientSecret' => "stfnZfuSZUDay6cJSWtvQ9HkWiKFbcI9YuBTET5P", |
| 16 | + 'accessTokenKey' => |
| 17 | + 'eyJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiYWxnIjoiZGlyIn0..3jjOsnri0wWe_0nyKLB2SA.OaSJHdewrPVGRMbQNI8lKIhH3bOiCVhmyDLxn8W6zoiJrRnEhHuJ-GFWiO9sRS_4BaPLnlbEDsp3PUfPpGUmveD8CloaLXjgp0nPIApvqbKDA0La0zX5OhWGmvShZVwtZ-T_qAR3hU3f2TzqfaoeRTtO23S9idKSCDiSJVLdVMIbHM8DZFJvKDdKFDus5EjtEX_LNx-6vCnpWNCUU0_vu4Pjyyp1iAz2c3GgpYMbnx56985r2LA7td8mZgiXKxkpVKy2yWrXZSgmG62SDDKeqD9KRCsF7QBgYU5sqa4mts8CAR_jQr4pRMlbresPw16fVmh2n-6uoKJYXkCkLmSMZ4PtjIZ85cbpx3ECo8Te5uW4bz03EtXGdM75yJYbiuhOTP7Z8wGaPQcnZbGcMbux_Kqb5ReQWHmDNP05W6h-c61AouY0SLTbup6gXqTaYtUH8o9m6_WNUh77gMUj9rPRfMjAOrEpBfPIa_FqsQENzMFe2me-5jMNaMlVPpL0u7itmXyFU6zvHs-sUcOIFoTVEzef9felpjdNUnrv9g1uxDIY7NHS4fPuUHCo3tbqZeUavGEMKXrIN7ytILMfRdhxU1ANf__iOTby-ZRjQAQH-tXC6itPk5l6zji62LSt89Cuqp-Adm4_LHCj-3F4slEhqogKamb27v8P6gry9tLkKEjSUqtaec9i09mcnJNel93w.cBA70qRF375xICHD0GFEYQ', |
| 18 | + 'refreshTokenKey' => "Q01152727758997PwQ3G6gLh4tlZYKrH499SSytAMt12r7uKwy", |
| 19 | + 'QBORealmID' => "193514611894164", |
| 20 | + 'baseUrl' => "development" |
| 21 | +]); |
| 22 | + |
20 | 23 |
|
21 | 24 | $dataService->setLogLocation("/Users/hlu2/Desktop/newFolderForLog");
|
22 | 25 |
|
| 26 | +$theResourceObj = Invoice::create([ |
| 27 | + "Line" => [ |
| 28 | + [ |
| 29 | + "Amount" => 100.00, |
| 30 | + "DetailType" => "SalesItemLineDetail", |
| 31 | + "SalesItemLineDetail" => [ |
| 32 | + "ItemRef" => [ |
| 33 | + "value" => 1, |
| 34 | + "name" => "Services" |
| 35 | + ] |
| 36 | + ] |
| 37 | + ] |
| 38 | + ], |
| 39 | + "CustomerRef"=> [ |
| 40 | + "value"=> 1 |
| 41 | + ] |
| 42 | +]); |
23 | 43 | // Run a batch
|
24 |
| -$maxSearch = 500; |
25 | 44 | $batch = $dataService->CreateNewBatch();
|
26 |
| -$batch->AddQuery("select * from Customer startPosition 0 maxResults {$maxSearch}", "queryCustomer"); |
27 |
| -$batch->AddQuery("select * from Vendor startPosition 0 maxResults {$maxSearch}", "queryVendor"); |
| 45 | +$batch->AddQuery("select * from Customer startPosition 0 maxResults 5", "queryCustomer"); |
| 46 | +$batch->AddQuery("select * from Vendor startPosition 0 maxResults 5", "queryVendor"); |
| 47 | +$batch->AddEntity($theResourceObj, "CreateInvoice", "Create"); |
28 | 48 | $batch->Execute();
|
29 | 49 | $error = $batch->getLastError();
|
30 |
| -if ($error != null) { |
| 50 | +if ($error) { |
31 | 51 | echo "The Status code is: " . $error->getHttpStatusCode() . "\n";
|
32 | 52 | echo "The Helper message is: " . $error->getOAuthHelperError() . "\n";
|
33 | 53 | echo "The Response message is: " . $error->getResponseBody() . "\n";
|
34 | 54 | exit();
|
35 | 55 | }
|
36 | 56 |
|
37 | 57 | // Echo some formatted output
|
38 |
| -$batchItemResponse = $batch->intuitBatchItemResponses[0]; |
39 |
| -echo "Looked for up to {$maxSearch} customers; found " . count($batchItemResponse->entities) . "\n"; |
| 58 | +$batchItemResponse_createInvoice = $batch->intuitBatchItemResponses["CreateInvoice"]; |
| 59 | +if($batchItemResponse_createInvoice->isSuccess()){ |
| 60 | + $createdInvoice = $batchItemResponse_createInvoice->getResult(); |
| 61 | + echo "Create Invoice success!:\n"; |
| 62 | + $xmlBody = XmlObjectSerializer::getPostXmlFromArbitraryEntity($createdInvoice, $something); |
| 63 | + echo $xmlBody . "\n"; |
| 64 | +}else{ |
| 65 | + $result = $batchItemResponse_createInvoice->getError(); |
| 66 | + var_dump($result); |
| 67 | +} |
| 68 | + |
| 69 | +$batchItemResponse_queryCustomer = $batch->intuitBatchItemResponses["queryCustomer"]; |
| 70 | +if($batchItemResponse_queryCustomer->isSuccess()){ |
| 71 | + $customers = $batchItemResponse_queryCustomer->getResult(); |
| 72 | + echo "Query success!:\n"; |
| 73 | + foreach($customers as $oneCustomer){ |
| 74 | + $xmlBody = XmlObjectSerializer::getPostXmlFromArbitraryEntity($oneCustomer, $something); |
| 75 | + echo $xmlBody . "\n"; |
| 76 | + } |
| 77 | + |
| 78 | +}else{ |
| 79 | + $result = $batchItemResponse_queryCustomer->getError(); |
| 80 | + var_dump($result); |
| 81 | +} |
| 82 | + |
| 83 | +$batchItemResponse_queryVendor = $batch->intuitBatchItemResponses["queryVendor"]; |
| 84 | +if($batchItemResponse_queryVendor->isSuccess()){ |
| 85 | + echo "Query success!:\n"; |
| 86 | + $vendors = $batchItemResponse_queryVendor->getResult(); |
| 87 | + foreach($vendors as $oneVendor){ |
| 88 | + $xmlBody = XmlObjectSerializer::getPostXmlFromArbitraryEntity($oneVendor , $something); |
| 89 | + echo $xmlBody . "\n"; |
| 90 | + } |
| 91 | + |
| 92 | +}else{ |
| 93 | + $result = $batchItemResponse_queryVendor->getError(); |
| 94 | + var_dump($result); |
| 95 | +} |
40 | 96 |
|
41 |
| -$batchItemResponse = $batch->intuitBatchItemResponses[1]; |
42 |
| -echo "Looked for up to {$maxSearch} vendors; found " . count($batchItemResponse->entities) . "\n"; |
| 97 | +//$batchItemResponse = $batch->intuitBatchItemResponses[1]; |
| 98 | +//echo "Looked for up to {$maxSearch} vendors; found " . count($batchItemResponse->entities) . "\n"; |
43 | 99 |
|
44 | 100 | /*
|
45 | 101 | Example output:
|
|
0 commit comments