diff --git a/examples/core-api/checkout-process.php b/examples/core-api/checkout-process.php index 2000984..cb1e88d 100644 --- a/examples/core-api/checkout-process.php +++ b/examples/core-api/checkout-process.php @@ -1,27 +1,19 @@ '; // Uncomment for append and override notification URL // Config::$appendNotifUrl = "https://example.com"; // Config::$overrideNotifUrl = "https://example.com"; -if (strpos(Config::$serverKey, 'your ') != false ) { - echo ""; - echo "

Please set your server key from sandbox

"; - echo "In file: " . __FILE__; - echo "
"; - echo "
"; - echo htmlspecialchars('Config::$serverKey = \'\';'); - die(); -} +// non-relevant function only used for demo/example purpose +printExampleWarningMessage(); // Uncomment for production environment // Config::$isProduction = true; @@ -86,14 +78,17 @@ // Token ID from checkout page $token_id = $_POST['token_id']; +$authentication = isset($_POST['secure']); +$save_token_id = isset($_POST['save_cc']); // Transaction data to be sent $transaction_data = array( 'payment_type' => 'credit_card', 'credit_card' => array( - 'token_id' => $token_id, - // 'bank' => 'bni', // optional acquiring bank, must be the same bank with get-token bank - 'save_token_id' => isset($_POST['save_cc']) + 'token_id' => $token_id, + 'authentication' => $authentication, + // 'bank' => 'bni', // optional acquiring bank + 'save_token_id' => $save_token_id ), 'transaction_details' => $transaction_details, 'item_details' => $items, @@ -102,56 +97,21 @@ try { $response = CoreApi::charge($transaction_data); -} catch (Exception $e) { + header('Content-Type: application/json'); + echo json_encode($response); +} catch (\Exception $e) { echo $e->getMessage(); - die(); } -// Success -if ($response->transaction_status == 'capture') { - echo "

Transaksi berhasil.

"; - echo "

Status transaksi untuk order id $response->order_id: " . - "$response->transaction_status

"; - - echo "

Detail transaksi:

"; - echo "
";
-    var_dump($response);
-    echo "
"; -} -// Deny -else if ($response->transaction_status == 'deny') { - echo "

Transaksi ditolak.

"; - echo "

Status transaksi untuk order id .$response->order_id: " . - "$response->transaction_status

"; - echo "

Detail transaksi:

"; - echo "
";
-    var_dump($response);
-    echo "
"; -} -// Challenge -else if ($response->transaction_status == 'challenge') { - echo "

Transaksi challenge.

"; - echo "

Status transaksi untuk order id $response->order_id: " . - "$response->transaction_status

"; - - echo "

Detail transaksi:

"; - echo "
";
-    var_dump($response);
-    echo "
"; -} -// Error -else { - echo "

Terjadi kesalahan pada data transaksi yang dikirim.

"; - echo "

Status message: [$response->status_code] " . - "$response->status_message

"; - - echo "
";
-    var_dump($response);
-    echo "
"; +function printExampleWarningMessage() { + if (strpos(Config::$serverKey, 'your ') != false ) { + echo ""; + echo "

Please set your server key from sandbox

"; + echo "In file: " . __FILE__; + echo "
"; + echo "
"; + echo htmlspecialchars('Config::$serverKey = \'\';'); + die(); + } } -echo "
"; -echo "

Request

"; -echo "
";
-var_dump($response);
-echo "
"; diff --git a/examples/core-api/checkout.php b/examples/core-api/checkout.php index fb37298..07ecf67 100644 --- a/examples/core-api/checkout.php +++ b/examples/core-api/checkout.php @@ -1,17 +1,28 @@ Settings -> Access keys -Config::$clientKey = ""; - -if (strpos(Config::$clientKey, 'your ') != false ) { - echo "

"; - echo "Please set your client key in file " . __FILE__; - echo "

"; +Config::$clientKey = ''; + +// non-relevant function only used for demo/example purpose +printExampleWarningMessage(); + +function printExampleWarningMessage() { + if (strpos(Config::$clientKey, 'your ') != false ) { + echo ""; + echo "

Please set your client key from sandbox

"; + echo "In file: " . __FILE__; + echo "
"; + echo "
"; + echo htmlspecialchars('Config::$clientKey = \'\';'); + die(); + } } ?> @@ -22,7 +33,7 @@ - + @@ -33,29 +44,27 @@ Field that may be presented to customer:

- +

- + / - +

- +

- +

- Fields that shouldn't be presented to the customer:

- +

- @@ -84,35 +93,24 @@ diff --git a/examples/core-api/tokenization-process.php b/examples/core-api/tokenization-process.php index 7942c6b..20dc907 100644 --- a/examples/core-api/tokenization-process.php +++ b/examples/core-api/tokenization-process.php @@ -1,9 +1,15 @@ "; +// Set Your server key +// can find in Merchant Portal -> Settings -> Access keys +Config::$serverKey = ''; + +// non-relevant function only used for demo/example purpose +printExampleWarningMessage(); // define variables and set to empty values $number = ""; @@ -21,7 +27,26 @@ ) ); -$response = CoreApi::linkPaymentAccount($params); +$response = ''; +try { + $response = CoreApi::linkPaymentAccount($params); +} catch (\Exception $e) { + echo $e->getMessage(); + die(); +} + +function printExampleWarningMessage() { + if (strpos(Config::$serverKey, 'your ') != false ) { + echo ""; + echo "

Please set your server key from sandbox

"; + echo "In file: " . __FILE__; + echo "
"; + echo "
"; + echo htmlspecialchars('Config::$serverKey = \'\';'); + die(); + } +} + ?> diff --git a/examples/core-api/transaction-manipulation.php b/examples/core-api/transaction-manipulation.php index 356732c..8053bc9 100644 --- a/examples/core-api/transaction-manipulation.php +++ b/examples/core-api/transaction-manipulation.php @@ -1,27 +1,22 @@ Settings -> Access keys Config::$serverKey = ''; -if (strpos(Config::$serverKey, 'your ') != false ) { - echo ""; - echo "

Please set your server key from sandbox

"; - echo "In file: " . __FILE__; - echo "
"; - echo "
"; - echo htmlspecialchars('Config::$serverKey = \'\';'); - die(); -} +// non-relevant function only used for demo/example purpose +printExampleWarningMessage(); $orderId = ''; - // Get transaction status to Midtrans API +$status = ''; try { $status = Transaction::status($orderId); -} catch (Exception $e) { +} catch (\Exception $e) { echo $e->getMessage(); die(); } @@ -29,6 +24,19 @@ echo '
';
 echo json_encode($status);
 
