-
Notifications
You must be signed in to change notification settings - Fork 0
/
currencyconverterWS.php
59 lines (50 loc) · 1.28 KB
/
currencyconverterWS.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
<?php
header('Content-type: application/json');
$amount = 0;
$actual = '';
$target = '';
$results ='';
if (isset($_POST['amount'])) {
$amount = floatval($_POST['amount']);
}
if (isset($_POST['actual'])) {
$actual = $_POST['actual'];
}
if (isset($_POST['target'])) {
$target = $_POST['target'];
}
if (isset($_POST['target'])) {
$target = $_POST['target'];
}
$conversionRates = [
"USD" => 1.23,
"EUR" => 0.9237,
"XOF" => 655.957,
"XAF" => 655.957,
"POUNDS" => 132.14,
];
if (isset($conversionRates[$actual]) ) {
$convertedAmount = $amount * $conversionRates[$target];
$result = number_format($convertedAmount, 2);
$response = [
'http_method' => 'POST',
'amount' => $amount,
'actual' => $actual,
'target' => $target,
'converted_amount' => $result,
'message' => 'Currency converted successfully',
'http_status_code' => '200'
];
} else {
$response = [
'http_method' => 'POST',
'amount' => $amount,
'actual' => $actual,
'target' => $target,
'converted_amount' => null,
'message' => 'Invalid currency selected',
'http_status_code' => '400'
];
}
echo json_encode($response);
?>