PluginProbe
MONEI Payments for WooCommerce / 4.1.1
MONEI Payments for WooCommerce v4.1.1
7.3.3 7.3.2 7.3.1 7.3.0 7.2.4 7.2.3 7.2.2 7.2.0 7.2.1 7.1.3 2.1.0 3.0.0 3.1.0 3.1.1 4.0.0 4.1.0 4.1.1 4.2.0 4.2.1 5.0 5.1.0 5.1.1 5.1.2 5.2.2 5.2.3 All 87 releases
monei / includes / lib / MoneiClient.php

MoneiClient.php in MONEI Payments for WooCommerce 4.1.1, at includes/lib/MoneiClient.php

84 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MONEI Payment Gateway API v1
4 * MoneiClient
5 * PHP version 5
6 *
7 * @category Class
8 * @package Monei\MoneiClient
9 * @author MONEI
10 * @link https://monei.net
11 */
12
13 namespace Monei;
14
15 use OpenAPI\Client\ApiException;
16 use OpenAPI\Client\Configuration;
17 use OpenAPI\Client\Api\PaymentsApi;
18
19 /**
20 * PaymentsApi Class Doc Comment
21 *
22 * @category Class
23 * @package OpenAPI\Client
24 * @author OpenAPI Generator team
25 * @link https://openapi-generator.tech
26 */
27 class MoneiClient
28 {
29 /**
30 * @var Configuration
31 */
32 protected $config;
33
34 /**
35 * @var PaymentsApi
36 */
37 public $payments;
38
39 /**
40 * @param string $apiKey
41 * @param Configuration $config
42 */
43 public function __construct(
44 string $apiKey,
45 Configuration $config = null
46 ) {
47 $this->config = $config ?: Configuration::getDefaultConfiguration();
48 $this->config->setApiKey('Authorization', $apiKey);
49 $this->config->setUserAgent('MONEI/PHP/0.1.3');
50
51 $this->payments = new PaymentsApi(null, $this->config);
52 }
53
54 /**
55 * @return Configuration
56 */
57 public function getConfig()
58 {
59 return $this->config;
60 }
61
62 /**
63 * @param string $body
64 * @param string $signature
65 * @return object
66 */
67 public function verifySignature($body, $signature)
68 {
69 $parts = array_reduce(explode(',', $signature), function ($result, $part) {
70 [$key, $value] = explode('=', $part);
71 $result[$key] = $value;
72 return $result;
73 }, []);
74
75 $hmac = hash_hmac('SHA256', $parts['t'] . '.' . $body, $this->config->getApiKey('Authorization'));
76
77 if ($hmac !== $parts['v1']) {
78 throw new ApiException('[401] Signature verification failed', 401);
79 }
80
81 return json_decode($body);
82 }
83 }
84