Skip to content

Commit

Permalink
Merge pull request #12 from PayU/token-creation-with-alu
Browse files Browse the repository at this point in the history
  • Loading branch information
drealecs committed Nov 17, 2015
2 parents 971fd3e + 7dc8b9d commit bc34141
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/PayU/Alu/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class Card
*/
private $cardOwnerName;

/** @var bool */
private $enableTokenCreation;

/**
* @param string $cardNumber
* @param int $cardExpirationMonth
Expand Down Expand Up @@ -91,4 +94,18 @@ public function getCardOwnerName()
{
return $this->cardOwnerName;
}

public function enableTokenCreation()
{
$this->enableTokenCreation = true;
return $this;
}

/**
* @return boolean
*/
public function isEnableTokenCreation()
{
return $this->enableTokenCreation;
}
}
8 changes: 7 additions & 1 deletion src/PayU/Alu/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ private function getResponse(SimpleXMLElement $xmlObject)

$response->parseAdditionalParameters($xmlObject);

// @todo implement TOKEN_HASH parameter
if (property_exists($xmlObject, 'TOKEN_HASH')) {
$response->setTokenHash((string)$xmlObject->TOKEN_HASH);
}

// parameters used for wire payments on ALU v3
if (property_exists($xmlObject, 'WIRE_ACCOUNTS') && count($xmlObject->WIRE_ACCOUNTS->ITEM) > 0) {
Expand Down Expand Up @@ -246,6 +248,10 @@ private function getThreeDSReturnResponse(array $returnData = array())

$response->parseAdditionalParameters($returnData);

if (array_key_exists('TOKEN_HASH', $returnData)) {
$response->setTokenHash($returnData['TOKEN_HASH']);
}

if (array_key_exists('WIRE_ACCOUNTS', $returnData)
&& is_array($returnData['WIRE_ACCOUNTS'])
) {
Expand Down
3 changes: 3 additions & 0 deletions src/PayU/Alu/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ private function transformObject2Array()
$this->internalArray['EXP_YEAR'] = $this->card->getCardExpirationYear();
$this->internalArray['CC_CVV'] = $this->card->getCardCVV();
$this->internalArray['CC_OWNER'] = $this->card->getCardOwnerName();
if ($this->card->isEnableTokenCreation()) {
$this->internalArray['LU_ENABLE_TOKEN'] = '1';
}
}

$this->internalArray['SELECTED_INSTALLMENTS_NUMBER'] = $this->order->getInstallmentsNumber();
Expand Down
23 changes: 23 additions & 0 deletions src/PayU/Alu/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class Response
*/
private $wireAccounts = array();

/** @var string */
private $tokenHash;

/**
* @return ResponseWireAccount[]
*/
Expand Down Expand Up @@ -391,6 +394,22 @@ public function getAdditionalParameterValue($name)
return null;
}

/**
* @return string
*/
public function getTokenHash()
{
return $this->tokenHash;
}

/**
* @param string $tokenHash
*/
public function setTokenHash($tokenHash)
{
$this->tokenHash = $tokenHash;
}

/**
* @return bool
*/
Expand Down Expand Up @@ -445,6 +464,10 @@ private function computeInternalArray()
$this->internalArray[$parameterKey] = $parameterValue;
}

if (!is_null($this->tokenHash)) {
$this->internalArray['TOKEN_HASH'] = $this->tokenHash;
}

if (is_array($this->getWireAccounts())) {
foreach ($this->getWireAccounts() as $account) {
$this->internalArray['WIRE_ACCOUNTS'][] = array(
Expand Down

0 comments on commit bc34141

Please sign in to comment.