Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions phpstan-baseline.neon

This file was deleted.

3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
includes:
- phpstan-baseline.neon

parameters:
level: 5
paths:
Expand Down
3 changes: 2 additions & 1 deletion src/Riskified/Common/Env.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright 2013-2026 Riskified.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -24,4 +25,4 @@ class Env {
const PROD = 'prod';
const SANDBOX = 'sandbox';
const DEV = 'development';
}
}
8 changes: 6 additions & 2 deletions src/Riskified/Common/Exception/BaseException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php namespace Riskified\Common\Exception;
<?php

namespace Riskified\Common\Exception;

/**
* Copyright 2013-2026 Riskified.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -14,4 +17,5 @@
* permissions and limitations under the License.
*/

class BaseException extends \Exception {}
class BaseException extends \Exception {
}
Comment on lines +20 to +21

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we configure the opposite/keep as it was for these empty classes?

11 changes: 7 additions & 4 deletions src/Riskified/Common/Riskified.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Riskified\Common;
<?php

namespace Riskified\Common;

/**
* Copyright 2013-2026 Riskified.com, Inc. or its affiliates. All Rights Reserved.
Expand Down Expand Up @@ -54,19 +56,20 @@ public static function init($domain, $auth_token, $env = Env::SANDBOX, $validati
self::$env = $env;

// for backward compatibility (versions 1.0.*)
if (is_bool($validations))
if (is_bool($validations)) {
$validations = ($validations) ? Validations::SKIP : Validations::ALL;
}

self::$validations = $validations;

// suppress timezone warnings:
date_default_timezone_set(@date_default_timezone_get());
}

public static function getHostByEnv(){
public static function getHostByEnv() {
$env = (self::$env == null) ? Env::SANDBOX : self::$env;

switch ($env){
switch ($env) {
case Env::SANDBOX:
return array(
'default' => 'sandbox.riskified.com',
Expand Down
9 changes: 5 additions & 4 deletions src/Riskified/Common/Signature/HttpDataSignature.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php namespace Riskified\Common\Signature;
<?php

/**
* Copyright 2013-2026 Riskified.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -14,6 +15,8 @@
* permissions and limitations under the License.
*/

namespace Riskified\Common\Signature;

use Riskified\Common\Riskified;

