Skip to content

Commit 61dcf54

Browse files
Merge branch 'updateBatch_call_and_modified_overview_calls' into 'master'
Added updateBatch and modified overview calls See merge request mpluskassa/mplus-api-client!26
2 parents 60c023c + 8d8ffa7 commit 61dcf54

File tree

1 file changed

+85
-27
lines changed

1 file changed

+85
-27
lines changed

Mplusqapiclient.php

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

33
class MplusQAPIclient
44
{
5-
const CLIENT_VERSION = '1.28.8';
5+
const CLIENT_VERSION = '1.28.9';
66
const WSDL_TTL = 300;
77

88
var $MIN_API_VERSION_MAJOR = 0;
@@ -82,9 +82,9 @@ class MplusQAPIclient
8282
*/
8383
private $default_socket_timeout = 600;
8484

85-
const OverviewTypeEmployee = 'EMPLOYEE';
86-
const OverviewTypeProduct = 'PRODUCT';
87-
const OverviewTypeRelation = 'RELATION';
85+
const CardTypeEmployee = 'EMPLOYEE';
86+
const CardTypeProduct = 'PRODUCT';
87+
const CardTypeRelation = 'RELATION';
8888

8989
private $returnRawResult = false;
9090

@@ -3823,32 +3823,32 @@ public function getSalePromotions($branchNumbers = [], $attempts=0)
38233823
}
38243824
} // END getSalePromotions()
38253825

