| 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 |
|