| @@ 137-153 (lines=17) @@ | ||
| 134 | * @throws Exception\Runtime |
|
| 135 | * @return array |
|
| 136 | */ |
|
| 137 | protected function token_decode($token) |
|
| 138 | { |
|
| 139 | try |
|
| 140 | { |
|
| 141 | $decoded = (array) JWT::decode($token, $this->uapay_public_key(), array('RS512')); |
|
| 142 | } |
|
| 143 | catch (\Exception $e) |
|
| 144 | { |
|
| 145 | Log::instance()->error($e->getMessage().PHP_EOL.$e->getTraceAsString()); |
|
| 146 | throw new Exception\JSON('unable to decode JWT token', $e); |
|
| 147 | } |
|
| 148 | ||
| 149 | Log::instance()->debug('decoded payload:'); |
|
| 150 | Log::instance()->debug(print_r($decoded, true)); |
|
| 151 | ||
| 152 | return $decoded; |
|
| 153 | } |
|
| 154 | ||
| 155 | /** |
|
| 156 | * Get status code |
|
| @@ 217-232 (lines=16) @@ | ||
| 214 | * @throws Exception\JSON |
|
| 215 | * @return string Token |
|
| 216 | */ |
|
| 217 | protected function token_encode($payload) |
|
| 218 | { |
|
| 219 | Log::instance()->debug('encode payload:'); |
|
| 220 | Log::instance()->debug(print_r($payload, true)); |
|
| 221 | try |
|
| 222 | { |
|
| 223 | $token = JWT::encode($payload, $this->own_private_key(), 'RS512'); |
|
| 224 | } |
|
| 225 | catch (\Exception $e) |
|
| 226 | { |
|
| 227 | Log::instance()->error($e->getMessage().PHP_EOL.$e->getTraceAsString()); |
|
| 228 | throw new Exception\JSON('unable to create JWT token', $e); |
|
| 229 | } |
|
| 230 | ||
| 231 | return $token; |
|
| 232 | } |
|
| 233 | ||
| 234 | /** |
|
| 235 | * Send request to UAPAY |
|