3826-
private function validateOverviewType($overviewType) {
3827-
$overviewAllowedTypes = [
3828-
self::OverviewTypeEmployee,
3829-
self::OverviewTypeProduct,
3830-
self::OverviewTypeRelation,
3826+
protected function validateCardType($cardType) {
3827+
$cardAllowedTypes = [
3828+
self::CardTypeEmployee,
3829+
self::CardTypeProduct,
3830+
self::CardTypeRelation,
38313831
];
3832-
if (!in_array($overviewType, $overviewAllowedTypes)) {
3833-
throw new Exception('OverviewType should be one of those : ' . implode(', ', $overviewAllowedTypes));
3832+
if (!in_array($cardType, $cardAllowedTypes)) {
3833+
throw new Exception('CardType should be one of those : ' . implode(', ', $cardAllowedTypes));
38343834
}
38353835
}
38363836

38373837
//----------------------------------------------------------------------------
3838-
public function getOverview($overviewType, $selectFields, $pageNumber = null, $maxPerPage = null, $orderField = null, $sortOrder = null, $filters = null, $search = null, $attempts = 0) {
3838+
public function getOverview($cardType, $categoryId = 0, $selectFields, $pageNumber = null, $maxPerPage = null, $orderField = null, $sortOrder = null, $filters = null, $search = null, $attempts = 0) {
38393839
try {
3840-
$this->validateOverviewType($overviewType);
3841-
$request = $this->parser->convertGetOverviewRequest($overviewType, $selectFields, $pageNumber, $maxPerPage, $orderField, $sortOrder, $filters, $search);
3840+
$this->validateCardType($cardType);
3841+
$request = $this->parser->convertGetOverviewRequest($cardType, $categoryId, $selectFields, $pageNumber, $maxPerPage, $orderField, $sortOrder, $filters, $search);
38423842
$result = $this->client->getOverview($request);
3843-
if($this->returnRawResult) {
3843+
if ($this->returnRawResult) {
38443844
return $result;
38453845
}
38463846
return $this->parser->parseGetOverviewResult($result);
38473847
} catch (SoapFault $e) {
38483848
$msg = $e->getMessage();
38493849
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
38503850
sleep(1);
3851-
return $this->getOverview($overviewType, $selectFields, $pageNumber, $maxPerPage, $orderField, $sortOrder, $filters, $search, $attempts + 1);
3851+
return $this->getOverview($cardType, $categoryId, $selectFields, $pageNumber, $maxPerPage, $orderField, $sortOrder, $filters, $search, $attempts + 1);
38523852
} else {
38533853
throw new MplusQAPIException('SoapFault occurred: ' . $msg, 0, $e);
38543854
}
@@ -3859,20 +3859,20 @@ public function getOverview($overviewType, $selectFields, $pageNumber = null, $m
38593859

38603860
// END getOverview()
38613861
//----------------------------------------------------------------------------
3862-
public function getOverviewFields($overviewType, $attempts = 0) {
3862+
public function getOverviewFields($cardType, $categoryId = 0, $attempts = 0) {
38633863
try {
3864-
$this->validateOverviewType($overviewType);
3865-
$request = $this->parser->convertGetOverviewFieldsRequest($overviewType);
3864+
$this->validateCardType($cardType);
3865+
$request = $this->parser->convertGetOverviewFieldsRequest($cardType, $categoryId);
38663866
$result = $this->client->getOverviewFields($request);
3867-
if($this->returnRawResult) {
3867+
if ($this->returnRawResult) {
38683868
return $result;
38693869
}
38703870
return $this->parser->parseGetOverviewFieldsResult($result);
38713871
} catch (SoapFault $e) {
38723872
$msg = $e->getMessage();
38733873
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
38743874
sleep(1);
3875-
return $this->getOverviewFields($overviewType, $attempts + 1);
3875+
return $this->getOverviewFields($cardType, $categoryId, $attempts + 1);
38763876
} else {
38773877
throw new MplusQAPIException('SoapFault occurred: ' . $msg, 0, $e);
38783878
}
@@ -3883,6 +3883,30 @@ public function getOverviewFields($overviewType, $attempts = 0) {
38833883

38843884
// END getOverviewFields()
38853885

3886+
//----------------------------------------------------------------------------
3887+
public function updateBatch($cardType, $categoryId = 0, $numbers, $fields, $attempts = 0) {
3888+
try {
3889+
$this->validateCardType($cardType);
3890+
$request = $this->parser->convertUpdateBatchRequest($cardType, $categoryId, $numbers, $fields);
3891+
$result = $this->client->updateBatch($request);
3892+
if ($this->returnRawResult) {
3893+
return $result;
3894+
}
3895+
return $this->parser->parseUpdateBatchResult($result);
3896+
} catch (SoapFault $e) {
3897+
$msg = $e->getMessage();
3898+
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
3899+
sleep(1);
3900+
return $this->updateBatch($cardType, $categoryId, $numbers, $fields, $attempts + 1);
3901+
} else {
3902+
throw new MplusQAPIException('SoapFault occurred: ' . $msg, 0, $e);
3903+
}
3904+
} catch (Exception $e) {
3905+
throw new MplusQAPIException('Exception occurred: ' . $e->getMessage(), 0, $e);
3906+
}
3907+
}
3908+
3909+
// END updateBatch()
38863910

38873911
//----------------------------------------------------------------------------
38883912
public function checkGiftcardPayment($cardNumber, $branchNumber, $amount = null, $attempts = 0) {
@@ -6723,6 +6747,19 @@ public function parseGetOverviewResult($soapOverviewResult) {
67236747
}
67246748

67256749
// END parseGetOverviewResult()
6750+
6751+
//----------------------------------------------------------------------------
6752+
public function parseUpdateBatchResult($soapUpdateBatchResult) {
6753+
if (isset($soapUpdateBatchResult->errorList) && isset($soapUpdateBatchResult->errorList->errors)) {
6754+
$soapUpdateBatchResult->errors = objectToArray($soapUpdateBatchResult->errorList->errors);
6755+
} else {
6756+
$soapUpdateBatchResult->errors = [];
6757+
}
6758+
unset($soapUpdateBatchResult->errorList);
6759+
return $soapUpdateBatchResult;
6760+
}
6761+
6762+
// END parseUpdateBatchResult()
67266763

67276764
//----------------------------------------------------------------------------
67286765
public function parseCheckGiftcardPaymentResult($soapCheckGiftcardPaymentResult) {
@@ -9189,12 +9226,16 @@ public function convertGetSalePromotionsRequest($branchNumbers)
91899226
} // END convertGetSalePromotionsRequest()
91909227

91919228
//----------------------------------------------------------------------------
9192-
public function convertGetOverviewRequest($overviewType, $selectFieldList, $pageNumber, $maxPerPage, $orderField, $sortOrder, $filters, $search) {
9229+
public function convertGetOverviewRequest($cardType, $categoryId, $selectFieldList, $pageNumber, $maxPerPage, $orderField, $sortOrder, $filters, $search) {
91939230
$request = new stdClass();
91949231
$request->request = new stdClass();
91959232

9196-
if (isset($overviewType)) {
9197-
$request->request->overviewType = $overviewType;
9233+
if (isset($categoryId)) {
9234+
$request->request->categoryId = $categoryId;
9235+
}
9236+
9237+
if (isset($cardType)) {
9238+
$request->request->cardType = $cardType;
91989239
}
91999240

92009241
if (!is_array($selectFieldList)) {
@@ -9228,17 +9269,34 @@ public function convertGetOverviewRequest($overviewType, $selectFieldList, $page
92289269
// END convertGetOverviewRequest()
92299270

92309271
//----------------------------------------------------------------------------
9231-
public function convertGetOverviewFieldsRequest($overviewType) {
9272+
public function convertGetOverviewFieldsRequest($cardType, $categoryId = 0) {
92329273
$request = new stdClass();
92339274
$request->request = new stdClass();
9234-
if (isset($overviewType)) {
9235-
$request->request->overviewType = $overviewType;
9275+
$request->request->cardType = $cardType;
9276+
if (isset($categoryId)) {
9277+
$request->request->categoryId = $categoryId;
92369278
}
92379279
return $request;
92389280
}
92399281

92409282
// END convertGetOverviewFieldsRequest()
92419283

9284+
//----------------------------------------------------------------------------
9285+
public function convertUpdateBatchRequest($cardType, $categoryId, $numbers, $fields) {
9286+
$request = new stdClass();
9287+
$request->request = new stdClass();
9288+
$request->request->cardType = $cardType;
9289+
$request->request->categoryId = $categoryId;
9290+
if (!is_array($numbers)) {
9291+
$numbers = array($numbers);
9292+
}
9293+
$request->request->numbers = $numbers;
9294+
$request->request->fieldList = $fields;
9295+
return $request;
9296+
}
9297+
9298+
// END convertUpdateBatchRequest()
9299+
92429300
public function parseMplusDate($mplus_date)
92439301
{
92449302
if ($mplus_date['day'] == 0 || $mplus_date['mon'] == 0 || $mplus_date['year'] == 0) {

0 commit comments

Comments
 (0)