+function printExampleWarningMessage() {
+    if (strpos(Config::$serverKey, 'your ') != false ) {
+        echo "";
+        echo "

Please set your server key from sandbox

"; + echo "In file: " . __FILE__; + echo "
"; + echo "
"; + echo htmlspecialchars('Config::$serverKey = \'\';'); + die(); + } +} + + // Approve a transaction that is in Challenge status // $approve = Transaction::approve($orderId); // var_dump($approve); diff --git a/examples/notification-handler.php b/examples/notification-handler.php index 13fe318..a010033 100644 --- a/examples/notification-handler.php +++ b/examples/notification-handler.php @@ -1,12 +1,25 @@ '; -$notif = new Notification(); +Config::$serverKey = ''; +// non-relevant function only used for demo/example purpose +printExampleWarningMessage(); + +try { + $notif = new Notification(); +} +catch (\Exception $e) { + exit($e->getMessage()); +} + +$notif = $notif->getResponse(); $transaction = $notif->transaction_status; $type = $notif->payment_type; $order_id = $notif->order_id; @@ -40,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."; } -?> \ No newline at end of file + +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 ""; + echo "

Please set your server key from sandbox

"; + echo "In file: " . __FILE__; + echo "
"; + echo "
"; + echo htmlspecialchars('Config::$serverKey = \'\';'); + die(); + } +} diff --git a/examples/snap-redirect/checkout-process.php b/examples/snap-redirect/checkout-process.php index 5b5fcbc..2e92eaf 100644 --- a/examples/snap-redirect/checkout-process.php +++ b/examples/snap-redirect/checkout-process.php @@ -1,10 +1,17 @@ "; +// Set Your server key +// can find in Merchant Portal -> Settings -> Access keys +Config::$serverKey = ''; + +// non-relevant function only used for demo/example purpose +printExampleWarningMessage(); // Uncomment for production environment // Config::$isProduction = true; @@ -86,6 +93,18 @@ // Redirect to Snap Payment Page header('Location: ' . $paymentUrl); } -catch (Exception $e) { +catch (\Exception $e) { echo $e->getMessage(); } + +function printExampleWarningMessage() { + if (strpos(Config::$serverKey, 'your ') != false ) { + echo ""; + echo "

Please set your server key from sandbox

"; + echo "In file: " . __FILE__; + echo "
"; + echo "
"; + echo htmlspecialchars('Config::$serverKey = \'\';'); + die(); + } +} diff --git a/examples/snap/checkout-process-simple-version.php b/examples/snap/checkout-process-simple-version.php index fe896e3..9b9c535 100644 --- a/examples/snap/checkout-process-simple-version.php +++ b/examples/snap/checkout-process-simple-version.php @@ -1,10 +1,19 @@ "; +// Set Your server key +// can find in Merchant Portal -> Settings -> Access keys +Config::$serverKey = ''; +Config::$clientKey = ''; + +// non-relevant function only used for demo/example purpose +printExampleWarningMessage(); + // Uncomment for production environment // Config::$isProduction = true; Config::$isSanitized = Config::$is3ds = true; @@ -39,8 +48,27 @@ 'item_details' => $item_details, ); -$snapToken = Snap::getSnapToken($transaction); -echo "snapToken = ".$snapToken; +$snap_token = ''; +try { + $snap_token = Snap::getSnapToken($transaction); +} +catch (\Exception $e) { + echo $e->getMessage(); +} +echo "snapToken = ".$snap_token; + +function printExampleWarningMessage() { + if (strpos(Config::$serverKey, 'your ') != false ) { + echo ""; + echo "

Please set your server key from sandbox

"; + echo "In file: " . __FILE__; + echo "
"; + echo "
"; + echo htmlspecialchars('Config::$serverKey = \'\';'); + die(); + } +} + ?> @@ -48,11 +76,11 @@ - + diff --git a/examples/snap/checkout-process.php b/examples/snap/checkout-process.php index d5b61f9..57a8a27 100644 --- a/examples/snap/checkout-process.php +++ b/examples/snap/checkout-process.php @@ -1,11 +1,18 @@ Settings -> Access keys +Config::$serverKey = ''; +Config::$clientKey = ''; -//Set Your server key -Config::$serverKey = ""; +// non-relevant function only used for demo/example purpose +printExampleWarningMessage(); // Uncomment for production environment // Config::$isProduction = true; @@ -88,8 +95,28 @@ 'item_details' => $item_details, ); -$snapToken = Snap::getSnapToken($transaction); -echo "snapToken = ".$snapToken; +$snap_token = ''; +try { + $snap_token = Snap::getSnapToken($transaction); +} +catch (\Exception $e) { + echo $e->getMessage(); +} + +echo "snapToken = ".$snap_token; + +function printExampleWarningMessage() { + if (strpos(Config::$serverKey, 'your ') != false ) { + echo ""; + echo "

Please set your server key from sandbox

"; + echo "In file: " . __FILE__; + echo "
"; + echo "
"; + echo htmlspecialchars('Config::$serverKey = \'\';'); + die(); + } +} + ?> @@ -99,11 +126,11 @@
JSON result will appear here after payment:
- +