-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsetup.php
61 lines (49 loc) · 2.21 KB
/
setup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
use Flutterwave\Helper;
use Dotenv\Dotenv;
$flutterwave_installation = 'composer';
if( !file_exists( '.env' ) && !is_dir('vendor')) {
$dotenv = Dotenv::createImmutable(__DIR__."/../../../"); # on the event that the package is install via composer.
} else {
$flutterwave_installation = "manual";
$dotenv = Dotenv::createImmutable(__DIR__); # on the event that the package is forked or donwload directly from Github.
}
$dotenv->safeLoad();
//check if the current version of php is compatible
if(!Helper\CheckCompatibility::isCompatible())
{
if (PHP_SAPI === 'cli') {
echo "❌ Flutterwave: This SDK only support php version ". Helper\CheckCompatibility::MINIMUM_COMPATIBILITY. " or greater.";
} else {
echo "Flutterwave: This SDK only support php version ". Helper\CheckCompatibility::MINIMUM_COMPATIBILITY. " or greater.";
}
exit;
}
// check for required key in ENV super global
$flutterwaveKeys = ["SECRET_KEY","PUBLIC_KEY","ENV", "ENCRYPTION_KEY"];
asort($flutterwaveKeys);
try{
foreach($flutterwaveKeys as $key)
{
$new_key = sprintf( 'FLW_%s', $key );
if(empty($_ENV[ $new_key ]) && empty(\getenv($new_key)) && empty($_ENV[ $key ]) && empty(\getenv($key)))
{
throw new InvalidArgumentException("$new_key or $key environment variable missing.");
}
}
}catch(\Exception $e)
{
if (PHP_SAPI === 'cli') {
echo "❌❌Flutterwave sdk: " .$e->getMessage();
echo "Kindly create a .env in the project root and add the required environment variables. ❌". PHP_EOL;
} else {
echo "Flutterwave: Setup incomplete. check your environment variables are set currently. confirm .env contains the required variables.";
}
exit;
}
$keys = [
'SECRET_KEY' => $_ENV['FLW_SECRET_KEY'] ?? ($_ENV['SECRET_KEY'] ?? getenv('FLW_SECRET_KEY') ?: getenv('SECRET_KEY')),
'PUBLIC_KEY' => $_ENV['FLW_PUBLIC_KEY'] ?? ($_ENV['PUBLIC_KEY'] ?? getenv('FLW_PUBLIC_KEY') ?: getenv('PUBLIC_KEY')),
'ENV' => $_ENV['FLW_ENV'] ?? ($_ENV['ENV'] ?? getenv('FLW_ENV') ?: getenv('ENV')),
'ENCRYPTION_KEY' => $_ENV['FLW_ENCRYPTION_KEY'] ?? ($_ENV['ENCRYPTION_KEY'] ?? getenv('FLW_ENCRYPTION_KEY') ?: getenv('ENCRYPTION_KEY'))
];