Skip to content

Commit

Permalink
Merge branch 'v1281_giftcard_calls' into 'master'
Browse files Browse the repository at this point in the history
Giftcard API calls

See merge request mpluskassa/mplus-api-client!17
  • Loading branch information
dennismpluskassa committed Mar 16, 2020
2 parents dfa5e97 + 06311a3 commit eb63632
Showing 1 changed file with 252 additions and 1 deletion.
253 changes: 252 additions & 1 deletion Mplusqapiclient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class MplusQAPIclient
{
const CLIENT_VERSION = '1.28.0';
const CLIENT_VERSION = '1.28.1';
const WSDL_TTL = 300;

var $MIN_API_VERSION_MAJOR = 0;
Expand Down Expand Up @@ -3565,6 +3565,126 @@ public function updateOrderV2($order) {
}
}
// END updateOrderV2()

//----------------------------------------------------------------------------
public function getGiftcard($cardNumber = null, $cardId = null, $attempts = 0) {
try {
$request = $this->parser->convertGetGiftcardRequest($cardNumber, $cardId);
$result = $this->client->getGiftcard($request);
return $this->parser->parseGetGiftcardResult($result);
} catch (SoapFault $e) {
$msg = $e->getMessage();
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
sleep(1);
return $this->getGiftcard($cardNumber, $cardId, $attempts + 1);
} else {
throw new MplusQAPIException('SoapFault occurred: ' . $msg, 0, $e);
}
} catch (Exception $e) {
throw new MplusQAPIException('Exception occurred: ' . $e->getMessage(), 0, $e);
}
}
// END getGiftcard()

//----------------------------------------------------------------------------
public function getGiftcardHistory($cardNumber = null, $cardId = null, $attempts = 0) {
try {
$request = $this->parser->convertGetGiftcardHistoryRequest($cardNumber, $cardId);
$result = $this->client->getGiftcardHistory($request);
return $this->parser->parseGetGiftcardHistoryResult($result);
} catch (SoapFault $e) {
$msg = $e->getMessage();
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
sleep(1);
return $this->getGiftcardHistory($cardNumber, $cardId, $attempts + 1);
} else {
throw new MplusQAPIException('SoapFault occurred: ' . $msg, 0, $e);
}
} catch (Exception $e) {
throw new MplusQAPIException('Exception occurred: ' . $e->getMessage(), 0, $e);
}
}
// END getGiftcardHistory()

//----------------------------------------------------------------------------
public function createGiftcard($cardNumber, $cardTypeId, $branchNumber, $employeeNumber, $amount, $externalReference, $relationNumber = null, $attempts = 0) {
try {
$request = $this->parser->convertCreateGiftcardRequest($cardNumber, $cardTypeId, $branchNumber, $employeeNumber, $amount, $externalReference, $relationNumber);
$result = $this->client->createGiftcard($request);
return $this->parser->parseCreateGiftcardResult($result);
} catch (SoapFault $e) {
$msg = $e->getMessage();
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
sleep(1);
return $this->createGiftcard($cardNumber, $cardTypeId, $branchNumber, $employeeNumber, $amount, $externalReference, $relationNumber, $attempts + 1);
} else {
throw new MplusQAPIException('SoapFault occurred: ' . $msg, 0, $e);
}
} catch (Exception $e) {
throw new MplusQAPIException('Exception occurred: ' . $e->getMessage(), 0, $e);
}
}
// END createGiftcard()

//----------------------------------------------------------------------------
public function getGiftcardTypes($branchNumber, $attempts = 0) {
try {
$request = $this->parser->convertGetGiftcardTypesRequest($branchNumber);
$result = $this->client->getGiftcardTypes($request);
return $this->parser->parseGetGiftcardTypesResult($result);
} catch (SoapFault $e) {
$msg = $e->getMessage();
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
sleep(1);
return $this->getGiftcardTypes($branchNumber, $attempts + 1);
} else {
throw new MplusQAPIException('SoapFault occurred: ' . $msg, 0, $e);
}
} catch (Exception $e) {
throw new MplusQAPIException('Exception occurred: ' . $e->getMessage(), 0, $e);
}
}
// END getGiftcardTypes()

//----------------------------------------------------------------------------
public function getRelationGiftcards($relationNumber, $attempts = 0) {
try {
$request = $this->parser->convertGetRelationGiftcardsRequest($relationNumber);
$result = $this->client->getRelationGiftcards($request);
return $this->parser->parseGetRelationGiftcardsResult($result);
} catch (SoapFault $e) {
$msg = $e->getMessage();
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
sleep(1);
return $this->getRelationGiftcards($relationNumber, $attempts + 1);
} else {
throw new MplusQAPIException('SoapFault occurred: ' . $msg, 0, $e);
}
} catch (Exception $e) {
throw new MplusQAPIException('Exception occurred: ' . $e->getMessage(), 0, $e);
}
}
// END getRelationGiftcards()

//----------------------------------------------------------------------------
public function reloadGiftcard($cardNumber, $branchNumber, $employeeNumber, $amount, $externalReference, $attempts = 0) {
try {
$request = $this->parser->convertReloadGiftcardRequest($cardNumber, $branchNumber, $employeeNumber, $amount, $externalReference);
$result = $this->client->reloadGiftcard($request);
return $this->parser->parseReloadGiftcardResult($result);
} catch (SoapFault $e) {
$msg = $e->getMessage();
if (false !== stripos($msg, 'Could not connect to host') and $attempts < 3) {
sleep(1);
return $this->reloadGiftcard($cardNumber, $branchNumber, $employeeNumber, $amount, $externalReference, $attempts + 1);
} else {
throw new MplusQAPIException('SoapFault occurred: ' . $msg, 0, $e);
}
} catch (Exception $e) {
throw new MplusQAPIException('Exception occurred: ' . $e->getMessage(), 0, $e);
}
}
// END reloadGiftcard()
}

