| @@ 195-210 (lines=16) @@ | ||
| 192 | * @throws Exception\JSON |
|
| 193 | * @return string Token |
|
| 194 | */ |
|
| 195 | protected function token_encode($payload) |
|
| 196 | { |
|
| 197 | Log::instance()->debug('encode payload:'); |
|
| 198 | Log::instance()->debug(print_r($payload, true)); |
|
| 199 | try |
|
| 200 | { |
|
| 201 | $token = JWT::encode($payload, $this->own_private_key(), 'RS512'); |
|
| 202 | } |
|
| 203 | catch (\Exception $e) |
|
| 204 | { |
|
| 205 | Log::instance()->error($e->getMessage().PHP_EOL.$e->getTraceAsString()); |
|
| 206 | throw new Exception\JSON('unable to create JWT token', $e); |
|
| 207 | } |
|
| 208 | ||
| 209 | return $token; |
|
| 210 | } |
|
| 211 | ||
| 212 | /** |
|
| 213 | * Send request to UAPAY |
|
| @@ 150-166 (lines=17) @@ | ||
| 147 | * @throws Exception\Runtime |
|
| 148 | * @return array |
|
| 149 | */ |
|
| 150 | protected function token_decode($token) |
|
| 151 | { |
|
| 152 | try |
|
| 153 | { |
|
| 154 | $decoded = (array) JWT::decode($token, $this->uapay_public_key(), array('RS512')); |
|
| 155 | } |
|
| 156 | catch (\Exception $e) |
|
| 157 | { |
|
| 158 | Log::instance()->error($e->getMessage().PHP_EOL.$e->getTraceAsString()); |
|
| 159 | throw new Exception\JSON('unable to decode JWT token', $e); |
|
| 160 | } |
|
| 161 | ||
| 162 | Log::instance()->debug('decoded payload:'); |
|
| 163 | Log::instance()->debug(print_r($decoded, true)); |
|
| 164 | ||
| 165 | return $decoded; |
|
| 166 | } |
|
| 167 | ||
| 168 | /** |
|
| 169 | * Get status code |
|