Skip to content

Commit 4f435e9

Browse files
committed
2 parents 69581d6 + 255a923 commit 4f435e9

10 files changed

Lines changed: 89 additions & 55 deletions

File tree

src/Commands/MidtransCommand.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Codenom\Midtrans\Commands;
44

5-
use Config\Autoload;
6-
use CodeIgniter\CLI\CLI;
75
use CodeIgniter\CLI\BaseCommand;
6+
use CodeIgniter\CLI\CLI;
7+
use Config\Autoload;
88

99
class MidtransCommand extends BaseCommand
1010
{
@@ -14,12 +14,13 @@ class MidtransCommand extends BaseCommand
1414

1515
/**
1616
* Private or protected function
17-
*
17+
*
1818
* @var string
1919
*/
2020
protected $sourcePath;
2121

2222
//--------------------------------------------------------------------
23+
2324
/**
2425
* Copy config file
2526
*
@@ -37,26 +38,30 @@ public function run(array $params)
3738
*/
3839
protected function determineSourcePath()
3940
{
40-
$this->sourcePath = realpath(__DIR__ . '/../');
41+
$this->sourcePath = \realpath(__DIR__ . '/../');
4142
if ($this->sourcePath == '/' || empty($this->sourcePath)) {
4243
CLI::error('Unable to determine the correct source directory. Bailing.');
4344
exit();
4445
}
4546
}
47+
4648
//--------------------------------------------------------------------
49+
4750
/**
4851
* Publish config file.
4952
*/
5053
protected function publishConfig()
5154
{
5255
$path = "{$this->sourcePath}/Config/Midtrans.php";
53-
$content = file_get_contents($path);
54-
$content = str_replace('use CodeIgniter\Config\BaseConfig', "use Codenom\Midtrans\Config\Midtrans as MidtransConfig", $content);
55-
$content = str_replace('namespace Codenom\Midtrans\Config', "namespace Config", $content);
56-
$content = str_replace('extends BaseConfig', "extends MidtransConfig", $content);
56+
$content = \file_get_contents($path);
57+
$content = \str_replace('use CodeIgniter\Config\BaseConfig', "use Codenom\Midtrans\Config\Midtrans as MidtransConfig", $content);
58+
$content = \str_replace('namespace Codenom\Midtrans\Config', 'namespace Config', $content);
59+
$content = \str_replace('extends BaseConfig', 'extends MidtransConfig', $content);
5760
$this->writeFile('Config/Midtrans.php', $content);
5861
}
62+
5963
//--------------------------------------------------------------------
64+
6065
/**
6166
* Write a file, catching any exceptions and showing a nicely formatted error.
6267
*
@@ -67,11 +72,11 @@ protected function writeFile(string $path, string $content)
6772
{
6873
$config = new Autoload();
6974
$appPath = $config->psr4[APP_NAMESPACE];
70-
$directory = dirname($appPath . $path);
71-
if (!is_dir($directory)) {
72-
mkdir($directory, 0777, true);
75+
$directory = \dirname($appPath . $path);
76+
if (!\is_dir($directory)) {
77+
\mkdir($directory, 0777, true);
7378
}
74-
if (file_exists($appPath . $path) && CLI::prompt('Config file already exists, do you want to replace it?', ['y', 'n']) == 'n') {
79+
if (\file_exists($appPath . $path) && CLI::prompt('Config file already exists, do you want to replace it?', ['y', 'n']) == 'n') {
7580
CLI::error('Cancelled');
7681
exit();
7782
}
@@ -81,8 +86,9 @@ protected function writeFile(string $path, string $content)
8186
$this->showError($e);
8287
exit();
8388
}
84-
$path = str_replace($appPath, '', $path);
89+
$path = \str_replace($appPath, '', $path);
8590
CLI::write(CLI::color('Created: ', 'yellow') . $path);
8691
}
92+
8793
//--------------------------------------------------------------------
8894
}

src/Config/Midtrans.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/**
44
* @see https://github.com/codenomdev/codeigniter4-midtrans for the canonical source repository
5+
*
56
* @copyright 2020 - Codenom Dev (https://codenom.com).
67
* @license https://github.com/codenomdev/codeigniter4-midtrans/blob/main/LICENSE MIT License
78
*/
@@ -14,49 +15,40 @@ class Midtrans extends BaseConfig
1415
{
1516
/**
1617
* Your merchant's server key
17-
*
1818
*/
1919
public $serverKey = '';
2020
/**
2121
* Your merchant's client key
22-
*
2322
*/
2423
public $clientKey = '';
2524
/**
2625
* Your ID merchant's key
27-
*
2826
*/
2927
public $idMerchant = '';
3028
/**
3129
* True for production
3230
* false for sandbox mode
33-
*
3431
*/
3532
public $isProduction = false;
3633
/**
3734
* Set it true to enable 3D Secure by default
38-
*
3935
*/
4036
public $is3ds = false;
4137
/**
4238
* Set Append URL notification
43-
*
4439
*/
4540
public $appendNotifUrl = '';
4641
/**
4742
* Set Override URL notification
48-
*
4943
*/
5044
public $overrideNotifUrl = '';
5145
/**
5246
* Enable request params sanitizer (validate and modify charge request params).
5347
* See Midtrans_Sanitizer for more details
54-
*
5548
*/
5649
public $isSanitized = false;
5750
/**
5851
* Default options for every request
59-
*
6052
*/
61-
public $curlOptions = array();
53+
public $curlOptions = [];
6254
}

src/Config/Services.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/**
44
* @see https://github.com/codenomdev/codeigniter4-midtrans for the canonical source repository
5+
*
56
* @copyright 2020 - Codenom Dev (https://codenom.com).
67
* @license https://github.com/codenomdev/codeigniter4-midtrans/blob/main/LICENSE MIT License
78
*/
@@ -21,6 +22,7 @@ public static function Midtrans(MidtransConfig $midtransConfig = null, bool $get
2122
return self::getSharedInstance('Midtrans', $midtransConfig);
2223
}
2324
$midtransConfig = $midtransConfig ?? config('Midtrans');
25+
2426
return new Midtrans($midtransConfig);
2527
}
2628

