Skip to content

Commit

Permalink
Merge pull request #130 from wtfzdotnet/feature/CORE-258--sdk
Browse files Browse the repository at this point in the history
[CORE-258] SDK modifications for CSE.
  • Loading branch information
daan-pay authored Mar 24, 2021
2 parents 8047d44 + 482dbb4 commit 3c87530
Show file tree
Hide file tree
Showing 8 changed files with 350 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function doRequest($endpoint, $version = null)
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, Config::getVerifyPeer());

$result = $curl->post($uri, $data);

if (isset($result->status) && $result->status === 'FALSE') {
throw new Error\Api($result->error);
}
Expand Down
84 changes: 84 additions & 0 deletions src/Api/Creditcard/AbstractCseRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Paynl\Api\Creditcard;

use Paynl\Api\Api;

/**
* Encrypted transaction
*
* @author Michael Roterman <[email protected]>
*/
abstract class AbstractCseRequest extends Api
{
private $orderId;
private $payload;
private $threeDSTransactionId;

/**
* @var int the version of the api
*/
protected $version = 2;

/**
* @var bool Is the ApiToken required for this API
*/
protected $apiTokenRequired = true;

public function getData()
{
return array_merge(parent::getData(), array(
'orderId' => $this->getOrderId(),
'threeDSTransactionId' => $this->getThreeDSTransactionId(),
'payload' => $this->getPayload()
));
}

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

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

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

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

/**
* @return string|null
*/
public function getThreeDSTransactionId()
{
return $this->threeDSTransactionId;
}

/**
* @param string|null $threeDSTransactionId
*/
public function setThreeDSTransactionId($threeDSTransactionId)
{
$this->threeDSTransactionId = $threeDSTransactionId;
}
}
21 changes: 21 additions & 0 deletions src/Api/Creditcard/CseAuthenticate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Paynl\Api\Creditcard;

use Paynl\Api\Api;

/**
* Encrypted transaction
*
* @author Michael Roterman <[email protected]>
*/
class CseAuthenticate extends AbstractCseRequest
{
/**
* @inheritdoc
*/
public function doRequest($endpoint = null, $version = null)
{
return parent::doRequest('creditcard/cseAuthenticate');
}
}
21 changes: 21 additions & 0 deletions src/Api/Creditcard/CseAuthorize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Paynl\Api\Creditcard;

use Paynl\Api\Api;

/**
* Encrypted transaction
*
* @author Michael Roterman <[email protected]>
*/
class CseAuthorize extends AbstractCseRequest
{
/**
* @inheritdoc
*/
public function doRequest($endpoint = null, $version = null)
{
return parent::doRequest('creditcard/cseAuthorize');
}
}
57 changes: 57 additions & 0 deletions src/Api/Creditcard/CseTdsStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Paynl\Api\Creditcard;

use Paynl\Api\Api;

/**
* Encrypted transaction
*
* @author Michael Roterman <[email protected]>
*/
class CseTdsStatus extends Api
{
/**
* @var int the version of the api
*/
protected $version = 2;

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

/**
* @inheritdoc
*/
public function doRequest($endpoint = null, $version = null)
{
return parent::doRequest('creditcard/cseTdsStatus');
}

/**
* {@inheritDoc}
*/
public function getData()
{
return array_merge(parent::getData(), array(
'transactionId' => $this->transactionId
));
}

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

/**
* @param string $transactionId
*/
public function setTransactionId($transactionId)
{
$this->transactionId = $transactionId;
}
}
22 changes: 22 additions & 0 deletions src/Api/Creditcard/PublicKeys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace Paynl\Api\Creditcard;

use Paynl\Api\Api;

/**
* Api class to obtain public keys for encryption.
*/
class PublicKeys extends Api
{
protected $apiTokenRequired = false;

protected $version = 2;

/**
* @inheritdoc
*/
public function doRequest($endpoint = null, $version = null)
{
return parent::doRequest('creditcard/cseGetPublicKeys');
}
}
132 changes: 132 additions & 0 deletions src/Creditcard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php

namespace Paynl;

use Paynl\Api\Creditcard as Api;
use Paynl\Result\Transaction as Result;

/**
* Description of Creditcard
*
* @author Michael Roterman <[email protected]>
*/
class Creditcard
{
/**
* Attempt to authorize a encrypted transaction.
*
* @param string $orderId
*
* @param string $payload
*
* @return array|Result\Details
* @throws Error\Api
* @throws Error\Error
* @throws Error\Required\ApiToken
*/
public static function cseAuthorize(
$orderId,
$threeDSTransactionId,
$payload
) {
$api = new Api\CseAuthorize();

$api->setOrderId($orderId);
$api->setThreeDSTransactionId($threeDSTransactionId);
$api->setPayload($payload);

try {
return $api->doRequest();
} catch (\Exception $e) {
return array(
'type' => 'error',
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString()
);
}
}

/**
* Attempt to authenticate a encrypted transaction.
*
* @param string $orderId
* @param string $payload
* @param string|null $threeDSTransactionId
*
* @return array|Result\Details
* @throws Error\Api
* @throws Error\Error
* @throws Error\Required\ApiToken
*/
public static function cseAuthenticate(
$orderId,
$payload,
$threeDSTransactionId = null
) {
$api = new Api\CseAuthenticate();

$api->setOrderId($orderId);
$api->setPayload($payload);
$api->setThreeDSTransactionId($threeDSTransactionId);

try {
return $api->doRequest();
} catch (\Exception $e) {
return array(
'type' => 'error',
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString()
);
}
}


/**
* Attempt to authenticate a encrypted transaction.
*
* @param string $transactionId
*
* @return array|Result\Details
* @throws Error\Api
* @throws Error\Error
* @throws Error\Required\ApiToken
*/
public static function cseTdsStatus(
$transactionId
) {
$api = new Api\CseTdsStatus();
$api->setTransactionId($transactionId);

try {
return $api->doRequest();
} catch (\Exception $e) {
return array(
'type' => 'error',
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString()
);
}
}


/**
* Obtain cryptographic keys to use.
*
* @return array
* @throws Error\Api
* @throws Error\Error
* @throws Error\Required\ApiToken
*/
public static function publicKeys()
{
$api = new Api\PublicKeys();

return $api->doRequest();
}
}
Loading

0 comments on commit 3c87530

Please sign in to comment.