forked from notchpaybackup/notchpay-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotchPay.php
More file actions
97 lines (82 loc) · 2.43 KB
/
NotchPay.php
File metadata and controls
97 lines (82 loc) · 2.43 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace NotchPay;
use NotchPay\Exceptions\InvalidArgumentException;
class NotchPay
{
/** @var string The Notch Pay API key to be used for requests. */
public static string $apiKey;
/** @var string|null The Private key to be used for requests. */
public static ?string $privateKey = null;
/** @var string|null The Sync ID to be used for requests. */
public static ?string $syncId = null;
/** @var string The instance API key, settable once per new instance */
private $instanceApiKey;
/** @var string The base URL for the Notch Pay API. */
public static $apiBase = 'https://api.notchpay.co';
/**
* @return string the API key used for requests
*/
public static function getApiKey(): string
{
return self::$apiKey;
}
/**
* Sets the API key to be used for requests.
*
* @param string $apiKey
*/
public static function setApiKey(string $apiKey): void
{
self::validateApiKey($apiKey);
self::$apiKey = $apiKey;
}
/**
* @return string|null the Private key used for requests
*/
public static function getPrivateKey(): ?string
{
return self::$privateKey;
}
/**
* Sets the Private key to be used for requests.
*
* @param string $privateKey
*/
public static function setPrivateKey(string $privateKey): void
{
self::$privateKey = $privateKey;
}
/**
* @return string|null the Sync ID used for requests
*/
public static function getSyncId(): ?string
{
return self::$syncId;
}
/**
* Sets the Sync ID to be used for requests.
*
* @param string $syncId
*/
public static function setSyncId(string $syncId): void
{
self::$syncId = $syncId;
}
/**
* Validates the API key format
*
* @param string $apiKey
* @return bool
* @throws InvalidArgumentException
*/
private static function validateApiKey($apiKey): bool
{
if ($apiKey == '' || ! is_string($apiKey)) {
throw new InvalidArgumentException('Api key must be a string and cannot be empty');
}
if(substr( $apiKey, 0, 2 ) !== "b." && substr( $apiKey, 0, 3 ) !== "sb." && substr( $apiKey, 0, 3 ) !== "pk." && substr( $apiKey, 0, 8 ) !== "pk_test.") {
throw new InvalidArgumentException('Api key must have a valid signature.');
}
return true;
}
}