Skip to content

Commit 5180bea

Browse files
committed
wip
1 parent 9a71cc5 commit 5180bea

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

openapi.json

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
"summary": "Start a transaction",
3131
"description": "Start a transaction using the given parameters",
3232
"operationId": "start",
33+
"headers": {
34+
"Signature": {
35+
"$ref": "#/components/headers/Signature"
36+
}
37+
},
3338
"requestBody": {
3439
"description": "The transaction object you would like to start.",
3540
"required": true,
@@ -46,10 +51,7 @@
4651
"description": "Success response",
4752
"headers": {
4853
"Signature": {
49-
"description": "The signature created by the SimplePay back-end.",
50-
"schema": {
51-
"type": "string"
52-
}
54+
"$ref": "#/components/headers/Signature"
5355
}
5456
},
5557
"content": {
@@ -104,9 +106,24 @@
104106
}
105107
}
106108
}
109+
},
110+
"/finish": {
111+
"post": {}
107112
}
108113
},
109114
"components": {
115+
"headers": {
116+
"Signature": {
117+
"description": "The signature created by the SimplePay back-end.",
118+
"schema": {
119+
"type": "string",
120+
"example": "3WGqCnWJArhA224xVdUY1fPh91tpd6va6JvBrPNuHK449TZTgsRn3DBu5UBGbcTn"
121+
}
122+
}
123+
},
124+
"parameters": {
125+
126+
},
110127
"schemas": {
111128
"Transaction": {
112129
"required": [

src/Client.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,40 @@
44

55
class Client
66
{
7+
/**
8+
* The client version.
9+
*/
10+
public const VERSION = '1.0.0';
11+
712
/**
813
* Create a new SimplePay Client instance.
914
*/
10-
public function __construct(protected string $merchantId, protected string $secretKey)
11-
{
15+
public function __construct(
16+
protected string $merchantId,
17+
protected string $secretKey,
18+
protected bool $sandbox = false
19+
) {
1220
// $this->config()->setApiKey('X-API-KEY', $apiKey);
1321
}
1422

23+
/**
24+
* Sign the given data.
25+
*/
26+
public function sign(string $data): string
27+
{
28+
return base64_encode(
29+
hash_hmac('sha384', $data, $this->secretKey, true)
30+
);
31+
}
32+
33+
/**
34+
* Validate the signature.
35+
*/
36+
public function validateSignature(string $hash, string $data): bool
37+
{
38+
return hash_equals($hash, $this->sign($data));
39+
}
40+
1541
/**
1642
* Get the configuration instance.
1743
*/

0 commit comments

Comments
 (0)