diff --git a/api/merch/redeem.php b/api/merch/redeem.php new file mode 100644 index 0000000000000000000000000000000000000000..039c07f32db2590a2f940d997646c1c7336daf9b --- /dev/null +++ b/api/merch/redeem.php @@ -0,0 +1,46 @@ +<?php +function redeem($voucher, $userId) +{ + // rest buy merchandise + $ch = curl_init(); + // curl_setopt($ch, CURLOPT_URL, "http://express:5000/voucher/use/" . $voucher); + curl_setopt($ch, CURLOPT_URL, "http://172.20.10.2:5000/voucher/use/" . $voucher); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt( + $ch, + CURLOPT_POSTFIELDS, + json_encode( + array( + "user_id" => (int)$userId + ) + ) + ); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); + $response = curl_exec($ch); + + if ($response === false) { + echo 'Error: ' . curl_error($ch); + } else { + $data = json_decode($response, true); + } + + if ($data["message"] === "success") { + $isSuccess = 1; + } else { + $isSuccess = 0; + } + + return $isSuccess; +} + + +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['redeemVoucher'])) { + $userId = $_POST['userId']; + $voucher = $_POST['voucher']; + + $isSuccess = redeem($voucher, $userId); + + header('Location: ../../merchandise'); +} +?> \ No newline at end of file diff --git a/app/controllers/Exercise.php b/app/controllers/Exercise.php index 0f930734f075a5d0f55ff6ff1a03afba30f6fcbc..a842071a397b42ea0ec6b041eded57fa8776a4d3 100644 --- a/app/controllers/Exercise.php +++ b/app/controllers/Exercise.php @@ -134,7 +134,7 @@ class Exercise extends Controller } // user's gems - $baseUrl = 'http://soap:8080/service/gems'; + $baseUrl = 'http://soap:8080/service'; $soapRequest = '<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" diff --git a/app/controllers/Merchandise.php b/app/controllers/Merchandise.php index b653e7908ce145412bcc80339d9b1ac763a72cfc..ff5f996780d40c1dac4a17f7fa3e7412d6d85c40 100644 --- a/app/controllers/Merchandise.php +++ b/app/controllers/Merchandise.php @@ -11,7 +11,7 @@ class Merchandise extends Controller $data["email"] = $_SESSION['email']; // user's gems - $baseUrl = 'http://soap:8080/service/gems'; + $baseUrl = 'http://soap:8080/service'; $soapRequest = '<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" @@ -54,7 +54,7 @@ class Merchandise extends Controller // merch // $baseUrl = 'http://express:5000/merch'; - $baseUrl = 'http://192.168.0.11:5000/merch'; + $baseUrl = 'http://172.20.10.2:5000/merch'; $ch = curl_init($baseUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); @@ -87,7 +87,7 @@ class Merchandise extends Controller } // user's gems - $baseUrl = 'http://soap:8080/service/gems'; + $baseUrl = 'http://soap:8080/service'; $soapRequest = '<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" @@ -131,7 +131,7 @@ class Merchandise extends Controller // merch // $baseUrl = 'http://express:5000/merch/' . $merchId; - $baseUrl = 'http://192.168.0.11:5000/merch/' . $merchId; + $baseUrl = 'http://172.20.10.2:5000/merch/' . $merchId; $ch = curl_init($baseUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -151,7 +151,7 @@ class Merchandise extends Controller { if (isset($merchId) && !empty($merchId)) { // $baseUrl = 'http://express:5000/merch/validate/' . $merchId; - $baseUrl = 'http://192.168.0.11:5000/merch/validate/' . $merchId; + $baseUrl = 'http://172.20.10.2:5000/merch/validate/' . $merchId; $ch = curl_init($baseUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); diff --git a/app/controllers/Transaction.php b/app/controllers/Transaction.php index a33f8fc01aaa93b44f0d9b0bcfcb7377f6d746ca..2abf854d2fbc26573941ae3d5eda86b844e7376f 100644 --- a/app/controllers/Transaction.php +++ b/app/controllers/Transaction.php @@ -10,7 +10,7 @@ class Transaction extends Controller $data["user_id"] = $_SESSION['user_id']; // user's transaction - $baseUrl = 'http://soap:8080/service/transaction'; + $baseUrl = 'http://soap:8080/service'; $soapRequest = '<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" diff --git a/app/views/merchandise/index.php b/app/views/merchandise/index.php index 91bf63d0e5f85efff6f282e8406a0c7a24bb8810..49ae797d2f1d7c3ba0c038a356b385ed59c3dd96 100644 --- a/app/views/merchandise/index.php +++ b/app/views/merchandise/index.php @@ -3,17 +3,31 @@ <h1 class="font-bold text-xl text-blue-purple-gradient"> Merchandise </h1> - <h2 class="gems"> - <img src="/public/icons/gems.svg" alt="gem" width="50px" class="gem-icon"> - <div> - <div class="font-reg"> - Your Balance: + <div class="merch-header"> + <div class="gems"> + <img src="/public/icons/gems.svg" alt="gem" width="50px" class="gem-icon"> + <div> + <div class="font-reg"> + Your Balance: + </div> + <div class="font-bold"> + <?= $data['gems'] ?> gems + </div> </div> + </div> + <div class="redeem"> <div class="font-bold"> - <?= $data['gems'] ?> gems + Reedem Voucher </div> + <form action="../../../api/merch/redeem.php" method="post"> + <div> + <input type="hidden" name="userId" value="<?= $data['user_id'] ?>"> + <input type="text" name="voucher" placeholder="Enter Voucher Code" class="redeem-input"> + <button class="redeem-button distinct-button" type="submit" name="redeemVoucher">Redeem</button> + </div> + </form> </div> - </h2> + </div> <div class="merchandise-items"> <? foreach ($data['merch'] as $merch): ?> <div class="merch-item" diff --git a/app/views/transaction/index.php b/app/views/transaction/index.php index 25ef30d5f0f4f0736dadc0e8f69825008f8b5027..6495e0d627adbabbf648a2d0ae9f71fb73731583 100644 --- a/app/views/transaction/index.php +++ b/app/views/transaction/index.php @@ -22,10 +22,16 @@ <?= $transaction['action'] ?> </h2> <? if (explode(' ', $transaction['action'])[0] == 'Buy'): ?> - <h3 class="font-bold amount-text-buy"> - - - <?= $transaction['amount'] ?> Gems - </h3> + <? if ($transaction['status'] == 'ACCEPTED'): ?> + <h3 class="font-bold amount-text-buy"> + - + <?= $transaction['amount'] ?> Gems + </h3> + <? else: ?> + <h3 class="font-bold amount-text-buy"> + Insufficient Gems + </h3> + <? endif; ?> <? else: ?> <h3 class="font-bold amount-text-get"> + diff --git a/public/css/merchandise.css b/public/css/merchandise.css index d1ce283b459fad584cc50bba8e439f55748414c4..2eb3f0be453b934d7af08ba3615f7824e1368fec 100644 --- a/public/css/merchandise.css +++ b/public/css/merchandise.css @@ -18,6 +18,12 @@ text-align: center; } +.merch-header { + display: flex; + justify-content: center; + gap: 50px; +} + .gems { color: var(--orange); font-size: 28px; @@ -32,6 +38,56 @@ text-align: center; } +.redeem { + color: var(--blue); + font-size: 28px; + width: 300px; + flex-grow: 1; + border-radius: 20px; + background: var(--white); + box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2); + justify-content: center; + cursor: pointer; + transition: all 0.3s ease 0s; + padding: 20px 0; + text-align: center; + align-items: center; + display: flex; + flex-direction: column; +} + +.redeem-input { + width: 80%; + margin-top: 15px; + border-radius: 10px; + border: 1px solid #006CDB; + padding: 10px; + font-size: 16px; + text-align: center; +} + +.redeem-button { + margin-top: 20px; + color: #FFFFFF; + padding: 5px 30px; + border-radius: 50px; + font-size: 16px; + letter-spacing: 1px; + cursor: pointer; + border: 0.5px solid #006CDB; + transition: all 0.3s ease 0s; + +} + +.redeem-button:hover { + transform: translateY(-4px); + opacity: 0.6; +} + +.redeem-button:active { + transform: translateY(6px); +} + .merchandise-items { display: flex; justify-content: center; @@ -102,4 +158,13 @@ flex-direction: column; align-items: center; } + + .merch-header { + display: block; + margin: 0 2vw; + } + + .gems { + margin-bottom: 20px; + } } \ No newline at end of file