コード例 #1
0
ファイル: notification.php プロジェクト: vAugagneur/plugins
 public function postProcess()
 {
     $res = \CashWay\API::receiveNotification(Tools::file_get_contents('php://input'), getallheaders(), Configuration::get('CASHWAY_SHARED_SECRET'));
     if ($res[0] === false) {
         $this->terminateReply($res[2], $res[1]);
     }
     $event = $res[1];
     $this->data = $res[2];
     $handler = $this->snakeToCamel('on_' . $event);
     method_exists($this, $handler) ? $this->{$handler}() : $this->terminateReply(400, 'Do not know how to handle this event.');
 }
コード例 #2
0
 /**
  * Validate input payload:
  * - if it comes with a signature, validate signature,
  * - parse it (JSON)
  *
  * @param $file payload source
  *
  * @return Array
  */
 private function getValidPayload($file)
 {
     $this->headers = getallheaders();
     $data = file_get_contents($file);
     if (!array_key_exists('X-CashWay-Signature', $this->headers)) {
         $this->terminateReply(400, 'A signature header is required.');
     }
     $signature = trim($this->headers['X-CashWay-Signature']);
     if ($signature == 'none' || $signature == '') {
         $this->terminateReply(400, 'A real signature is required.');
     }
     if (!\CashWay\API::isDataValid($data, Configuration::get('CASHWAY_SHARED_SECRET'), $signature)) {
         $this->terminateReply(400, 'Payload signature does not match.');
     }
     $this->data = json_decode($data);
     if (null === $this->data) {
         $this->terminateReply(400, 'Could not parse JSON payload.');
     }
     return $this->data;
 }
コード例 #3
0
ファイル: APITest.php プロジェクト: vAugagneur/plugins
 /**
  * @dataProvider notificationsProvider
  */
 public function testReceiveNotification($body, $headers, $secret, $expected)
 {
     $this->assertEquals($expected, \CashWay\API::receiveNotification($body, $headers, $secret));
 }