Skip to content

Commit

Permalink
code smelled checked
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariful committed Nov 8, 2022
1 parent 2816c14 commit cd9b481
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@

use Exception;
use GuzzleHttp\Exception\GuzzleException;
use RuntimeException;
use Xenon\NagadApi\Exception\ExceptionHandler;
use Xenon\NagadApi\Exception\NagadPaymentException;
use Xenon\NagadApi\lib\Key;

class Helper extends Key
{


/**
* Helper constructor.
* @param $config
* @since v1.3.1
*/
public function __construct($config)
{

parent::__construct($config);
}

Expand Down Expand Up @@ -64,7 +68,7 @@ public static function generateRandomString(int $length = 40, string $prefix = '
* @throws ExceptionHandler
* @since v1.3.1
*/
public function EncryptDataWithPublicKey($data)
function EncryptDataWithPublicKey($data)
{

$publicKey = "-----BEGIN PUBLIC KEY-----\n" . $this->getPgPublicKey() . "\n-----END PUBLIC KEY-----";
Expand Down Expand Up @@ -97,16 +101,15 @@ public function SignatureGenerate($data)
}

/**
* @param $PostURL
* @param $PostData
* @param string $postUrl
* @param array $postData
* @return array|mixed
* @since v1.3.1
*/
public function HttpPostMethod($PostURL, $PostData)
public function HttpPostMethod(string $postUrl, array $postData)
{

$url = curl_init($PostURL);
$postToken = json_encode($PostData);
$url = curl_init($postUrl);
$postToken = json_encode($postData);
$header = array(
'Content-Type:application/json',
'X-KM-Api-Version:v-0.2.0',
Expand Down Expand Up @@ -175,15 +178,15 @@ public function getClientIP()
{
if (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
} else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else if (isset($_SERVER['HTTP_X_FORWARDED'])) {
} elseif (isset($_SERVER['HTTP_X_FORWARDED'])) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
} else if (isset($_SERVER['HTTP_FORWARDED_FOR'])) {
} elseif (isset($_SERVER['HTTP_FORWARDED_FOR'])) {
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
} else if (isset($_SERVER['HTTP_FORWARDED'])) {
} elseif (isset($_SERVER['HTTP_FORWARDED'])) {
$ipaddress = $_SERVER['HTTP_FORWARDED'];
} else if (isset($_SERVER['REMOTE_ADDR'])) {
} elseif (isset($_SERVER['REMOTE_ADDR'])) {
$ipaddress = $_SERVER['REMOTE_ADDR'];
} else {
$ipaddress = 'UNKNOWN IP';
Expand Down Expand Up @@ -230,21 +233,22 @@ public static function generateFakeInvoice($length = 20, $capitalize = false, $p
public static function errorLog($data)
{
if (!file_exists('logs/nagadApi') && !mkdir('logs', 0775) && !is_dir('logs')) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', 'logs'));
throw new RuntimeException(sprintf('Directory "%s" was not created', 'logs'));
}

if (!file_exists('logs/nagadApi/error.log')) {
$errorLogFile = 'logs/nagadApi/error.log';
if (!file_exists($errorLogFile)) {

$logFile = "logs/error.log";
$fh = fopen($logFile, 'w+') or die("can't open file");
fclose($fh);
chmod($logFile, 0755);
}
$date = '=====================' . date('Y-m-d H:i:s') . '=============================================\n';
file_put_contents('logs/nagadApi/error.log', print_r($date, true), FILE_APPEND);
file_put_contents('logs/nagadApi/error.log', PHP_EOL . print_r($data, true), FILE_APPEND);
file_put_contents($errorLogFile, print_r($date, true), FILE_APPEND);
file_put_contents($errorLogFile, PHP_EOL . print_r($data, true), FILE_APPEND);
$string = '=====================' . date('Y-m-d H:i:s') . '=============================================' . PHP_EOL;
file_put_contents('logs/nagadApi/error.log', print_r($string, true), FILE_APPEND);
file_put_contents($errorLogFile, print_r($string, true), FILE_APPEND);
}

/**
Expand All @@ -271,7 +275,10 @@ public static function serverDetails()
*/
public static function successResponse($response)
{
// $response = 'https://example.com/payment/success/id=4/?merchant=683002007104225&order_id=EBSXGJ5OYQCRO7D&payment_ref_id=MTEyOTAwMjY1NDMxNi42ODMwMDIwMDcxMDQyMjUuRUJTWEdKNU9ZUUNSTzdELmExODVkYWE4MDAyMDEyM2ZlYzRl&status=Success&status_code=00_0000_000&message=Successful%20Transaction&payment_dt=20201129002747&issuer_payment_ref=MTEyOTAwMjY1NDMxNi42ODMwMDIwMDcxMDQyMjUuRUJTWEdKNU9ZUUNSTzdELmExODVkYWE4MDAyMDEyM2ZlYzRl';
// $response = 'https://example.com/payment/success/id=4/?merchant=683002007104225&order_id=EBSXGJ5OYQCRO7D&
//payment_ref_id=MTEyOTAwMjY1NDMxNi42ODMwMDIwMDcxMDQyMjUuRUJTWEdKNU9ZUUNSTzdELmExODVkYWE4MDAyMDEyM2ZlYzRl&
//status=Success&status_code=00_0000_000&message=Successful%20Transaction&payment_dt=20201129002747&
//issuer_payment_ref=MTEyOTAwMjY1NDMxNi42ODMwMDIwMDcxMDQyMjUuRUJTWEdKNU9ZUUNSTzdELmExODVkYWE4MDAyMDEyM2ZlYzRl';
$parts = parse_url($response);
parse_str($parts['query'], $query);
return $query;
Expand Down

0 comments on commit cd9b481

Please sign in to comment.