-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaylinkAPI.php
More file actions
55 lines (47 loc) · 1.84 KB
/
PaylinkAPI.php
File metadata and controls
55 lines (47 loc) · 1.84 KB
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
<?php
declare(strict_types=1);
namespace Qvickly\Api\Paylink;
use Qvickly\Api\Payment\Interfaces\DataObjectInterface;
use Qvickly\Api\Payment\RequestDataObjects\Data;
use Qvickly\Api\Payment\PaymentAPI;
use stdClass;
class PaylinkAPI
{
protected PaymentAPI $paymentAPI;
public function __construct(
private readonly string $eid,
private readonly string $secret,
private readonly bool $testMode = false,
private array $overrides = []
)
{
$this->paymentAPI = new PaymentAPI(eid: $this->eid, secret: $this->secret, testMode: $this->testMode, overrides: $this->overrides);
}
public function __call(string $name, array $arguments)
{
return match($name) {
'create' => call_user_func_array(array($this, 'create'), $arguments),
default => throw new \Exception('Method not found')
};
}
public static function __callStatic(string $name, array $arguments)
{
$eid = defined('QVICKLY_PAYLINK_API_EID') ? constant('QVICKLY_PAYLINK_API_EID') : $_ENV['EID'];
$secret = defined('QVICKLY_PAYLINK_API_SECRET') ? constant('QVICKLY_PAYLINK_API_SECRET') : $_ENV['SECRET'];
if(!isset($eid) || !isset($secret)) {
throw new \Exception('EID and SECRET must be set either as constants or in the environment variables');
}
return match($name) {
'create' => call_user_func_array(array(new self($eid, $secret), 'create'), $arguments),
default => throw new \Exception('Method not found')
};
}
protected function create(array|Data $data, bool|null|int $roundCart = null): array|string|DataObjectInterface|stdClass
{
if(is_array($data)) {
$data = new Data($data);
}
$data->updateCart($roundCart);
return $this->paymentAPI->addPayment($data);
}
}