Skip to content

Commit

Permalink
LTQR Bulk push support
Browse files Browse the repository at this point in the history
  • Loading branch information
wvdhaute committed Dec 10, 2015
1 parent f611e54 commit afb4a3f
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 1 deletion.
45 changes: 44 additions & 1 deletion linkid-sdk-php/LinkIDClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
require_once('LinkIDThemes.php');
require_once('LinkIDLocalization.php');
require_once('LinkIDLTQRContent.php');
require_once('LinkIDLTQRPushContent.php');
require_once('LinkIDLTQRPushResponse.php');
require_once('LinkIDLTQRLockType.php');
require_once('LinkIDLTQRSession.php');
require_once('LinkIDLTQRClientSession.php');
Expand Down Expand Up @@ -46,7 +48,7 @@ class LinkIDClient
public function __construct($linkIDHost, $username, $password, array $options = array())
{

$wsdlLocation = "http://" . $linkIDHost . "/linkid-ws-username/linkid31?wsdl";
$wsdlLocation = "https://" . $linkIDHost . "/linkid-ws-username/linkid31?wsdl";

$this->client = new LinkIDWSSoapClient($wsdlLocation, $options);
$this->client->__setUsernameToken($username, $password, 'PasswordDigest');
Expand Down Expand Up @@ -398,6 +400,47 @@ public function ltqrPush($content, $userAgent, $lockType)

}

/**
* @param array $contents the LTQR codes to be pushed
* @return array the created LTQR codes
* @throws Exception
*/
public function ltqrBulkPush($contents)
{
$requestParams = new stdClass;
$requestParams->requests = array();
foreach ($contents as $content) {
$ltqrPushContent = new stdClass();

$ltqrPushContent->content = $this->convertLTQRContent($content->content);
$ltqrPushContent->userAgent = $content->userAgent;
$ltqrPushContent->lockType = linkIDLTQRLockTypeToString($content->lockType);

$requestParams->requests[] = $ltqrPushContent;
}

/** @noinspection PhpUndefinedMethodInspection */
$response = $this->client->ltqrBulkPush($requestParams);

if (isset($response->error) && null != $response->error) {
throw new Exception('Error: ' . $response->error->errorCode);
}

$results = array();

foreach ($response->success->responses as $ltqrPushResponse) {
if (null != $ltqrPushResponse->success) {
$results[] = new LinkIDLTQRPushResponse(new LinkIDLTQRSession($ltqrPushResponse->success->ltqrReference,
$this->convertQRCodeInfo($ltqrPushResponse->success->qrCodeInfo),
isset($ltqrPushResponse->success->paymentOrderReference) ? $ltqrPushResponse->success->paymentOrderReference : null));
} else {
$results[] = new LinkIDLTQRPushResponse(null, $ltqrPushResponse->error->errorCode, $ltqrPushResponse->error->errorMessage);
}
}

return $results;
}

/**
* @param string $ltqrReference
* @param LinkIDLTQRContent $content
Expand Down
34 changes: 34 additions & 0 deletions linkid-sdk-php/LinkIDLTQRPushContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

require_once('LinkIDLTQRContent.php');

class LinkIDLTQRPushContent
{
/**
* @var LinkIDLTQRContent
*/
public $content;
/**
* @var string
*/
public $userAgent;
/**
* @var LinkIDLTQRLockType
*/
public $lockType;

/**
* LinkIDLTQRPushContent constructor.
* @param LinkIDLTQRContent $content
* @param string $userAgent
* @param LinkIDLTQRLockType $lockType
*/
public function __construct(LinkIDLTQRContent $content, $userAgent, $lockType)
{
$this->content = $content;
$this->userAgent = $userAgent;
$this->lockType = $lockType;
}


}
26 changes: 26 additions & 0 deletions linkid-sdk-php/LinkIDLTQRPushResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

require_once('LinkIDLTQRSession.php');

class LinkIDLTQRPushResponse
{

public $ltqrSession;
public $errorCode;
public $errorMessage;

/**
* LinkIDLTQRPushResponse constructor.
* @param $ltqrSession
* @param $errorCode
* @param $errorMessage
*/
public function __construct($ltqrSession, $errorCode = null, $errorMessage = null)
{
$this->ltqrSession = $ltqrSession;
$this->errorCode = $errorCode;
$this->errorMessage = $errorMessage;
}


}
33 changes: 33 additions & 0 deletions linkid-sdk-php/examples/ws/LinkIDWSLTQRBulkExample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

require_once('../../LinkIDClient.php');
require_once('../ExampleConfig.php');

date_default_timezone_set('UTC'); // needed for parsing dates

$client = new LinkIDClient($linkIDHost, $linkIDWSUsername, $linkIDWSPassword);


$paymentContext = new LinkIDPaymentContext(new LinkIDPaymentAmount(500, LinkIDCurrency::EUR, null), "LTQR Test");
$authenticationMessage = "PHP LTQR";
$finishedMessage = "PHP LTQR Finished";
$callback = new LinkIDCallback("https://www.linkid.be");
$sessionExpiryOverride = 10;
$theme = "ugent";
$ltqrContent = new LinkIDLTQRContent($authenticationMessage, $finishedMessage, $paymentContext, $callback, null, $sessionExpiryOverride, $theme, null, null, null, null, null, null, null, false, null);

$contents = array();
for ($i = 0; $i < 2; $i++) {
$contents[] = new LinkIDLTQRPushContent($ltqrContent, null, LinkIDLTQRLockType::NEVER);
}

$results = $client->ltqrBulkPush($contents);

print("<h2>LTQR Bulk results</h2>");

print("<pre>");
print_r($results);
print("</pre>");


?>

0 comments on commit afb4a3f

Please sign in to comment.