//==============================================================================
Expand Down Expand Up @@ -6146,6 +6266,61 @@ public function parseUpdateOrderV2Result($soapUpdateOrderV2Result) {
}
}
// END parseUpdateOrderV2Result()

//----------------------------------------------------------------------------
public function parseGetGiftcardTypesResult($soapGetGiftcardTypesResult) {
if (property_exists($soapGetGiftcardTypesResult, "giftcardTypesList") &&
property_exists($soapGetGiftcardTypesResult->giftcardTypesList, "giftcardTypes")) {
return $soapGetGiftcardTypesResult->giftcardTypesList->giftcardTypes;
} else {
return false;
}
}
// END parseGetGiftcardTypesResult()

//----------------------------------------------------------------------------
public function parseGetRelationGiftcardsResult($soapGetRelationGiftcardsResult) {
if (property_exists($soapGetRelationGiftcardsResult, "relationGiftcardList") &&
property_exists($soapGetRelationGiftcardsResult->relationGiftcardList, "relationGiftcards")) {
return $soapGetRelationGiftcardsResult->relationGiftcardList->relationGiftcards;
} else {
return false;
}
}
// END parseGetGiftcardTypesResult()

//----------------------------------------------------------------------------
public function parseCreateGiftcardResult($soapCreateGiftcardResult) {
return $soapCreateGiftcardResult;
}
// END parseCreateGiftcardResult()

//----------------------------------------------------------------------------
public function parseReloadGiftcardResult($soapReloadGiftcardResult) {
return $soapReloadGiftcardResult;
}
// END parseReloadGiftcardResult()

//----------------------------------------------------------------------------
public function parseGetGiftcardResult($soapGetGiftcardResult) {
if (property_exists($soapGetGiftcardResult, "giftcard")) {
return $soapGetGiftcardResult->giftcard;
} else {
return false;
}
}
// END parseGetGiftcardResult()

//----------------------------------------------------------------------------
public function parseGetGiftcardHistoryResult($soapGetGiftcardHistoryResult) {
if (property_exists($soapGetGiftcardHistoryResult, "giftcardHistoryList") &&
property_exists($soapGetGiftcardHistoryResult->giftcardHistoryList, "giftcardHistory")) {
return $soapGetGiftcardHistoryResult->giftcardHistoryList->giftcardHistory;
} else {
return false;
}
}
// END parseGetGiftcardHistoryResult()

//----------------------------------------------------------------------------

Expand Down Expand Up @@ -8909,6 +9084,82 @@ public function convertUpdateOrderV2($order, $applySalesAndActions = null, $appl
}
// END convertUpdateOrderV2()

//----------------------------------------------------------------------------
public function convertGetGiftcardTypesRequest($branchNumber) {
$request = new stdClass();
$request->request = new stdClass();
$request->request->branchNumber = $branchNumber;
return $request;
}
// END convertGetGiftcardTypesRequest()

//----------------------------------------------------------------------------
public function convertGetRelationGiftcardsRequest($relationNumber) {
$request = new stdClass();
$request->request = new stdClass();
$request->request->relationNumber = $relationNumber;
return $request;
}
// END convertGetRelationGiftcardsRequest()

//----------------------------------------------------------------------------
public function convertCreateGiftcardRequest($cardNumber, $cardTypeId, $branchNumber, $employeeNumber, $amount, $externalReference, $relationNumber) {
$request = new stdClass();
$request->request = new stdClass();
$request->request->cardNumber = $cardNumber;
$request->request->cardTypeId = $cardTypeId;
$request->request->branchNumber = $branchNumber;
$request->request->employeeNumber = $employeeNumber;
$request->request->amount = $amount;
$request->request->externalReference = $externalReference;
if ($relationNumber !== null) {
$request->request->relationNumber = $relationNumber;
}
return $request;
}
// END convertCreateGiftcardRequest()

//----------------------------------------------------------------------------
public function convertReloadGiftcardRequest($cardNumber, $branchNumber, $employeeNumber, $amount, $externalReference) {
$request = new stdClass();
$request->request = new stdClass();
$request->request->cardNumber = $cardNumber;
$request->request->branchNumber = $branchNumber;
$request->request->employeeNumber = $employeeNumber;
$request->request->amount = $amount;
$request->request->externalReference = $externalReference;
return $request;
}
// END convertReloadGiftcardRequest()

//----------------------------------------------------------------------------
public function convertGetGiftcardRequest($cardNumber, $cardId) {
$request = new stdClass();
$request->request = new stdClass();
if ($cardNumber !== null) {
$request->request->cardNumber = $cardNumber;
}
if ($cardId !== null) {
$request->request->cardId = $cardId;
}
return $request;
}
// END convertGetGiftcardRequest()

//----------------------------------------------------------------------------
public function convertGetGiftcardHistoryRequest($cardNumber, $cardId) {
$request = new stdClass();
$request->request = new stdClass();
if ($cardNumber !== null) {
$request->request->cardNumber = $cardNumber;
}
if ($cardId !== null) {
$request->request->cardId = $cardId;
}
return $request;
}
// END convertGetGiftcardHistoryRequest()

}

//------------------------------------------------------------------------------
Expand Down

0 comments on commit eb63632

Please sign in to comment.