/** * Get all of the received requests. * * @throws \RuntimeException * @return ResponseInterface[] * */ public static function received() { if (!self::$started) { return []; } $response = self::getClient()->request('GET', 'guzzle-server/requests'); $data = json_decode($response->getBody(), true); return array_map(function ($message) { $uri = $message['uri']; if (isset($message['query_string'])) { $uri .= '?' . $message['query_string']; } $response = new Psr7\Request($message['http_method'], $uri, $message['headers'], $message['body'], $message['version']); return $response->withUri($response->getUri()->withScheme('http')->withHost($response->getHeaderLine('host'))); }, $data); }
public function testAddsPortToHeader() { $r = new Request('GET', 'http://foo.com:8124/bar'); $this->assertEquals('foo.com:8124', $r->getHeaderLine('host')); }
/** * {@inheritDoc} */ public function getHeader($header) { return $this->request->getHeaderLine($header); }
/** * Return notification * * @param Request $request Incoming request * @param string $webhookUrl Webhook url * * @return Notification * @throws NotificationException */ public function hookNotificaion(Request $request, $webhookUrl) { $signature = $request->getHeaderLine('X-Signature'); $requestBody = $request->getBody(); $errorMessages = NotificationException::getErrorMessages(); if ($signature !== $this->getSignature($webhookUrl, $requestBody)) { throw new NotificationException($errorMessages[NotificationException::BAD_SIGNATURE], NotificationException::BAD_SIGNATURE); } if ($body = json_decode($requestBody, true)) { if (time() - (int) $body['timestamp'] > 86400) { throw new NotificationException($errorMessages[NotificationException::EXPIRED_TIMESTAMP], NotificationException::EXPIRED_TIMESTAMP); } return new Notification($body['receiver_email'], $body['transaction_code'], $body['transaction_status'], $body['sender_name'], $body['sender_email'], $body['sender_phone'], $body['sender_address'], $body['amount'], $body['currency'], $body['expiry'], $body['timestamp'], $body['nonce'], $body['payload'], $body['description']); } }