forked from AuthorizeNet/accept-sample-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateCardinalJWT.php
More file actions
executable file
·36 lines (28 loc) · 970 Bytes
/
generateCardinalJWT.php
File metadata and controls
executable file
·36 lines (28 loc) · 970 Bytes
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
<?php
require 'JWT.php';
$APIKEY = getenv("CARDINAL_API_KEY");
$APIID = getenv("CARDINAL_API_ID");
$ORGUNIT = getenv("CARDINAL_ORG_UNIT");
function generateCardinalJwt($jwtId, $apiKeyId, $apiKey, $orgUnitId, $orderNumber)
{
$currentTime = time();
$expireTime = 3600; // expiration in seconds - this equals 1hr
$orderDetails = array(
"OrderDetails" => array(
"OrderNumber" => $orderNumber
)
);
$token = array();
$token['jti'] = $jwtId;
$token['iss'] = $apiKeyId; // API Key Identifier
$token['iat'] = $currentTime; // JWT Issued At Time
$token['exp'] = $currentTime + $expireTime; // JWT Expiration Time
$token['OrgUnitId'] = $orgUnitId; // Merchant's OrgUnit
$token['Payload'] = $orderDetails;
$token['ObjectifyPayload'] = true;
return JWT::encode($token, $apiKey, 'HS256');
}
$cardinalRequestJwt = generateCardinalJwt(
'MYJWT', $APIID, $APIKEY, $ORGUNIT, 'ORDER-' . strval(mt_rand(1000, 10000))
);
?>