-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi_temporary_quotes.php
55 lines (50 loc) · 1.29 KB
/
api_temporary_quotes.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
<?php
/**
* Created by PhpStorm.
* User: leminhtoan
* Date: 7/15/17
* Time: 20:54
*/
require_once 'common/config.php';
use \libs\FunctionUtil;
use \libs\Transferwise;
// Get data from GET
$source = FunctionUtil::fetchKey($_GET, 'source');
$target = FunctionUtil::fetchKey($_GET, 'target');
$amount = FunctionUtil::fetchKey($_GET, 'amount');
// Call Transferwise API to get temporary quotes
$result = Transferwise::temporaryQuotes($source, $target, $amount);
// Return response
if($result){
// Success
if(empty($result['errors'])){
$response = [
'status' => [
'code' => 0,
'message' => 'OK'
],
'data' =>[
'fee' => $result['fee'],
'targetAmount' => $result['targetAmount'],
'sourceAmount' => $result['sourceAmount'],
]
];
// Get error result from Transferwise API
}else{
$response = [
'status' => [
'code' => 1,
'message' => $result['errors'][0]['message']
]
];
}
// Cant get result from Transferwise
}else{
$response = [
'status' => [
'code' => 2,
'message' => "Can't get result from Transferwise"
]
];
}
echo json_encode($response);