/**
Expand All @@ -23,7 +26,6 @@
* @package Riskified\Common\Signature
*/
class HttpDataSignature {

const SHOP_DOMAIN_HEADER_NAME = 'X-RISKIFIED-SHOP-DOMAIN';
const SUBMIT_HEADER_NAME = 'X-RISKIFIED-SUBMIT-NOW';
const HMAC_HEADER_NAME = 'X-RISKIFIED-HMAC-SHA256';
Expand All @@ -36,5 +38,4 @@ class HttpDataSignature {
public function calc_hmac($body) {
return hash_hmac('sha256', $body, Riskified::$auth_token);
}

}
}
3 changes: 2 additions & 1 deletion src/Riskified/Common/Validations.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright 2013-2026 Riskified.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -24,4 +25,4 @@ class Validations {
const SKIP = 'skip';
const IGNORE_MISSING = 'ignore_missing';
const ALL = 'all';
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php namespace Riskified\DecisionNotification\Exception;
<?php

namespace Riskified\DecisionNotification\Exception;

/**
* Copyright 2013-2026 Riskified.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -19,13 +22,12 @@
* Thrown on HMAC mismatch
* @package Riskified\DecisionNotification\Exception
*/
class AuthorizationException extends NotificationException{

class AuthorizationException extends NotificationException {
public function __construct($headers, $body) {
parent::__construct($headers, $body);
}

protected function customMessage() {
return parent::customMessage().', Authorization Error: HMAC does not match';
return parent::customMessage() . ', Authorization Error: HMAC does not match';
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php namespace Riskified\DecisionNotification\Exception;
<?php

namespace Riskified\DecisionNotification\Exception;

/**
* Copyright 2013-2026 Riskified.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -20,7 +23,6 @@
* @package Riskified\DecisionNotification\Exception
*/
class BadHeaderException extends NotificationException {

protected $header;

public function __construct($headers, $body, $header) {
Expand All @@ -29,7 +31,7 @@ public function __construct($headers, $body, $header) {
}

protected function customMessage() {
return parent::customMessage().
', Header: '.$this->header;
return parent::customMessage() .
', Header: ' . $this->header;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php namespace Riskified\DecisionNotification\Exception;
<?php

namespace Riskified\DecisionNotification\Exception;

/**
* Copyright 2013-2026 Riskified.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -19,4 +22,5 @@
* Thrown on bad POST parameters in notification received
* @package Riskified\DecisionNotification\Exception
*/
class BadPostJsonException extends NotificationException {}
class BadPostJsonException extends NotificationException {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php namespace Riskified\DecisionNotification\Exception;
<?php

/**
* Copyright 2013-2026 Riskified.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -14,6 +15,8 @@
* permissions and limitations under the License.
*/

namespace Riskified\DecisionNotification\Exception;

use Riskified\Common\Exception\BaseException;
use Riskified\Common\Signature\HttpDataSignature;

Expand All @@ -23,7 +26,6 @@
* @package Riskified\DecisionNotification\Exception
*/
class NotificationException extends BaseException {

protected $headers;
protected $body;

Expand All @@ -37,15 +39,13 @@ protected function headersString() {
$headers = $this->headers;
$hmacKey = HttpDataSignature::HMAC_HEADER_NAME;
if (isset($headers[$hmacKey])) {
$headers[$hmacKey] = '***'.substr($headers[$hmacKey], -3);
$headers[$hmacKey] = '***' . substr($headers[$hmacKey], -3);
}
return '[ '.join(', ', $headers).' ]';
return '[ ' . join(', ', $headers) . ' ]';
}

protected function customMessage() {
return 'Headers: '.$this->headersString().
', Body: '.$this->body;
return 'Headers: ' . $this->headersString() .
', Body: ' . $this->body;
}


}
}
18 changes: 12 additions & 6 deletions src/Riskified/DecisionNotification/Model/Notification.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php namespace Riskified\DecisionNotification\Model;
<?php

/**
* Copyright 2013-2026 Riskified.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -19,6 +20,8 @@
* It is a NON-best-practice to use shop URL in the notifications programmatically as this field will not be supported long term in API notifications.
*/

namespace Riskified\DecisionNotification\Model;

use Riskified\DecisionNotification\Exception;

/**
Expand All @@ -27,7 +30,6 @@
* @package Riskified\DecisionNotification\Model
*/
class Notification {

/**
* @var string Order ID
*/
Expand Down Expand Up @@ -77,6 +79,7 @@ class Notification {
* @param $body string The raw body of the Request
* @throws NotificationException on issues with the request
*/
// @phpstan-ignore throws.notThrowable
public function __construct($signature, $headers, $body) {
$this->signature = $signature;
$this->headers = $headers;
Expand All @@ -94,8 +97,9 @@ protected function test_authorization() {
$signature = $this->signature;
$remote_hmac = $this->headers[$signature::HMAC_HEADER_NAME];
$local_hmac = $signature->calc_hmac($this->body);
if (!hash_equals($remote_hmac, $local_hmac))
if (!hash_equals($remote_hmac, $local_hmac)) {
throw new Exception\AuthorizationException($this->headers, $this->body);
}
}

/**
Expand All @@ -104,12 +108,14 @@ protected function test_authorization() {
*/
protected function parse_body() {
$body = json_decode($this->body, true);
if (!isset($body["order"]))
if (!isset($body["order"])) {
throw new Exception\BadPostJsonException($this->headers, $this->body);
}

$order = $body["order"];
if (!isset($order["id"]) || !isset($order["status"]))
if (!isset($order["id"]) || !isset($order["status"])) {
throw new Exception\BadPostJsonException($this->headers, $this->body);
}

//foreach($order as $key => $value)
// $this->$key = $value;
Expand All @@ -120,7 +126,7 @@ protected function parse_body() {
$this->riskIndicators = isset($order["risk_indicators"]) ? $order["risk_indicators"] : array();
$this->description = $order["description"];

if (isset($order["category"])) {
if (isset($order["category"])) {
$this->category = $order["category"];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php namespace Riskified\OrderWebhook\Exception;
<?php

namespace Riskified\OrderWebhook\Exception;

/**
* Copyright 2013-2026 Riskified.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -19,4 +22,5 @@
* thrown when wrong object assigned to field
* @package Riskified\OrderWebhook\Exception
*/
class ClassMismatchPropertyException extends PropertyException {}
class ClassMismatchPropertyException extends PropertyException {
}
8 changes: 6 additions & 2 deletions src/Riskified/OrderWebhook/Exception/CurlException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php namespace Riskified\OrderWebhook\Exception;
<?php

/**
* Copyright 2013-2026 Riskified.com, Inc. or its affiliates. All Rights Reserved.
*
Expand All @@ -14,11 +15,14 @@
* permissions and limitations under the License.
*/

namespace Riskified\OrderWebhook\Exception;

use Riskified\Common\Exception\BaseException;

/**
* Class CurlException
* On all cURL errors, including HTTP 500 Bad Auth
* @package Riskified\OrderWebhook\Exception
*/
class CurlException extends BaseException {}
class CurlException extends BaseException {
}
Loading