-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction-edit-payment-method.php
111 lines (95 loc) · 3.49 KB
/
transaction-edit-payment-method.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
session_start();
// cek apakah cust sudah login
if (!isset($_SESSION['customer_id'])) {
header("Location: ./login.php");
exit();
}
// JIKA TIDAK ADA ORDER YANG DIUBAH PEMBAYARANNYA ARAHKAN KE HAL ORDER
if (!isset($_GET['order_id'])) {
header("Location: ./transactions.php");
exit();
}
require_once('data/order.php');
require_once('data/payment_method.php');
// LIST TEMP ERROR
$errors = [];
// AMBIL SELURUH ORDERAN CUST X
$order = find_order($_SESSION['customer_id'], $_GET['order_id']);
// AMBIL SELURUH METHODE PEMBAYARAN
$payment_methods = get_payment_methods();
// JIKA TIDAK ADA ORDERAN
if (!$order) {
header("Location: ./transactions.php");
exit();
}
// JIKA STATUS ORDERAN TELAH TERBAYAR
if ($order['order_status'] == 'paid') {
header("Location: ./transaction-single.php?order_id=" . $_GET['order_id']);
exit();
}
// JIKA TOMBOL SIMPAN (SUBMIT) DIKLIK
if (isset($_POST['submit'])) {
// JIKA METHODE PEMBAYARAN DIPILIH
if (isset($_POST['payment_method_id'])) {
// UPDATE METHODE PEMBAYARAN
update_order($_SESSION['customer_id'], $_GET['order_id'], $_POST['payment_method_id']);
header("Location: ./transaction-single.php?order_id=" . $_GET['order_id']);
exit();
}
// ISI ERROR MSG
$errors['payment_method_id'] = 'Pilih satu metode pembayaran.';
}
// HEADER
$title = 'Ubah Metode Pembayaran Transaksi';
require('layouts/header.php');
?>
<!-- css customs -->
<link rel="stylesheet" href="./assets/css/transaction-edit-payment-method.css">
<!-- content -->
<main>
<!-- transaction edit payment method -->
<div class="transaction-edit-method">
<div class="transaction-edit-method__header">
<p>
<!-- LINK KEMBALI -->
<i class="ph-bold ph-arrow-left"></i>
<a href="./transaction-single.php?order_id=<?= $_GET['order_id'] ?>">Kembali</a>
</p>
<h1>Ubah Metode Pembayaran #FF<?= $order['order_id'] ?></h1>
</div>
<form action="./transaction-edit-payment-method.php?order_id=<?= $_GET['order_id'] ?>" method="post" class="transaction-edit-method__body">
<div class="transaction-edit-method__method">
<div class="transaction-edit-method__method-group">
<h2 class="transaction-edit-method__method-title">
Metode Pembayaran <span class="text-danger">*</span>
</h2>
<div class="transaction-edit-method__method-list">
<!-- TAMPILKAN SEMUA METHODE PEMBAYARAN -->
<?php foreach ($payment_methods as $payment_method) : ?>
<label>
<input type="radio" name="payment_method_id" value="<?= $payment_method['payment_method_id'] ?>" <?= $payment_method['payment_method_id'] == $order['payment_method_id'] ? 'checked' : '' ?> />
<span></span>
<i class="ph-fill ph-check-circle"></i>
<img src="./assets/img/banks/<?= $payment_method['payment_method_logo'] ?>" alt="<?= $payment_method['payment_method_bank'] ?>" />
</label>
<?php endforeach; ?>
</div>
<!-- JIKA TERDAPAT ERROR -->
<?php if (isset($errors['payment_method_id'])) : ?>
<div class="input-error"><?= $errors['payment_method_id'] ?></div>
<?php endif; ?>
</div>
</div>
<!-- TOMBOL SIMPAN(SUBMIT) -->
<button type="submit" name="submit" class="transaction-edit-method__button">
Simpan
</button>
</form>
</div>
<!-- end transaction edit payment method -->
</main>
<!-- end content -->
<?php
require('layouts/footer.php');
?>