Skip to content
Snippets Groups Projects
Commit 317c2a89 authored by bewe's avatar bewe
Browse files

feat: add transaction

parent 3a3839f6
Branches
No related merge requests found
<?php
class Transaction extends Controller
{
public function index()
{
$this->validateSession();
$data["pageTitle"] = "Transaction History";
$data["user_id"] = $_SESSION['user_id'];
// user's transaction
$baseUrl = 'http://soap:8080/service/transaction';
$soapRequest = '<x:Envelope
xmlns:x="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ser="http://service.toco.org/">
<x:Header/>
<x:Body>
<ser:getTransactions>
<user_id>' . $data["user_id"] . '</user_id>
</ser:getTransactions>
</x:Body>
</x:Envelope>';
$ch = curl_init($baseUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $soapRequest);
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array(
'Content-Type: text/xml',
'SOAPAction: getTransactions',
'X-api-key: toco_php'
)
);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
$data['transaction'] = $response;
if (preg_match_all('/<return>(.*?)<\/return>/', $response, $matches)) {
$data['transaction'] = [];
foreach ($matches[1] as $match) {
$components = explode(', ', $match);
$transaction = [
'amount' => intval($components[0]),
'action' => $components[1],
'status' => $components[2]
];
$data['transaction'][] = $transaction;
}
} else {
echo 'Error extracting values from XML response.';
}
$this->view('header/index', $data);
$this->view('navbar/index');
$this->view('transaction/index', $data);
$this->view('footer/index');
}
}
\ No newline at end of file
...@@ -5,7 +5,7 @@ $selectedLanguageId = isset($_GET['language']) ? (int) $_GET['language'] : -1; ...@@ -5,7 +5,7 @@ $selectedLanguageId = isset($_GET['language']) ? (int) $_GET['language'] : -1;
<div class="exercise"> <div class="exercise">
<div class="container exercise-container"> <div class="container exercise-container">
<h1 class="font-bold text-xl text-blue-purple-gradient"> <h1 class="font-bold text-xl text-blue-purple-gradient">
Exercises Exercise
</h1> </h1>
<form id="search-filter-sort-form" action="" method="GET"> <form id="search-filter-sort-form" action="" method="GET">
......
...@@ -37,6 +37,7 @@ $profile_pic = isset($_SESSION['profile_pic']) ? $_SESSION['profile_pic'] : '/pu ...@@ -37,6 +37,7 @@ $profile_pic = isset($_SESSION['profile_pic']) ? $_SESSION['profile_pic'] : '/pu
<li><a href="<?php echo $username ? '/learn' : '/login'; ?>" class="text-sm text-black">Learn</a></li> <li><a href="<?php echo $username ? '/learn' : '/login'; ?>" class="text-sm text-black">Learn</a></li>
<li><a href="/exercise" class="text-sm text-black">Exercise</a></li> <li><a href="/exercise" class="text-sm text-black">Exercise</a></li>
<li><a href="/merchandise" class="text-sm text-black">Merchandise</a></li> <li><a href="/merchandise" class="text-sm text-black">Merchandise</a></li>
<li><a href="/transaction" class="text-sm text-black">Transactions</a></li>
</ul> </ul>
</div> </div>
...@@ -72,8 +73,9 @@ $profile_pic = isset($_SESSION['profile_pic']) ? $_SESSION['profile_pic'] : '/pu ...@@ -72,8 +73,9 @@ $profile_pic = isset($_SESSION['profile_pic']) ? $_SESSION['profile_pic'] : '/pu
<div class="dropdown-menu"> <div class="dropdown-menu">
<ul> <ul>
<li><a href="<?php echo $username ? '/learn' : '/login'; ?>" class="text-sm text-black">Learn</a></li> <li><a href="<?php echo $username ? '/learn' : '/login'; ?>" class="text-sm text-black">Learn</a></li>
<li><a href="/#" class="text-sm text-black">Articles</a></li> <li><a href="/exercise" class="text-sm text-black">Exercise</a></li>
<li><a href="/#" class="text-sm text-black">Bootcamp</a></li> <li><a href="/merchandise" class="text-sm text-black">Merchandise</a></li>
<li><a href="/transaction" class="text-sm text-black">Transactions</a></li>
<?php if ($username) : ?> <?php if ($username) : ?>
<?php if ($is_admin) : ?> <?php if ($is_admin) : ?>
<li><a href="/admin" class="text-sm text-black">CMS</a></li> <li><a href="/admin" class="text-sm text-black">CMS</a></li>
......
<?php
?>
<div class="transaction">
<div class="container transaction-container">
<h1 class="font-bold text-xl text-blue-purple-gradient">
Transaction
</h1>
<div class="card-container" id="transaction-container">
<?php foreach ($data['transaction'] as $transaction): ?>
<div class="transaction-card">
<div class="transaction-head">
<div class="content">
<h2 class="font-bold text-md">
<?= $transaction['amount'] ?>
</h2>
<span class="font-reg text-xs">
<?= $transaction['action'] ?> &#9679;
<?= $transaction['status'] ?>
</span>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment