| @@ 170-185 (lines=16) @@ | ||
| 167 | * @throws Exception\JSON |
|
| 168 | * @return string Token |
|
| 169 | */ |
|
| 170 | protected function token_encode($payload) |
|
| 171 | { |
|
| 172 | Log::instance()->debug('encode payload:'); |
|
| 173 | Log::instance()->debug(print_r($payload, true)); |
|
| 174 | try |
|
| 175 | { |
|
| 176 | $token = JWT::encode($payload, $this->own_private_key(), 'RS512'); |
|
| 177 | } |
|
| 178 | catch (\Exception $e) |
|
| 179 | { |
|
| 180 | Log::instance()->error($e->getMessage().PHP_EOL.$e->getTraceAsString()); |
|
| 181 | throw new Exception\JSON('unable to create JWT token', $e); |
|
| 182 | } |
|
| 183 | ||
| 184 | return $token; |
|
| 185 | } |
|
| 186 | ||
| 187 | /** |
|
| 188 | * 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 |
|