-
Notifications
You must be signed in to change notification settings - Fork 111
/
transaction-manipulation.php
50 lines (40 loc) · 1.36 KB
/
transaction-manipulation.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
<?php
// This is just for very basic implementation reference, in production, you should validate the incoming requests and implement your backend more securely.
namespace Midtrans;
require_once dirname(__FILE__) . '/../../Midtrans.php';
// Set Your server key
// can find in Merchant Portal -> Settings -> Access keys
Config::$serverKey = '<your server key>';
// 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) {
echo $e->getMessage();
die();
}
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);
// Cancel a transaction
// $cancel = Transaction::cancel($orderId);
// var_dump($cancel);
// Expire a transaction
// $expire = Transaction::expire($orderId);
// var_dump($expire);