-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutilities.php
63 lines (55 loc) · 1.6 KB
/
utilities.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
<?php
function consoleLog($s) {
echo("<script>console.log('PHP: ".$s."');</script>");
}
function postToCurl($url, $post) {
// $url is a URL string i.e 'http://www.someurl.com';
// $post is an array i.e array('client_secret' => 'secret', 'code' => 'code', 'grant_type' => 'authorization_code');
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_POSTFIELDS => http_build_query($post)
);
$ch = curl_init();
curl_setopt_array($ch, $defaults);
if( ! $result = curl_exec($ch)) {
trigger_error(curl_error($ch));
} else {
return $result;
}
curl_close($ch);
}
function get_parameter($param_name){
if(isset($_REQUEST[$param_name]) && $_REQUEST[$param_name]){
return $_REQUEST[$param_name];
}else{
return '';
}
}
function getCurrency($currSymbol) {
switch ($currSymbol) {
case "$":
return "usd";
case "€":
return "eur";
case "£":
return "gbp";
default:
return $currSymbol;
}
}
function putStripeError($e) {
$body = $e->getJsonBody();
$err = $body['error'];
print('Status is:' . $e->getHttpStatus() . "\n");
print('Type is:' . $err['type'] . "\n");
print('Code is:' . $err['code'] . "\n");
// param is '' in this case
print('Param is:' . $err['param'] . "\n");
print('Message is:' . $err['message'] . "\n");
}