11<?php
22
3+ declare (strict_types=1 );
4+
35namespace GlobalPayments \Api \Entities \GpApi ;
46
57use GlobalPayments \Api \Gateways \IAccessTokenProvider ;
68
79class GpApiSessionInfo implements IAccessTokenProvider
810{
9- private static function generateSecret ($ nonce , $ appKey )
11+ private static function generateSecret (string $ nonce , string $ appKey ): string
1012 {
1113 return hash ('SHA512 ' , $ nonce . $ appKey );
1214 }
1315
14- private static function generateNonce ()
16+ private static function generateNonce (): string
1517 {
16- $ base = new \DateTime ();
17- return $ base ->format (\DateTime::RFC3339 );
18+ return (new \DateTime ())->format (\DateTime::RFC3339 );
1819 }
1920
20- public function signIn ($ appId , $ appKey , $ secondsToExpire = null , $ intervalToExpire = null , $ permissions = []) : GpApiRequest
21+ public function signIn (
22+ $ appId ,
23+ $ appKey ,
24+ $ secondsToExpire = null ,
25+ $ intervalToExpire = null ,
26+ $ permissions = [],
27+ $ porticoCredentials = null ,
28+ $ secretApiKey = null
29+ ): GpApiRequest
2130 {
2231 $ nonce = self ::generateNonce ();
32+ $ credentials = null ;
33+
34+ // Build credentials array if Portico credentials are provided
35+ if (!empty ($ porticoCredentials )) {
36+ $ credentials = [];
37+
38+ if (!empty ($ porticoCredentials ['deviceId ' ])) {
39+ $ credentials [] = ['name ' => 'device_id ' , 'value ' => $ porticoCredentials ['deviceId ' ]];
40+ }
41+ if (!empty ($ porticoCredentials ['siteId ' ])) {
42+ $ credentials [] = ['name ' => 'site_id ' , 'value ' => $ porticoCredentials ['siteId ' ]];
43+ }
44+ if (!empty ($ porticoCredentials ['licenseId ' ])) {
45+ $ credentials [] = ['name ' => 'license_id ' , 'value ' => $ porticoCredentials ['licenseId ' ]];
46+ }
47+ if (!empty ($ porticoCredentials ['username ' ])) {
48+ $ credentials [] = ['name ' => 'username ' , 'value ' => $ porticoCredentials ['username ' ]];
49+ }
50+ if (!empty ($ porticoCredentials ['password ' ])) {
51+ $ credentials [] = ['name ' => 'password ' , 'value ' => $ porticoCredentials ['password ' ]];
52+ }
53+
54+ if (!empty ($ appKey )) {
55+ $ credentials [] = ['name ' => 'apikey ' , 'value ' => $ appKey ];
56+ }
57+ }
58+
59+ if (!empty ($ secretApiKey )) {
60+ if (empty ($ credentials )) {
61+ $ credentials = [];
62+ }
63+ $ credentials [] = ['name ' => 'apikey ' , 'value ' => $ secretApiKey ];
64+ }
65+
66+ $ finalAppId = null ;
67+ $ finalNonce = null ;
68+ $ finalSecret = null ;
69+
70+ if (!empty ($ appId ) && !empty ($ appKey )) {
71+ $ finalAppId = $ appId ;
72+ $ finalNonce = $ nonce ;
73+ $ finalSecret = self ::generateSecret ($ nonce , $ appKey );
74+ }
2375
2476 $ requestBody = new AccessTokenRequest (
25- $ appId ,
26- $ nonce ,
27- self :: generateSecret ( $ nonce , $ appKey ) ,
77+ $ finalAppId ,
78+ $ finalNonce ,
79+ $ finalSecret ,
2880 'client_credentials ' ,
2981 $ secondsToExpire ,
3082 $ intervalToExpire ,
31- $ permissions
83+ $ permissions ,
84+ $ credentials
3285 );
3386
3487 return new GpApiRequest (GpApiRequest::ACCESS_TOKEN_ENDPOINT , 'POST ' , $ requestBody );
3588 }
3689
3790 public function singOut (): GpApiRequest
3891 {
39- // TODO: Implement singOut() method.
92+ throw new \ BadMethodCallException ( ' Method not implemented ' );
4093 }
4194}
0 commit comments