Skip to content

Commit 7c241c8

Browse files
author
Mplus Software
committed
v1.8.0
- Added moveTableOrder() - updateOrder() now returns TRUE when the update itself succeeded, but there were no changes.
1 parent cb42f53 commit 7c241c8

File tree

1 file changed

+82
-11
lines changed

1 file changed

+82
-11
lines changed

Mplusqapiclient.php

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class MplusQAPIclient
44
{
5-
const CLIENT_VERSION = '1.7.0';
5+
const CLIENT_VERSION = '1.8.0';
66

77

88
var $MIN_API_VERSION_MAJOR = 0;
@@ -2504,45 +2504,79 @@ public function getTableOrderCourseList($terminal, $branchNumber, $tableNumber,
25042504

25052505
//----------------------------------------------------------------------------
25062506

2507-
public function saveTableOrder($terminal, $order)
2507+
public function saveTableOrder($terminal, $order, $attempts=0)
25082508
{
25092509
try {
25102510
$result = $this->client->saveTableOrder($this->parser->convertSaveTableOrder($terminal, $order));
25112511
return $this->parser->parseSaveTableOrderResult($result);
25122512
} catch (SoapFault $e) {
2513-
throw new MplusQAPIException('SoapFault occurred: '.$e->getMessage(), 0, $e);
2513+
$msg = $e->getMessage();
2514+
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
2515+
sleep(1);
2516+
return $this->saveTableOrder($terminal, $order, $attempts+1);
2517+
} else {
2518+
throw new MplusQAPIException('SoapFault occurred: '.$msg, 0, $e);
2519+
}
25142520
} catch (Exception $e) {
25152521
throw new MplusQAPIException('Exception occurred: '.$e->getMessage(), 0, $e);
25162522
}
25172523
} // END getTableOrder()
25182524

25192525
//----------------------------------------------------------------------------
25202526

2521-
public function cancelTableOrder($terminal, $branchNumber, $tableNumber)
2527+
public function moveTableOrder($terminal, $order, $tableNumber, $attempts=0)
2528+
{
2529+
try {
2530+
$result = $this->client->moveTableOrder($this->parser->convertMoveTableOrderRequest($terminal, $order, $tableNumber));
2531+
return $this->parser->parseMoveTableOrderResult($result);
2532+
} catch (SoapFault $e) {
2533+
$msg = $e->getMessage();
2534+
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
2535+
sleep(1);
2536+
return $this->moveTableOrder($terminal, $order, $tableNumber, $attempts+1);
2537+
} else {
2538+
throw new MplusQAPIException('SoapFault occurred: '.$msg, 0, $e);
2539+
}
2540+
} catch (Exception $e) {
2541+
throw new MplusQAPIException('Exception occurred: '.$e->getMessage(), 0, $e);
2542+
}
2543+
} // END cancelTableOrder()
2544+
2545+
//----------------------------------------------------------------------------
2546+
2547+
public function cancelTableOrder($terminal, $branchNumber, $tableNumber, $attempts=0)
25222548
{
25232549
try {
25242550
$result = $this->client->cancelTableOrder($this->parser->convertGetTableOrderRequest($terminal, $branchNumber, $tableNumber));
25252551
return $this->parser->parseCancelOrderResult($result);
25262552
} catch (SoapFault $e) {
2527-
throw new MplusQAPIException('SoapFault occurred: '.$e->getMessage(), 0, $e);
2553+
$msg = $e->getMessage();
2554+
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
2555+
sleep(1);
2556+
return $this->cancelTableOrder($terminal, $branchNumber, $tableNumber, $attempts+1);
2557+
} else {
2558+
throw new MplusQAPIException('SoapFault occurred: '.$msg, 0, $e);
2559+
}
25282560
} catch (Exception $e) {
25292561
throw new MplusQAPIException('Exception occurred: '.$e->getMessage(), 0, $e);
25302562
}
25312563
} // END cancelTableOrder()
25322564

25332565
//----------------------------------------------------------------------------
25342566

