-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotification-handler.php
More file actions
58 lines (46 loc) · 2.33 KB
/
notification-handler.php
File metadata and controls
58 lines (46 loc) · 2.33 KB
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
51
52
53
54
55
56
<?php
require_once 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
Midtrans\Config::$isProduction = false;
Midtrans\Config::$serverKey = $_ENV['MIDTRANS_SERVER_KEY'];
$notif = new Midtrans\Notification();
$transaction = $notif->transaction_status;
$type = $notif->payment_type;
$order_id = $notif->order_id;
$fraud = $notif->fraud_status;
$tanggal = $notif->transaction_time;
$matauang = $notif->currency;
$message = 'ok';
if ($transaction == 'capture') {
// For credit card transaction, we need to check whether transaction is challenge by FDS or not
if ($type == 'credit_card') {
if ($fraud == 'challenge') {
// set payment status in merchant's database to 'Challenge by FDS'
// merchant should decide whether this transaction is authorized or not in MAP
$message = "Transaction order_id: " . $order_id . " is challenged by FDS";
} else {
// set payment status in merchant's database to 'Success'
$message = "Transaction order_id: " . $order_id . " successfully captured using " . $type;
}
}
} elseif ($transaction == 'settlement') {
// set payment status in merchant's database to 'Settlement'
$message = "Transaction order_id: " . $order_id . " successfully transfered using " . $type . " Pada tanggal " . $tanggal . "Dibayar dengan uang ". $matauang;
} elseif ($transaction == 'pending') {
// set payment status in merchant's database to 'Pending'
$message = "Waiting customer to finish transaction order_id: " . $order_id . " using " . $type;
} elseif ($transaction == 'deny') {
// set payment status in merchant's database to 'Denied'
$message = "Payment using " . $type . " for transaction order_id: " . $order_id . " is denied.";
} elseif ($transaction == 'expire') {
// set payment status in merchant's database to 'expire'
$message = "Payment using " . $type . " for transaction order_id: " . $order_id . " is expired.";
} elseif ($transaction == 'cancel') {
// set payment status in merchant's database to 'Denied'
$message = "Payment using " . $type . " for transaction order_id: " . $order_id . " is canceled.";
}
$filename = $order_id . ".txt";
$dirpath = 'log';
is_dir($dirpath) || mkdir($dirpath, 0777, true);
json_decode( file_put_contents($dirpath . "/" . $filename, $message));