public function handle($post) { if (!isset($post['event']) || !isset($post['sign'])) { throw new Paysera_WalletApi_Exception_CallbackException('At least one of required parameters is missing'); } $event = $post['event']; $sign = $post['sign']; if (!$this->callbackSignChecker->checkSign($event, $sign)) { throw new Paysera_WalletApi_Exception_CallbackException('Sign validation failed'); } $eventData = json_decode($event, true); try { if ($eventData['object'] === 'transaction') { $subject = new Paysera_WalletApi_Event_TransactionEvent($this->mapper->decodeTransaction($eventData['data'])); } elseif ($eventData['object'] === 'payment') { $subject = new Paysera_WalletApi_Event_PaymentEvent($this->mapper->decodePayment($eventData['data'])); } elseif ($eventData['object'] === 'allowance') { $subject = new Paysera_WalletApi_Event_AllowanceEvent($this->mapper->decodeAllowance($eventData['data'])); } else { throw new Paysera_WalletApi_Exception_CallbackUnsupportedException('Unknown event object'); } } catch (Paysera_WalletApi_Exception_CallbackException $exception) { throw $exception; // just pass callback exceptions } catch (Exception $exception) { throw new Paysera_WalletApi_Exception_CallbackException('Exception caught while trying to decode event subject', 0, $exception); } $eventKey = $eventData['object'] . '.' . $eventData['type']; $this->eventDispatcher->dispatch($eventKey, $subject); }
/** * * @param string $data * @param string $sign * @param string $publicKey * * @dataProvider invalidDataProvider */ public function testCheckSignWithInvalid($data, $sign, $publicKey) { $this->webClient->expects($this->once())->method('makeRequest')->with(new Paysera_WalletApi_Http_Request('http://publickey.abc'))->will($this->returnValue(new Paysera_WalletApi_Http_Response(200, array(), $publicKey))); $this->assertFalse($this->service->checkSign($data, $sign)); }