PluginProbe
HyperPay Payments / trunk
HyperPay Payments vtrunk
6.6.0 trunk 1.7 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.1.0 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.5 4.0.0 4.0.2 All 34 releases
hyperpay-gateways / src / Helpers / Http.php

Http.php in HyperPay Payments trunk, at src/Helpers/Http.php

55 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hyperpay\Gateways\Helpers;
4
5 if (! defined('ABSPATH')) exit;
6
7 use WP_Error;
8 use Hyperpay\Gateways\Helpers\Log;
9
10 final class Http
11 {
12
13 public static function post($url, $data = [])
14 {
15 $response = wp_remote_post($url, \array_merge($data, ['timeout' => 10000])); // 10 seconds timeout
16 return self::handelResponse($response);
17 }
18
19 public static function get($url, $options = [])
20 {
21 $response = wp_remote_get($url, \array_merge($options, ['timeout' => 10000])); // 10 seconds timeout
22 return self::handelResponse($response);
23 }
24
25 public static function delete($url, $data = [])
26 {
27 $options = \array_merge($data, [
28 'method' => 'DELETE',
29 'timeout' => 10000
30 ]);
31
32 $response = wp_remote_request($url, $options);
33 return self::handelResponse($response);
34 }
35
36 public static function handelResponse($response)
37 {
38 $result = json_decode(wp_remote_retrieve_body($response), true);
39
40 if (is_wp_error($response)) {
41 $error = $response->get_error_message();
42 Log::write(["error" => $error, "response" => $result]);
43
44 return [
45 "result" => [
46 "code" => wp_remote_retrieve_response_code($response),
47 "description" => $error
48 ]
49 ];
50 }
51
52 return $result;
53 }
54 }
55