Skip to content

Commit

Permalink
add warningMessage function
Browse files Browse the repository at this point in the history
  • Loading branch information
omarxp committed Sep 14, 2021
1 parent 126bb33 commit c7e321b
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 87 deletions.
24 changes: 15 additions & 9 deletions examples/core-api/checkout-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@
// Config::$appendNotifUrl = "https://example.com";
// Config::$overrideNotifUrl = "https://example.com";

if (strpos(Config::$serverKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$serverKey = \'<your server key>\';');
die();
}
// non-relevant function only used for demo/example purpose
printExampleWarningMessage();

// Uncomment for production environment
// Config::$isProduction = true;
Expand Down Expand Up @@ -109,3 +102,16 @@
} catch (\Exception $e) {
echo $e->getMessage();
}

function printExampleWarningMessage() {
if (strpos(Config::$serverKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$serverKey = \'<your server key>\';');
die();
}
}

26 changes: 16 additions & 10 deletions examples/core-api/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
// Set Your server key
// can find in Merchant Portal -> Settings -> Access keys
Config::$clientKey = '<your client key>';
if (strpos(Config::$clientKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$clientKey = \'<your client key>\';');
die();

// non-relevant function only used for demo/example purpose
printExampleWarningMessage();

function printExampleWarningMessage() {
if (strpos(Config::$clientKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your client key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$clientKey = \'<your client key>\';');
die();
}
}
?>
<html>
Expand Down Expand Up @@ -145,12 +151,12 @@ function closeDialog() {
$(this).attr("disabled", "disabled");

console.log('1. get token_id');
MidtransNew3ds.getCardToken(card, callback);
MidtransNew3ds.getCardToken(card, getCardTokenCallback);
return false;
});

// callback functions
var callback = {
var getCardTokenCallback = {
onSuccess: function(response) {
// Success to get card token_id, implement as you wish here
console.log('Success to get card token_id, response:', response);
Expand Down
25 changes: 16 additions & 9 deletions examples/core-api/tokenization-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
// Set Your server key
// can find in Merchant Portal -> Settings -> Access keys
Config::$serverKey = '<your server key>';
if (strpos(Config::$serverKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$serverKey = \'<your server key>\';');
die();
}

// non-relevant function only used for demo/example purpose
printExampleWarningMessage();

// define variables and set to empty values
$number = "";
Expand All @@ -33,13 +27,26 @@
)
);

$response = '';
try {
$response = CoreApi::linkPaymentAccount($params);
} catch (\Exception $e) {
echo $e->getMessage();
die();
}

function printExampleWarningMessage() {
if (strpos(Config::$serverKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$serverKey = \'<your server key>\';');
die();
}
}

?>

<!DOCTYPE HTML>
Expand Down
27 changes: 17 additions & 10 deletions examples/core-api/transaction-manipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@
// Set Your server key
// can find in Merchant Portal -> Settings -> Access keys
Config::$serverKey = '<your server key>';
if (strpos(Config::$serverKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$serverKey = \'<your server key>\';');
die();
}

$orderId = '<your order id / transaction id>';
// non-relevant function only used for demo/example purpose
printExampleWarningMessage();

$orderId = '<your order id / transaction id>';
// Get transaction status to Midtrans API
$status = '';
try {
$status = Transaction::status($orderId);
} catch (\Exception $e) {
Expand All @@ -30,6 +24,19 @@
echo '<pre>';
echo json_encode($status);

function printExampleWarningMessage() {
if (strpos(Config::$serverKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$serverKey = \'<your server key>\';');
die();
}
}


// Approve a transaction that is in Challenge status
// $approve = Transaction::approve($orderId);
// var_dump($approve);
Expand Down
28 changes: 18 additions & 10 deletions examples/notification-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@
require_once dirname(__FILE__) . '/../Midtrans.php';
Config::$isProduction = false;
Config::$serverKey = '<your server key>';
if (strpos(Config::$serverKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$serverKey = \'<your server key>\';');
die();
}

// non-relevant function only used for demo/example purpose
printExampleWarningMessage();

try {
$notif = new Notification();
Expand Down Expand Up @@ -59,4 +53,18 @@
// TODO set payment status in merchant's database to 'Denied'
echo "Payment using " . $type . " for transaction order_id: " . $order_id . " is canceled.";
}
?>

function printExampleWarningMessage() {
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
echo 'Notification-handler are not meant to be opened via browser / GET HTTP method. It is used to handle Midtrans HTTP POST notification / webhook.';
}
if (strpos(Config::$serverKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$serverKey = \'<your server key>\';');
die();
}
}
24 changes: 15 additions & 9 deletions examples/snap-redirect/checkout-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@
// Set Your server key
// can find in Merchant Portal -> Settings -> Access keys
Config::$serverKey = '<your server key>';
if (strpos(Config::$serverKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$serverKey = \'<your server key>\';');
die();
}

// non-relevant function only used for demo/example purpose
printExampleWarningMessage();

// Uncomment for production environment
// Config::$isProduction = true;
Expand Down Expand Up @@ -102,3 +96,15 @@
catch (\Exception $e) {
echo $e->getMessage();
}

function printExampleWarningMessage() {
if (strpos(Config::$serverKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$serverKey = \'<your server key>\';');
die();
}
}
37 changes: 22 additions & 15 deletions examples/snap/checkout-process-simple-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@
// Set Your server key
// can find in Merchant Portal -> Settings -> Access keys
Config::$serverKey = '<your server key>';
if (strpos(Config::$serverKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$serverKey = \'<your server key>\';');
die();
}
$client_key = '<your client key>';
Config::$clientKey = '<your client key>';

// non-relevant function only used for demo/example purpose
printExampleWarningMessage();

// Uncomment for production environment
// Config::$isProduction = true;
Expand Down Expand Up @@ -54,26 +48,39 @@
'item_details' => $item_details,
);

