18
18
19
19
use QuickBooksOnline \API \Core \CoreHelper ;
20
20
use QuickBooksOnline \API \Core \Http \Serialization \IEntitySerializer ;
21
+ use QuickBooksOnline \API \Core \Http \Serialization \XmlObjectSerializer ;
21
22
use QuickBooksOnline \API \Core \HttpClients \FaultHandler ;
22
23
use QuickBooksOnline \API \Core \HttpClients \RestHandler ;
23
24
use QuickBooksOnline \API \Core \ServiceContext ;
29
30
use QuickBooksOnline \API \Data \IPPAttachable ;
30
31
use QuickBooksOnline \API \Data \IPPEntitlementsResponse ;
31
32
use QuickBooksOnline \API \Data \IPPIntuitEntity ;
33
+ use QuickBooksOnline \API \Data \IPPRecurringTransaction ;
32
34
use QuickBooksOnline \API \Data \IPPTaxService ;
33
35
use QuickBooksOnline \API \Data \IPPid ;
34
36
use QuickBooksOnline \API \Exception \IdsException ;
@@ -803,7 +805,6 @@ public function Add($entity)
803
805
}
804
806
805
807
$ httpsPostBody = $ this ->executeObjectSerializer ($ entity , $ urlResource );
806
-
807
808
// Builds resource Uri
808
809
$ resourceURI = implode (CoreConstants::SLASH_CHAR , array ('company ' , $ this ->serviceContext ->realmId , $ urlResource ));
809
810
@@ -1193,6 +1194,67 @@ public function CDC($entityList, $changedSince)
1193
1194
}
1194
1195
}
1195
1196
1197
+ /**
1198
+ * Creates a RecurringTransaction Entity under the specified realm. The realm must be set in the context.
1199
+ *
1200
+ * @param IPPIntuitEntity $entity Entity to Create.
1201
+ * @return IntuitRecurringTransactionResponse Returns the RecurringTransaction created for the entity.
1202
+ * @throws IdsException
1203
+ */
1204
+ public function addRecurringTxn ($ entity )
1205
+ {
1206
+ $ this ->serviceContext ->IppConfiguration ->Logger ->RequestLog ->Log (TraceLevel::Info, "Called Method Add. " );
1207
+
1208
+ // Validate parameter
1209
+ if (!$ entity ) {
1210
+ $ this ->serviceContext ->IppConfiguration ->Logger ->RequestLog ->Log (TraceLevel::Error, "Argument Null Exception " );
1211
+ throw new IdsException ('Argument Null Exception ' );
1212
+ }
1213
+ // Verify operation access
1214
+ $ this ->verifyOperationAccess ($ entity , __FUNCTION__ );
1215
+ if ($ this ->isJsonOnly ($ entity )) {
1216
+ $ this ->forceJsonSerializers ();
1217
+ }
1218
+ // Create recurring transaction object
1219
+ $ recurringtxn = RecurringTransactionAdapter::createRecurringTransactionObject ($ entity );
1220
+
1221
+ // Create recurring transaction Post Body
1222
+ $ httpsPostBody = RecurringTransactionAdapter::getRecurringTxnBody ($ recurringtxn );
1223
+
1224
+ // Builds resource Uri
1225
+ $ resourceURI = implode (CoreConstants::SLASH_CHAR , array ('company ' , $ this ->serviceContext ->realmId , 'recurringtransaction ' ));
1226
+
1227
+ $ requestParameters = new RequestParameters ($ resourceURI , 'POST ' , CoreConstants::CONTENTTYPE_APPLICATIONXML , null );
1228
+ $ restRequestHandler = $ this ->getRestHandler ();
1229
+ list ($ responseCode , $ responseBody ) = $ restRequestHandler ->sendRequest ($ requestParameters , $ httpsPostBody , null , $ this ->isThrownExceptionOnError ());
1230
+ $ faultHandler = $ restRequestHandler ->getFaultHandler ();
1231
+ if ($ faultHandler ) {
1232
+ $ this ->lastError = $ faultHandler ;
1233
+ return null ;
1234
+ } else {
1235
+ $ this ->lastError = false ;
1236
+ $ returnValue = new IntuitRecurringTransactionResponse ();
1237
+ try {
1238
+ $ xmlObj = simplexml_load_string ($ responseBody );
1239
+ // deserialize the response body
1240
+ $ deserializedResponse = $ this ->responseSerializer ->Deserialize ($ xmlObj ->RecurringTransaction ->asXML (), false );
1241
+ $ entityName = XmlObjectSerializer::cleanPhpClassNameToIntuitEntityName (get_class ($ entity ));
1242
+ $ returnValue ->entities [$ entityName ] = $ deserializedResponse ;
1243
+ } catch (\Exception $ e ) {
1244
+ IdsExceptionManager::HandleException ($ e );
1245
+ }
1246
+ $ this ->serviceContext ->IppConfiguration ->Logger ->CustomLogger ->Log (TraceLevel::Info, "Finished Executing Recurring Transaction. " );
1247
+ return $ returnValue ;
1248
+ }
1249
+ }
1250
+
1251
+ /**
1252
+ * Query RecurringTransaction Entity under the specified realm. The realm must be set in the context.
1253
+ *
1254
+ * @param query ex : SELECT * FROM RecurringTransaction
1255
+ * @return IntuitRecurringTransactionResponse Returns the RecurringTransaction created for the entity.
1256
+ * @throws IdsException
1257
+ */
1196
1258
public function recurringTransaction ($ query )
1197
1259
{
1198
1260
$ this ->serviceContext ->IppConfiguration ->Logger ->RequestLog ->Log (TraceLevel::Info, "Called Method Query. " );
@@ -1244,6 +1306,112 @@ public function recurringTransaction($query)
1244
1306
}
1245
1307
}
1246
1308
1309
+ /**
1310
+ * Find a RecurringTransaction Entity By ID under the specified realm. The realm must be set in the context.
1311
+ *
1312
+ * @param $Id Id of the IPPIntuitEntity Object
1313
+ * @return IntuitRecurringTransactionResponse Returns the RecurringTransaction created for the entity.
1314
+ * @throws IdsException
1315
+ */
1316
+ public function findRecurringTransactionById ($ Id = null )
1317
+ {
1318
+ $ this ->serviceContext ->IppConfiguration ->Logger ->RequestLog ->Log (TraceLevel::Info, "Called Method findRecurringTransactionById. " );
1319
+
1320
+ if (!$ Id ) {
1321
+ $ this ->serviceContext ->IppConfiguration ->Logger ->RequestLog ->Log (TraceLevel::Error, "Argument Null Exception " );
1322
+ throw new IdsException ('Argument [Id] Null Exception ' );
1323
+ }
1324
+
1325
+ // Builds resource Uri
1326
+ $ resourceURI = implode (CoreConstants::SLASH_CHAR , array ('company ' , $ this ->serviceContext ->realmId , 'recurringtransaction/ ' . $ Id ));
1327
+
1328
+ // Make the GET request to fetch the recurring transaction
1329
+ $ requestParameters = new RequestParameters ($ resourceURI , 'GET ' , CoreConstants::CONTENTTYPE_APPLICATIONXML , null );
1330
+ $ restRequestHandler = $ this ->getRestHandler ();
1331
+ list ($ responseCode , $ responseBody ) = $ restRequestHandler ->sendRequest ($ requestParameters , null , null , $ this ->isThrownExceptionOnError ());
1332
+ $ faultHandler = $ restRequestHandler ->getFaultHandler ();
1333
+ //$faultHandler now is true or false
1334
+ if ($ faultHandler ) {
1335
+ $ this ->lastError = $ faultHandler ;
1336
+ return null ;
1337
+ } else {
1338
+ //clean the error
1339
+ $ this ->lastError = false ;
1340
+ $ returnValue = new IntuitRecurringTransactionResponse ();
1341
+ try {
1342
+ $ xmlObj = simplexml_load_string ($ responseBody );
1343
+
1344
+ // deserialize the response body
1345
+ $ deserializedResponse = $ this ->responseSerializer ->Deserialize ($ xmlObj ->RecurringTransaction ->asXML (), false );
1346
+ $ entityName = XmlObjectSerializer::cleanPhpClassNameToIntuitEntityName (get_class ($ deserializedResponse [0 ]));
1347
+ $ returnValue ->entities [$ entityName ] = $ deserializedResponse ;
1348
+ } catch (\Exception $ e ) {
1349
+ IdsExceptionManager::HandleException ($ e );
1350
+ }
1351
+ $ this ->serviceContext ->IppConfiguration ->Logger ->CustomLogger ->Log (TraceLevel::Info, "Finished Executing Recurring Transaction. " );
1352
+ return $ returnValue ;
1353
+ }
1354
+ }
1355
+
1356
+ /**
1357
+ * Find a RecurringTransaction Entity By ID under the specified realm. The realm must be set in the context.
1358
+ *
1359
+ * @param IntuitRecurringTransactionResponse RecurringTransaction Response from findRecurringTransactionById method.
1360
+ * @return IntuitRecurringTransactionResponse Returns the RecurringTransaction created for the entity.
1361
+ * @throws IdsException
1362
+ */
1363
+ public function deleteRecurringTransaction ($ recurringTransaction )
1364
+ {
1365
+ $ this ->serviceContext ->IppConfiguration ->Logger ->RequestLog ->Log (TraceLevel::Info, "Called Method Delete. " );
1366
+
1367
+ // Validate parameter
1368
+ if (!$ recurringTransaction ) {
1369
+ $ this ->serviceContext ->IppConfiguration ->Logger ->RequestLog ->Log (TraceLevel::Error, "Argument Null Exception " );
1370
+ throw new IdsException ('Argument Null Exception ' );
1371
+ }
1372
+ $ this ->verifyOperationAccess ($ recurringTransaction , __FUNCTION__ );
1373
+
1374
+ // Get the Entity Name from $recurringTransaction
1375
+ $ entityName = array_keys ($ recurringTransaction ->entities )[0 ];
1376
+
1377
+ // Get the IPPEntity Object from $recurringTransaction
1378
+ $ entity = $ recurringTransaction ->entities [$ entityName ][0 ];
1379
+
1380
+ // Create recurring transaction object
1381
+ $ recurringtxn = RecurringTransactionAdapter::createRecurringTransactionObject ($ entity );
1382
+ // Create recurring transaction Post Body
1383
+ $ httpsPostBody = RecurringTransactionAdapter::getRecurringTxnBody ($ recurringtxn );
1384
+
1385
+ // Builds resource Uri
1386
+ $ resourceURI = implode (CoreConstants::SLASH_CHAR , array ('company ' , $ this ->serviceContext ->realmId , 'recurringtransaction ' . '?operation=delete ' ));
1387
+
1388
+ // Make the GET request to fetch the recurring transaction
1389
+ $ requestParameters = new RequestParameters ($ resourceURI , 'POST ' , CoreConstants::CONTENTTYPE_APPLICATIONXML , null );
1390
+ $ restRequestHandler = $ this ->getRestHandler ();
1391
+ list ($ responseCode , $ responseBody ) = $ restRequestHandler ->sendRequest ($ requestParameters , $ httpsPostBody , null , $ this ->isThrownExceptionOnError ());
1392
+ $ faultHandler = $ restRequestHandler ->getFaultHandler ();
1393
+ //$faultHandler now is true or false
1394
+ if ($ faultHandler ) {
1395
+ $ this ->lastError = $ faultHandler ;
1396
+ return null ;
1397
+ } else {
1398
+ //clean the error
1399
+ $ this ->lastError = false ;
1400
+ $ returnValue = new IntuitRecurringTransactionResponse ();
1401
+ try {
1402
+ $ xmlObj = simplexml_load_string ($ responseBody );
1403
+
1404
+ // deserialize the response body
1405
+ $ deserializedResponse = $ this ->responseSerializer ->Deserialize ($ xmlObj ->RecurringTransaction ->asXML (), false );
1406
+ $ entityName = XmlObjectSerializer::cleanPhpClassNameToIntuitEntityName (get_class ($ entity ));
1407
+ $ returnValue ->entities [$ entityName ] = $ deserializedResponse ;
1408
+ } catch (\Exception $ e ) {
1409
+ IdsExceptionManager::HandleException ($ e );
1410
+ }
1411
+ $ this ->serviceContext ->IppConfiguration ->Logger ->CustomLogger ->Log (TraceLevel::Info, "Finished Executing Recurring Transaction. " );
1412
+ return $ returnValue ;
1413
+ }
1414
+ }
1247
1415
1248
1416
/**
1249
1417
* Returns an entity under the specified realm. The realm must be set in the context.
@@ -1266,7 +1434,6 @@ public function Retrieve($entity)
1266
1434
*/
1267
1435
protected function executeObjectSerializer ($ entity , &$ urlResource )
1268
1436
{
1269
- //
1270
1437
$ result = $ this ->getRequestSerializer ()->Serialize ($ entity );
1271
1438
$ urlResource = $ this ->getRequestSerializer ()->getResourceURL ();
1272
1439
0 commit comments