From 126bb3353e8d5dc0bdb6e7b3f7511c40efbc0bd2 Mon Sep 17 00:00:00 2001 From: Komarudin Date: Mon, 13 Sep 2021 12:19:24 +0700 Subject: [PATCH] add notes and add try catch --- examples/core-api/tokenization-process.php | 24 +++++++++++++-- .../core-api/transaction-manipulation.php | 7 +++-- examples/notification-handler.php | 23 ++++++++++++-- examples/snap-redirect/checkout-process.php | 19 ++++++++++-- .../snap/checkout-process-simple-version.php | 29 +++++++++++++++--- examples/snap/checkout-process.php | 30 +++++++++++++++---- 6 files changed, 112 insertions(+), 20 deletions(-) diff --git a/examples/core-api/tokenization-process.php b/examples/core-api/tokenization-process.php index 7942c6b..fcf80e8 100644 --- a/examples/core-api/tokenization-process.php +++ b/examples/core-api/tokenization-process.php @@ -1,9 +1,21 @@ "; +// Set Your server key +// can find in Merchant Portal -> 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(); +} // define variables and set to empty values $number = ""; @@ -21,7 +33,13 @@ ) ); -$response = CoreApi::linkPaymentAccount($params); +try { + $response = CoreApi::linkPaymentAccount($params); +} catch (\Exception $e) { + echo $e->getMessage(); + die(); +} + ?> diff --git a/examples/core-api/transaction-manipulation.php b/examples/core-api/transaction-manipulation.php index 356732c..846badb 100644 --- a/examples/core-api/transaction-manipulation.php +++ b/examples/core-api/transaction-manipulation.php @@ -1,11 +1,12 @@ Settings -> Access keys Config::$serverKey = ''; - if (strpos(Config::$serverKey, 'your ') != false ) { echo ""; echo "

Please set your server key from sandbox

"; @@ -21,7 +22,7 @@ // Get transaction status to Midtrans API try { $status = Transaction::status($orderId); -} catch (Exception $e) { +} catch (\Exception $e) { echo $e->getMessage(); die(); } diff --git a/examples/notification-handler.php b/examples/notification-handler.php index 13fe318..1f05b3c 100644 --- a/examples/notification-handler.php +++ b/examples/notification-handler.php @@ -1,12 +1,31 @@ '; -$notif = new Notification(); +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(); +} + +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; diff --git a/examples/snap-redirect/checkout-process.php b/examples/snap-redirect/checkout-process.php index 5b5fcbc..4eb6aec 100644 --- a/examples/snap-redirect/checkout-process.php +++ b/examples/snap-redirect/checkout-process.php @@ -1,10 +1,23 @@ "; +// Set Your server key +// can find in Merchant Portal -> 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(); +} // Uncomment for production environment // Config::$isProduction = true; @@ -86,6 +99,6 @@ // Redirect to Snap Payment Page header('Location: ' . $paymentUrl); } -catch (Exception $e) { +catch (\Exception $e) { echo $e->getMessage(); } diff --git a/examples/snap/checkout-process-simple-version.php b/examples/snap/checkout-process-simple-version.php index fe896e3..ee53703 100644 --- a/examples/snap/checkout-process-simple-version.php +++ b/examples/snap/checkout-process-simple-version.php @@ -1,10 +1,25 @@ "; +// Set Your server key +// can find in Merchant Portal -> 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(); +} +$client_key = ''; + // Uncomment for production environment // Config::$isProduction = true; Config::$isSanitized = Config::$is3ds = true; @@ -39,7 +54,13 @@ 'item_details' => $item_details, ); -$snapToken = Snap::getSnapToken($transaction); +$snapToken = ''; +try { + $snapToken = Snap::getSnapToken($transaction); +} +catch (\Exception $e) { + echo $e->getMessage(); +} echo "snapToken = ".$snapToken; ?> @@ -48,7 +69,7 @@ - + +