$snapToken = '';
$snap_token = '';
try {
$snapToken = Snap::getSnapToken($transaction);
$snap_token = Snap::getSnapToken($transaction);
}
catch (\Exception $e) {
echo $e->getMessage();
}
echo "snapToken = ".$snapToken;
echo "snapToken = ".$snap_token;

function printExampleWarningMessage() {
if (strpos(Config::$serverKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$serverKey = \'<your server key>\';');
die();
}
}

?>

<!DOCTYPE html>
<html>
<body>
<button id="pay-button">Pay!</button>
<!-- TODO: Remove ".sandbox" from script src URL for production environment. Also input your client key in "data-client-key" -->
<script src="https://app.sandbox.midtrans.com/snap/snap.js" data-client-key="<?php echo $client_key;?>"></script>
<script src="https://app.sandbox.midtrans.com/snap/snap.js" data-client-key="<?php echo Config::$clientKey;?>"></script>
<script type="text/javascript">
document.getElementById('pay-button').onclick = function(){
// SnapToken acquired from previous step
snap.pay('<?php echo $snapToken?>');
snap.pay('<?php echo $snap_token?>');
};
</script>
</body>
Expand Down
37 changes: 22 additions & 15 deletions examples/snap/checkout-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@
// Set Your server key
// can find in Merchant Portal -> Settings -> Access keys
Config::$serverKey = '<your server key>';
if (strpos(Config::$serverKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$serverKey = \'<your server key>\';');
die();
}
$client_key = '<your client key>';
Config::$clientKey = '<your client key>';

// non-relevant function only used for demo/example purpose
printExampleWarningMessage();

// Uncomment for production environment
// Config::$isProduction = true;
Expand Down Expand Up @@ -101,15 +95,28 @@
'item_details' => $item_details,
);

$snapToken = '';
$snap_token = '';
try {
$snapToken = Snap::getSnapToken($transaction);
$snap_token = Snap::getSnapToken($transaction);
}
catch (\Exception $e) {
echo $e->getMessage();
}

echo "snapToken = ".$snapToken;
echo "snapToken = ".$snap_token;

function printExampleWarningMessage() {
if (strpos(Config::$serverKey, 'your ') != false ) {
echo "<code>";
echo "<h4>Please set your server key from sandbox</h4>";
echo "In file: " . __FILE__;
echo "<br>";
echo "<br>";
echo htmlspecialchars('Config::$serverKey = \'<your server key>\';');
die();
}
}

?>

<!DOCTYPE html>
Expand All @@ -119,11 +126,11 @@
<pre><div id="result-json">JSON result will appear here after payment:<br></div></pre>

<!-- TODO: Remove ".sandbox" from script src URL for production environment. Also input your client key in "data-client-key" -->
<script src="https://app.sandbox.midtrans.com/snap/snap.js" data-client-key="<?php echo $client_key;?>"></script>
<script src="https://app.sandbox.midtrans.com/snap/snap.js" data-client-key="<?php echo Config::$clientKey;?>"></script>
<script type="text/javascript">
document.getElementById('pay-button').onclick = function(){
// SnapToken acquired from previous step
snap.pay('<?php echo $snapToken?>', {
snap.pay('<?php echo $snap_token?>', {
// Optional
onSuccess: function(result){
/* You may add your own js here, this is just example */ document.getElementById('result-json').innerHTML += JSON.stringify(result, null, 2);
Expand Down

0 comments on commit c7e321b

Please sign in to comment.