@@ -30,6 +32,7 @@ public static function Veritrans(MidtransConfig $midtransConfig = null, bool $ge
3032
return self::getSharedInstance('Veritrans', $midtransConfig);
3133
}
3234
$midtransConfig = $midtransConfig ?? config('Midtrans');
35+
3336
return new Veritrans($midtransConfig);
3437
}
3538
}

src/Constant.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/**
44
* @see https://github.com/codenomdev/codeigniter4-midtrans for the canonical source repository
5+
*
56
* @copyright 2020 - Codenom Dev (https://codenom.com).
67
* @license https://github.com/codenomdev/codeigniter4-midtrans/blob/main/LICENSE MIT License
78
*/
@@ -12,53 +13,57 @@ class Constant
1213
{
1314
/**
1415
* Constant value Base Veritrans
15-
*
16+
*
1617
* @return Sandbox Base URL Veritrans
18+
*
1719
* @version 2.0
1820
*/
1921
const SANDBOX_BASE_URL = 'https://api.sandbox.veritrans.co.id/v2';
2022
/**
2123
* Constant value Base Veritrans
22-
*
24+
*
2325
* @return production Base URL Veritrans
26+
*
2427
* @version 2.0
2528
*/
2629
const PRODUCTION_BASE_URL = 'https://api.veritrans.co.id/v2';
2730
/**
2831
* Constant value Base Midtrans
29-
*
32+
*
3033
* @return Sandbox Base URL Midtrans
34+
*
3135
* @version 1.0
3236
*/
3337
const SNAP_SANDBOX_BASE_URL = 'https://app.sandbox.midtrans.com/snap/v1';
3438
/**
3539
* Constant value Base Midtrans
36-
*
40+
*
3741
* @return Production Base URL Midtrans
42+
*
3843
* @version 1.0
3944
*/
4045
const SNAP_PRODUCTION_BASE_URL = 'https://app.midtrans.com/snap/v1';
4146
/**
4247
* CURL type POST
43-
*
48+
*
4449
* @return string
4550
*/
4651
const CURL_TYPE_POST = 'POST';
4752
/**
4853
* CURL type GET
49-
*
54+
*
5055
* @return string
5156
*/
5257
const CURL_TYPE_GET = 'GET';
5358
/**
5459
* Content Type Header request
55-
*
60+
*
5661
* @return string
5762
*/
5863
const CONTENT_TYPE = 'application/json';
5964
/**
6065
* Accpet Header request
61-
*
66+
*
6267
* @return string
6368
*/
6469
const ACCEPT = 'application/json';

src/Exceptions/VeritransException.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/**
44
* @see https://github.com/codenomdev/codeigniter4-midtrans for the canonical source repository
5+
*
56
* @copyright 2020 - Codenom Dev (https://codenom.com).
67
* @license https://github.com/codenomdev/codeigniter4-midtrans/blob/main/LICENSE MIT License
78
*/

src/HTTP/APIMidtrans.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/**
44
* @see https://github.com/codenomdev/codeigniter4-midtrans for the canonical source repository
5+
*
56
* @copyright 2020 - Codenom Dev (https://codenom.com).
67
* @license https://github.com/codenomdev/codeigniter4-midtrans/blob/main/LICENSE MIT License
78
*/
@@ -11,18 +12,19 @@
1112
class APIMidtrans
1213
{
1314
/**
14-
*
15-
* @var $typeCURL = \Codenom\Midtrans\Constant::CURL_TYPE_GET (default GET)
15+
* @var = \Codenom\Midtrans\Constant::CURL_TYPE_GET (default GET)
1616
* @var \Codenom\Midtrans\Parse\JSONParse::encode($options)
17-
* @var string $endPoint URL
18-
* @param array $options = [] //for sent data to API Midtrans
17+
* @var string URL
18+
*
19+
* @param array $options = [] //for sent data to API Midtrans
1920
* @param string $serverKey \Codenom\Midtrans\Config\Midtrans
20-
*
21-
* @return Object response body
21+
*
22+
* @return object response body
2223
*/
2324
public static function call($typeCURL = \Codenom\Midtrans\Constant::CURL_TYPE_GET, string $endPoint = '', string $serverKey = '', array $options = [])
2425
{
2526
$services = \CodeIgniter\Config\Services::curlrequest();
27+
2628
return $services->setBody(
2729
\Codenom\Midtrans\Parse\JSONParse::encode($options)
2830
)
@@ -32,7 +34,7 @@ public static function call($typeCURL = \Codenom\Midtrans\Constant::CURL_TYPE_GE
3234
['headers' => [
3335
'Content-type' => \Codenom\Midtrans\Constant::CONTENT_TYPE,
3436
'Accept' => \Codenom\Midtrans\Constant::ACCEPT,
35-
'Authorization' => 'Basic ' . base64_encode($serverKey . ':')
37+
'Authorization' => 'Basic ' . \base64_encode($serverKey . ':'),
3638
]]
3739
)->getBody();
3840
}

src/Libraries/Midtrans.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/**
44
* @see https://github.com/codenomdev/codeigniter4-midtrans for the canonical source repository
5+
*
56
* @copyright 2020 - Codenom Dev (https://codenom.com).
67
* @license https://github.com/codenomdev/codeigniter4-midtrans/blob/main/LICENSE MIT License
78
*/
@@ -12,7 +13,7 @@ class Midtrans
1213
{
1314
/**
1415
* Property Protected
15-
*
16+
*
1617
* @var \Codenom\Midtrans\Config\Midtrans;
1718
*/
1819
protected $config;
@@ -24,7 +25,7 @@ public function __construct()
2425

2526
/**
2627
* Get baseUrl
27-
*
28+
*
2829
* @return string Midtrans API URL, depends on public $isProduction
2930
*/
3031
public function getBaseUrl()
@@ -35,7 +36,7 @@ public function getBaseUrl()
3536

3637
/**
3738
* Get snapBaseUrl
38-
*
39+
*
3940
* @return string Snap API URL, depends on public $isProduction
4041
*/
4142
public function getSnapBaseUrl()

src/Midtrans.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/**
44
* @see https://github.com/codenomdev/codeigniter4-midtrans for the canonical source repository
5+
*
56
* @copyright 2020 - Codenom Dev (https://codenom.com).
67
* @license https://github.com/codenomdev/codeigniter4-midtrans/blob/main/LICENSE MIT License
78
*/
@@ -25,8 +26,9 @@ class Midtrans
2526

2627
/**
2728
* Construct builder class
28-
*
29+
*
2930
* @param $config \Codenom\Midtrans\Config\Midtrans
31+
*
3032
* @var \Codenom\Midtrans\Libraries\Midtrans
3133
*/
3234
public function __construct($config = null)
@@ -39,9 +41,11 @@ public function __construct($config = null)
3941
* Payment with SNAP Midtrans
4042
* Data to Decode before sent CURL Request
4143
* After get response from CURL, then parsing data encode to decode [Object]
42-
*
44+
*
4345
* @var Type CURL POST = \Codenom\Midtrans\Constant::CURL_TYPE_POST
46+
*
4447
* @param array $placeOrder
48+
*
4549
* @return object response CURL
4650
*/
4751
public function getSnapToken(array $placeOrder = [])

0 commit comments

Comments
 (0)