Skip to content

Commit

Permalink
Merge pull request #2 from dipnot/dev
Browse files Browse the repository at this point in the history
release: v1.0.1
  • Loading branch information
ozgurg authored Jul 23, 2022
2 parents 55bdb2b + a290d55 commit 55c0499
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 23 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

# PTT Akıllı Esnaf API Wrapper for PHP
[![Latest Stable Version](https://poser.pugx.org/dipnot/ptt-akilliesnaf-php/v)](https://packagist.org/packages/dipnot/ptt-akilliesnaf-php) [![Total Downloads](https://poser.pugx.org/dipnot/ptt-akilliesnaf-php/downloads)](https://packagist.org/packages/dipnot/ptt-akilliesnaf-php)
# PTT Akıllı Esnaf API Wrapper for PHP

Unofficial PHP wrapper for [PTT Akıllı Esnaf API](https://akilliesnaf.ptt.gov.tr/developer/)

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "library",
"license": "MIT",
"homepage": "https://www.dipnot.com.tr/",
"version": "1.0.1",
"keywords": [
"api",
"composer",
Expand Down
4 changes: 2 additions & 2 deletions src/Dipnot/PttAkilliEsnaf/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct($baseUrl)
}

/**
* Makes a HTTP POST request
* Makes an HTTP POST request
*
* @param string $uri
* @param mixed $body
Expand All @@ -43,7 +43,7 @@ public function post($uri, $body)
}

/**
* Makes a HTTP request
* Makes an HTTP request
*
* @param string $method
* @param string $uri
Expand Down
3 changes: 2 additions & 1 deletion src/Dipnot/PttAkilliEsnaf/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ protected function getHash()

/**
* Generates hash
*
* @see https://akilliesnaf.ptt.gov.tr/developer/#hash-mekanizmasi
*
* @return string
Expand All @@ -96,7 +97,7 @@ private function createHash()
}

/**
* Creates a HttpClient instance based on the test mode
* Creates an HttpClient instance based on the test mode
*
* @return HttpClient
*/
Expand Down
20 changes: 13 additions & 7 deletions src/Dipnot/PttAkilliEsnaf/Request/InquiryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Exception;

/**
* Makes POST request to "API_ENDPOINT/inquiry"
* Makes POST request to "{API_ENDPOINT}/inquiry"
*
* Class InquiryRequest
* @package Dipnot\PttAkilliEsnaf\Request
Expand All @@ -23,6 +23,14 @@ class InquiryRequest extends Request
*/
private $_orderId;

/**
* @return bool
*/
private function isAllSet()
{
return $this->getOrderId();
}

/**
* @return string
*/
Expand All @@ -46,7 +54,7 @@ public function setOrderId($orderId)
public function getResponse()
{
if(!$this->_response) {
throw new Exception("Before that execute() must be called");
throw new Exception("Before that 'execute()' must be called");
}

return $this->_response;
Expand All @@ -58,14 +66,12 @@ public function getResponse()
*/
public function execute()
{
// Check if all required properties are set
if(!$this->getOrderId()) {
throw new Exception("orderId must be set before executing the request.");
if(!$this->isAllSet()) {
throw new Exception("'orderId' must be set before executing the request.");
}

// Check if all required Config properties are set
if(!$this->_config->isAllSet()) {
throw new Exception("clientId, apiUser and apiPass must be set for Config before executing the request.");
throw new Exception("'clientId', 'apiUser' and 'apiPass' must be set for Config before executing the request.");
}

$postData = [
Expand Down
28 changes: 18 additions & 10 deletions src/Dipnot/PttAkilliEsnaf/Request/ThreeDPaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Exception;

/**
* Makes POST request to "API_ENDPOINT/threeDPayment"
* Makes POST request to "{API_ENDPOINT}/threeDPayment"
*
* Class ThreeDPaymentRequest
* @package Dipnot\PttAkilliEsnaf\Request
Expand Down Expand Up @@ -51,6 +51,18 @@ class ThreeDPaymentRequest extends Request
*/
private $_installmentCount = 0;

/**
* @return bool
*/
private function isAllSet()
{
return $this->getCallbackUrl() &&
$this->getOrderId() &&
$this->getAmount() &&
$this->getCurrency() &&
$this->getInstallmentCount();
}

/**
* @return string
*/
Expand Down Expand Up @@ -138,7 +150,7 @@ public function setInstallmentCount($installmentCount)
public function getResponse()
{
if(!$this->_response) {
throw new Exception("Before that execute() must be called");
throw new Exception("Before that 'execute()' must be called");
}

return $this->_response;
Expand All @@ -153,7 +165,7 @@ public function getResponse()
public function getIframeUrl()
{
if(!$this->_response) {
throw new Exception("Before that execute() must be called");
throw new Exception("Before that 'execute()' must be called");
}

if($this->_config->isTestModeEnabled()) {
Expand All @@ -169,14 +181,12 @@ public function getIframeUrl()
*/
public function execute()
{
// Check if all required properties are set
if(!$this->getCallbackUrl() || !$this->getOrderId() || !$this->getAmount() || !$this->getCurrency() || !$this->getInstallmentCount()) {
throw new Exception("callbackUrl, orderId, amount, currency and installmentCount must be set before executing the request.");
if(!$this->isAllSet()) {
throw new Exception("'callbackUrl', 'orderId', 'amount', 'currency' and 'installmentCount' must be set before executing the request.");
}

// Check if all required Config properties are set
if(!$this->_config->isAllSet()) {
throw new Exception("clientId, apiUser and apiPass must be set for Config before executing the request.");
throw new Exception("'clientId', 'apiUser' and 'apiPass' must be set for Config before executing the request.");
}

$postData = [
Expand All @@ -195,12 +205,10 @@ public function execute()

$this->_response = $this->_client->post("/threeDPayment", $postData);

// Check the code if the request was successful
if(isset($this->_response->Code) && $this->_response->Code && intval($this->_response->Code) !== 0) {
throw new Exception(json_encode($this->_response));
}

// Check if the response has "ThreeDSessionId" property
if(!isset($this->_response->ThreeDSessionId) || !$this->_response->ThreeDSessionId) {
throw new Exception(json_encode($this->_response));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public function isPaymentSucceed()
*/
private function isBankResponseCodeSucceed()
{
// FIXME: 00 is not correct. The correct value should be updated after learning from the authorities.
return $this->getData("BankResponseCode") === "00";
}

Expand Down

0 comments on commit 55c0499

Please sign in to comment.