diff --git a/src/Api/Api.php b/src/Api/Api.php index 90102584..db4986e8 100644 --- a/src/Api/Api.php +++ b/src/Api/Api.php @@ -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); } diff --git a/src/Api/Creditcard/AbstractCseRequest.php b/src/Api/Creditcard/AbstractCseRequest.php new file mode 100644 index 00000000..a6a0cf39 --- /dev/null +++ b/src/Api/Creditcard/AbstractCseRequest.php @@ -0,0 +1,84 @@ + + */ +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; + } +} diff --git a/src/Api/Creditcard/CseAuthenticate.php b/src/Api/Creditcard/CseAuthenticate.php new file mode 100644 index 00000000..b34334fd --- /dev/null +++ b/src/Api/Creditcard/CseAuthenticate.php @@ -0,0 +1,21 @@ + + */ +class CseAuthenticate extends AbstractCseRequest +{ + /** + * @inheritdoc + */ + public function doRequest($endpoint = null, $version = null) + { + return parent::doRequest('creditcard/cseAuthenticate'); + } +} diff --git a/src/Api/Creditcard/CseAuthorize.php b/src/Api/Creditcard/CseAuthorize.php new file mode 100644 index 00000000..04ea8eb0 --- /dev/null +++ b/src/Api/Creditcard/CseAuthorize.php @@ -0,0 +1,21 @@ + + */ +class CseAuthorize extends AbstractCseRequest +{ + /** + * @inheritdoc + */ + public function doRequest($endpoint = null, $version = null) + { + return parent::doRequest('creditcard/cseAuthorize'); + } +} diff --git a/src/Api/Creditcard/CseTdsStatus.php b/src/Api/Creditcard/CseTdsStatus.php new file mode 100644 index 00000000..99589282 --- /dev/null +++ b/src/Api/Creditcard/CseTdsStatus.php @@ -0,0 +1,57 @@ + + */ +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; + } +} diff --git a/src/Api/Creditcard/PublicKeys.php b/src/Api/Creditcard/PublicKeys.php new file mode 100644 index 00000000..f296f440 --- /dev/null +++ b/src/Api/Creditcard/PublicKeys.php @@ -0,0 +1,22 @@ + + */ +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(); + } +} diff --git a/src/Transaction.php b/src/Transaction.php index 7bbde549..8d4aaf4e 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -37,7 +37,7 @@ class Transaction /** @var string Payment fees */ const PRODUCT_TYPE_PAYMENT = 'PAYMENT'; /** @var string An extra order line added by PAY. if the total amount does not match the total of the product lines */ - const PRODUCT_TYPE_ROUNDING = 'ROUNDING'; + const PRODUCT_TYPE_ROUNDING = 'ROUNDING'; /** @var string Costs for shipment */ const PRODUCT_TYPE_SHIPPING = 'SHIPPING'; /** @var string Ticket for events, festivals or theaters */ @@ -49,7 +49,6 @@ class Transaction /** @var string Voucher for a free article or discount for next order */ const PRODUCT_TYPE_VOUCHER = 'VOUCHER'; - /** * Start a new transaction * @@ -318,26 +317,26 @@ public static function status($transactionId) * @return Result\Details * @throws Error\Api * @throws Error\Error - * @throws Error\Required\ApiToken + * @throws Error\Required\ApiToken */ public static function details( $transactionId, $entranceCode = null ) { - + $api = new Api\Details(); - + $api->setTransactionId($transactionId); - + if ($entranceCode !== null) { $api->setEntranceCode($entranceCode); - } - $result = $api->doRequest(); - + } + $result = $api->doRequest(); + return new Result\Details($result); } - + /** * Get the transaction in an exchange script. * This will work for all kinds of exchange calls (GET, POST AND POST_XML) @@ -425,7 +424,7 @@ public static function refund( * @return Result\Cancel * @throws Error\Api * @throws Error\Error - * @throws Error\Required\ApiToken + * @throws Error\Required\ApiToken */ public static function cancel( $transactionId, @@ -434,11 +433,11 @@ public static function cancel( { $api = new Api\Cancel(); $api->setTransactionId($transactionId); - + if ($entranceCode !== null) { $api->setEntranceCode($entranceCode); } - + $result = $api->doRequest(); return new Result\Cancel($result);