Skip to content

Commit 565e2b0

Browse files
author
dormin
committed
skip all validations by adding new parameter to init
1 parent bc07f98 commit 565e2b0

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/Riskified/Common/Riskified.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @package Riskified\Common
2121
*/
2222
class Riskified {
23-
const VERSION = '1.0.8';
23+
const VERSION = '1.0.9';
2424
const API_VERSION = '2';
2525

2626
/**
@@ -39,20 +39,25 @@ class Riskified {
3939
* @var boolean indicates validation should ignore missing key errors
4040
*/
4141
public static $ignore_missing_keys;
42-
42+
/**
43+
* @var boolean skips all validations when true
44+
*/
45+
public static $skip_all_validations;
4346

4447
/**
4548
* Sets up Riskified credentials. Must be called before any other method can be used.
4649
* @param $domain string Riskified Shop Domain
4750
* @param $auth_token string Riskified Auth_Token
4851
* @param $env string Riskified environment
4952
* @param $ignore_missing_keys boolean ignores missing keys when true
53+
* @param $skip_all_validations boolean skips all validations when true
5054
*/
51-
public static function init($domain, $auth_token, $env = Env::SANDBOX, $ignore_missing_keys = false) {
55+
public static function init($domain, $auth_token, $env = Env::SANDBOX, $ignore_missing_keys = false, $skip_all_validations = false) {
5256
self::$domain = $domain;
5357
self::$auth_token = $auth_token;
5458
self::$env = $env;
5559
self::$ignore_missing_keys = $ignore_missing_keys;
60+
self::$skip_all_validations = $skip_all_validations;
5661
}
5762

5863
public static function getHostByEnv(){

src/Riskified/OrderWebhook/Transport/AbstractTransport.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct($signature, $url = null) {
6060
* @throws \Riskified\Common\Exception\BaseException on any issue
6161
*/
6262
public function submitOrder($order) {
63-
if ($order->validate())
63+
if ($this->validate_order($order))
6464
return $this->send_order($order, 'submit');
6565
return null;
6666
}
@@ -72,7 +72,7 @@ public function submitOrder($order) {
7272
* @throws \Riskified\Common\Exception\BaseException on any issue
7373
*/
7474
public function createOrder($order) {
75-
if ($order->validate())
75+
if ($this->validate_order($order))
7676
return $this->send_order($order, 'create');
7777
return null;
7878
}
@@ -84,7 +84,7 @@ public function createOrder($order) {
8484
* @throws \Riskified\Common\Exception\BaseException on any issue
8585
*/
8686
public function updateOrder($order) {
87-
if ($order->validate(false))
87+
if ($this->validate_order($order, false))
8888
return $this->send_order($order, 'update');
8989
return null;
9090
}
@@ -96,7 +96,7 @@ public function updateOrder($order) {
9696
* @throws \Riskified\Common\Exception\BaseException on any issue
9797
*/
9898
public function cancelOrder($order) {
99-
if ($order->validate(false))
99+
if ($this->validate_order($order, false))
100100
return $this->send_order($order, 'cancel');
101101
return null;
102102
}
@@ -108,7 +108,7 @@ public function cancelOrder($order) {
108108
* @throws \Riskified\Common\Exception\BaseException on any issue
109109
*/
110110
public function refundOrder($order) {
111-
if ($order->validate(false))
111+
if ($this->validate_order($order, false))
112112
return $this->send_order($order, 'refund');
113113
return null;
114114
}
@@ -119,6 +119,12 @@ public function sendHistoricalOrders($orders) {
119119
return $this->send_json_request($json, 'historical');
120120
}
121121

122+
protected function validate_order($order, $enforce_required_keys=true) {
123+
if (Riskified::$skip_all_validations)
124+
return true;
125+
return $order->validate($enforce_required_keys);
126+
}
127+
122128
protected function send_order($order, $endpoint) {
123129
$json = '{"order":'.$order->toJson().'}';
124130
return $this->send_json_request($json, $endpoint);

0 commit comments

Comments
 (0)