Skip to content

Commit

Permalink
init credentials from env it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
SangminLee committed Sep 18, 2020
1 parent d1ea817 commit 612d1bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
8 changes: 4 additions & 4 deletions samples/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ function dump()
//putenv('TENDOPAY_SANDBOX_ENABLED=true');

$config = [
'MERCHANT_ID' => $credentials->merchant_id,
'MERCHANT_SECRET' => $credentials->merchant_secret,
'CLIENT_ID' => $credentials->client_id,
'CLIENT_SECRET' => $credentials->client_secret,
'MERCHANT_ID' => $credentials->merchant_id ?? '',
'MERCHANT_SECRET' => $credentials->merchant_secret ?? '',
'CLIENT_ID' => $credentials->client_id ?? '',
'CLIENT_SECRET' => $credentials->client_secret ?? '',
'REDIRECT_URL' => $credentials->redirect_url ?? '',
'ERROR_REDIRECT_URL' => $credentials->error_redirect_url ?? '',
'TENDOPAY_SANDBOX_ENABLED' => true,
Expand Down
18 changes: 17 additions & 1 deletion samples/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
<?php

session_start();

$initCredentials = $_SESSION['credentials'] ?? '{}';
$initCredentials = $_SESSION['credentials'] ?? null;

if (!$initCredentials) {
if (getenv('MERCHANT_ID')) {
$initCredentials['merchant_id'] = getenv('MERCHANT_ID');
}
if (getenv('MERCHANT_SECRET')) {
$initCredentials['merchant_secret'] = getenv('MERCHANT_SECRET');
}
if (getenv('CLIENT_ID')) {
$initCredentials['client_id'] = getenv('CLIENT_ID');
}
if (getenv('CLIENT_SECRET')) {
$initCredentials['client_secret'] = getenv('CLIENT_SECRET');
}
}

require __DIR__.'/index.html.php';

0 comments on commit 612d1bd

Please sign in to comment.