add token to header
This commit is contained in:
		
							parent
							
								
									3870421751
								
							
						
					
					
						commit
						3b623393ac
					
				|  | @ -32,27 +32,6 @@ class Repository implements RepositoryInterface | |||
|         die(json_encode(['message' => 'unauthorized'])); | ||||
|     } | ||||
| 
 | ||||
|     static function getForm() | ||||
|     { | ||||
|         $data = [ | ||||
|             'url' => '', | ||||
|         ]; | ||||
| 
 | ||||
|         $config = \IpSupply\SyncOrder\Config\Getter::get('config'); | ||||
|         if ($config) { | ||||
|             $data = json_decode($config, true); | ||||
|         } | ||||
| 
 | ||||
|         return [ | ||||
|             [ | ||||
|                 'label' => 'API', | ||||
|                 'name' => 'url', | ||||
|                 'value' => $data['url'] ?? '' | ||||
|             ] | ||||
|         ]; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public function getData() | ||||
|     { | ||||
|         return \IpSupply\SyncOrder\Helper::responseOk([ | ||||
|  |  | |||
|  | @ -28,6 +28,6 @@ class Config extends Template | |||
|     } | ||||
| 
 | ||||
|     public function getForm() { | ||||
|         return \IpSupply\SyncOrder\Api\Repository::getForm(); | ||||
|         return \IpSupply\SyncOrder\Helper::getForm(); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -2,10 +2,37 @@ | |||
| 
 | ||||
| namespace IpSupply\SyncOrder; | ||||
| 
 | ||||
| final class Helper { | ||||
| final class Helper | ||||
| { | ||||
|     public const API_KEY = 'IpSupply@123'; | ||||
|     public const PREFIX = 'IpSupply_SyncOrder'; | ||||
| 
 | ||||
|     static function getForm() | ||||
|     { | ||||
|         $data = [ | ||||
|             'url' => '', | ||||
|             'token' => '' | ||||
|         ]; | ||||
| 
 | ||||
|         $config = \IpSupply\SyncOrder\Config\Getter::get('config'); | ||||
|         if ($config) { | ||||
|             $data = json_decode($config, true); | ||||
|         } | ||||
| 
 | ||||
|         return [ | ||||
|             [ | ||||
|                 'label' => 'API', | ||||
|                 'name' => 'url', | ||||
|                 'value' => $data['url'] ?? '' | ||||
|             ], | ||||
|             [ | ||||
|                 'label' => 'Token', | ||||
|                 'name' => 'token', | ||||
|                 'value' => $data['token'] ?? '' | ||||
|             ] | ||||
|         ]; | ||||
|     } | ||||
| 
 | ||||
|     static function responseOk(array $data) | ||||
|     { | ||||
|         header('HTTP/1.1 200 Ok'); | ||||
|  |  | |||
|  | @ -27,7 +27,8 @@ class UpgradeData implements UpgradeDataInterface | |||
|     public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) | ||||
|     { | ||||
|         \IpSupply\SyncOrder\Config\Setter::set(path: 'config', value: json_encode([ | ||||
|             'url' => 'https://google.com' // TODO: config api
 | ||||
|             'url' => 'https://api.nswteam.net/api/transferPostData', | ||||
|             'token' => 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2FwaS5uc3d0ZWFtLm5ldC9hcGkvbG9naW4iLCJpYXQiOjE2ODkzOTEyMDMsImV4cCI6MTcyMDkyNzIwMywibmJmIjoxNjg5MzkxMjAzLCJqdGkiOiJreFA1MW9jck5rdEYzSzY3Iiwic3ViIjozNjkwLCJwcnYiOiJjOGVlMWZjODllNzc1ZWM0YzczODY2N2U1YmUxN2E1OTBiNmQ0MGZjIn0.p-aE0oWkKmdrcKWD94oSmMd_CMbY_4MoqADIwYIhIKw' //
 | ||||
|         ])); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ final class Index | |||
|     protected function _headers($headers = array()) | ||||
|     { | ||||
|         return array_merge([ | ||||
|             'Authorization' => 'Bearer ' . null | ||||
|             'Authorization' => 'Bearer ' . $this->_config['token'] | ||||
|         ], $headers); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue