-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathChipApi.php
65 lines (54 loc) · 1.41 KB
/
ChipApi.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
64
65
<?php
namespace Chip;
use Chip\Traits\Api\Purchase;
use Chip\Traits\Api\PaymentMethod;
use Chip\Traits\Api\Client;
use Chip\Traits\Api\Webhook;
use Chip\Traits\Api\Billing;
class ChipApi
{
use Purchase, PaymentMethod, Client, Webhook, Billing;
protected $client;
protected $mapper;
public function __construct(
protected string $brandId,
protected string $apiKey,
protected string $base = 'https://gate.chip-in.asia/api/v1/',
array $config = []
) {
$this->mapper = new \JsonMapper();
$this->mapper->bStrictNullTypes = false;
$this->mapper->bEnforceMapType = false;
$this->client = new \GuzzleHttp\Client(array_merge([
'base_uri' => $this->base,
], $config));
}
protected function request(string $method, string $endpoint, array $options = array())
{
$headers = [];
if ($this->apiKey) {
$headers['Authorization'] = 'Bearer ' . $this->apiKey;
}
$response = $this->client->request($method, $endpoint, array_merge(array(
'headers' => $headers
), $options));
$body = (string)$response->getBody()->getContents();
return json_decode($body);
}
/**
*
* @param string $content
* @param string $signature
* @param string $publicKey
* @return bool
*/
public static function verify(string $content, string $signature, string $publicKey): bool
{
return 1 === openssl_verify(
$content,
base64_decode($signature),
$publicKey,
'sha256WithRSAEncryption'
);
}
}