2535-
public function sendMessage($branchNumber, $terminalNumber, $text, $sender=null, $messageType=null)
2567+
public function sendMessage($branchNumber, $terminalNumber, $text, $sender=null, $messageType=null, $attempts=0)
25362568
{
25372569
try {
25382570
$forceBranchTerminalNumber = $this->isApiVersionLowerThan('1.0.0');
25392571
$result = $this->client->sendMessage($this->parser->convertSendMessageRequest($branchNumber, $terminalNumber, $text, $sender, $messageType, $forceBranchTerminalNumber));
25402572
return $this->parser->parseSendMessageResult($result);
25412573
} catch (SoapFault $e) {
2542-
if (false !== stripos($e->getMessage(), "object has no 'branchNumber' property") and ! $forceBranchTerminalNumber) {
2543-
return $this->sendMessage($branchNumber, $terminalNumber, $text, $sender, $messageType, true);
2574+
$msg = $e->getMessage();
2575+
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
2576+
sleep(1);
2577+
return $this->sendMessage($branchNumber, $terminalNumber, $text, $sender, $messageType, $attempts+1);
25442578
} else {
2545-
throw new MplusQAPIException('SoapFault occurred: '.$e->getMessage(), 0, $e);
2579+
throw new MplusQAPIException('SoapFault occurred: '.$msg, 0, $e);
25462580
}
25472581
} catch (Exception $e) {
25482582
throw new MplusQAPIException('Exception occurred: '.$e->getMessage(), 0, $e);
@@ -2551,13 +2585,19 @@ public function sendMessage($branchNumber, $terminalNumber, $text, $sender=null,
25512585

25522586
//----------------------------------------------------------------------------
25532587

2554-
public function encryptString($plainString, $encryptionKey)
2588+
public function encryptString($plainString, $encryptionKey, $attempts=0)
25552589
{
25562590
try {
25572591
$result = $this->client->encryptString($this->parser->convertEncryptStringRequest($plainString, $encryptionKey));
25582592
return $this->parser->parseEncryptStringResult($result);
25592593
} catch (SoapFault $e) {
2560-
throw new MplusQAPIException('SoapFault occurred: '.$e->getMessage(), 0, $e);
2594+
$msg = $e->getMessage();
2595+
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
2596+
sleep(1);
2597+
return $this->encryptString($plainString, $encryptionKey, $attempts+1);
2598+
} else {
2599+
throw new MplusQAPIException('SoapFault occurred: '.$msg, 0, $e);
2600+
}
25612601
} catch (Exception $e) {
25622602
throw new MplusQAPIException('Exception occurred: '.$e->getMessage(), 0, $e);
25632603
}
@@ -4152,6 +4192,8 @@ public function parseRegisterTerminalResult($soapRegisterTerminalResult)
41524192
public function parseUpdateOrderResult($soapUpdateOrderResult) {
41534193
if (isset($soapUpdateOrderResult->result) and $soapUpdateOrderResult->result == 'UPDATE-ORDER-RESULT-OK') {
41544194
return true;
4195+
} else if (isset($soapUpdateOrderResult->result) and $soapUpdateOrderResult->result == 'UPDATE-ORDER-RESULT-FAILED' and $soapUpdateOrderResult->errorMessage == 'Order not saved because there were no changes in the order.') {
4196+
return true;
41554197
} else {
41564198
if ( ! empty($soapUpdateOrderResult->errorMessage)) {
41574199
$this->lastErrorMessage = $soapUpdateOrderResult->errorMessage;
@@ -4212,6 +4254,21 @@ public function parseQueueBranchOrderResult($soapQueueBranchOrderResult)
42124254

42134255
//----------------------------------------------------------------------------
42144256

4257+
public function parseMoveTableOrderResult($soapMoveTableOrderResult)
4258+
{
4259+
if (isset($soapMoveTableOrderResult->result) and $soapMoveTableOrderResult->result == 'MOVE-TABLE-ORDER-RESULT-OK') {
4260+
return true;
4261+
} else {
4262+
if (isset($soapMoveTableOrderResult->errorMessage)) {
4263+
return $soapMoveTableOrderResult->errorMessage;
4264+
} else {
4265+
return false;
4266+
}
4267+
}
4268+
} // END parseMoveTableOrderResult()
4269+
4270+
//----------------------------------------------------------------------------
4271+
42154272
public function parseCancelOrderResult($soapCancelOrderResult)
42164273
{
42174274
if (isset($soapCancelOrderResult->result) and $soapCancelOrderResult->result == 'CANCEL-ORDER-RESULT-OK') {
@@ -6421,6 +6478,20 @@ public function convertSaveTableOrder($terminal, $order)
64216478

64226479
//----------------------------------------------------------------------------
64236480

6481+
public function convertMoveTableOrderRequest($terminal, $order, $tableNumber)
6482+
{
6483+
$terminal = $this->convertTerminal($terminal);
6484+
$order = $this->convertOrder($order);
6485+
$object = arrayToObject(array(
6486+
'terminal'=>$terminal->terminal,
6487+
'order'=>$order->order,
6488+
'tableNumber'=>$tableNumber,
6489+
));
6490+
return $object;
6491+
} // END convertMoveTableOrderRequest()
6492+
6493+
//----------------------------------------------------------------------------
6494+
64246495
public function convertBranchNumber($branchNumber)
64256496
{
64266497
$object = arrayToObject(array('branchNumber'=>$branchNumber));

0 commit comments

Comments
 (0)