From 064c238d405a1868ce98ae58c7864e83cf81ca57 Mon Sep 17 00:00:00 2001 From: Serhat Tunca Date: Fri, 29 Dec 2023 10:13:53 +0300 Subject: [PATCH 1/2] change fraud list management --- .../add_card_fingerprint_to_fraud_value_list.php | 14 ++++++++++++++ .../add_temporary_value_to_fraud_value_list.php | 10 +++++++++- samples/add_value_to_fraud_value_list.php | 9 ++++++++- samples/config/sample_config.php | 4 ++-- samples/create_fraud_value_list.php | 4 +++- samples/remove_value_from_fraud_value_list.php | 2 +- src/Adapter/FraudAdapter.php | 16 ++++++---------- src/Model/FraudValueType.php | 12 ++++++++++++ 8 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 samples/add_card_fingerprint_to_fraud_value_list.php create mode 100644 src/Model/FraudValueType.php diff --git a/samples/add_card_fingerprint_to_fraud_value_list.php b/samples/add_card_fingerprint_to_fraud_value_list.php new file mode 100644 index 0000000..72e16cd --- /dev/null +++ b/samples/add_card_fingerprint_to_fraud_value_list.php @@ -0,0 +1,14 @@ +fraud()->addValueToValueList(array( + 'listName' => "cardList", + 'type' => FraudValueType::CARD, + 'label' => "John Doe's Card", + 'paymentId' => 11675, +)); + +print_r($response); diff --git a/samples/add_temporary_value_to_fraud_value_list.php b/samples/add_temporary_value_to_fraud_value_list.php index 8eeafb9..7f74a89 100644 --- a/samples/add_temporary_value_to_fraud_value_list.php +++ b/samples/add_temporary_value_to_fraud_value_list.php @@ -1,7 +1,15 @@ fraud()->addValueToValueList("ipList", "127.0.0.2", 60); +$response = SampleConfig::craftgate()->fraud()->addValueToValueList(array( + 'listName' => "ipList", + 'label' => "local ip 2", + 'type' => FraudValueType::IP, + 'value' => "127.0.0.2", + 'durationInSeconds' => 60 +)); print_r($response); diff --git a/samples/add_value_to_fraud_value_list.php b/samples/add_value_to_fraud_value_list.php index f68df8f..c98f980 100644 --- a/samples/add_value_to_fraud_value_list.php +++ b/samples/add_value_to_fraud_value_list.php @@ -1,7 +1,14 @@ fraud()->addValueToValueList("ipList", "127.0.0.1"); +$response = SampleConfig::craftgate()->fraud()->addValueToValueList(array( + 'listName' => "ipList", + 'type' => FraudValueType::IP, + 'label' => "local ip 1", + 'value' => "127.0.0.1", +)); print_r($response); diff --git a/samples/config/sample_config.php b/samples/config/sample_config.php index e9aa50f..e7dc4ba 100644 --- a/samples/config/sample_config.php +++ b/samples/config/sample_config.php @@ -9,9 +9,9 @@ class SampleConfig public static function craftgate() { return new Craftgate(array( - 'apiKey' => 'api-key', + 'apiKey' => 'api-key-2', 'secretKey' => 'secret-key', - 'baseUrl' => 'https://sandbox-api.craftgate.io' + 'baseUrl' => 'http://localhost:8000' )); } } diff --git a/samples/create_fraud_value_list.php b/samples/create_fraud_value_list.php index 2e60d4a..a17f428 100644 --- a/samples/create_fraud_value_list.php +++ b/samples/create_fraud_value_list.php @@ -1,7 +1,9 @@ fraud()->createValueList("ipList"); +$response = SampleConfig::craftgate()->fraud()->createValueList("ipList", FraudValueType::IP); print_r($response); diff --git a/samples/remove_value_from_fraud_value_list.php b/samples/remove_value_from_fraud_value_list.php index bfe99b4..efc24bf 100644 --- a/samples/remove_value_from_fraud_value_list.php +++ b/samples/remove_value_from_fraud_value_list.php @@ -2,6 +2,6 @@ require_once('config/sample_config.php'); -$response = SampleConfig::craftgate()->fraud()->removeValueFromValueList("ipList", "127.0.0.1"); +$response = SampleConfig::craftgate()->fraud()->removeValueFromValueList("ipList", "16d85c18-459d-4e44-820f-18ec7a4ed3a5"); print_r($response); diff --git a/src/Adapter/FraudAdapter.php b/src/Adapter/FraudAdapter.php index bfb481a..9246daa 100644 --- a/src/Adapter/FraudAdapter.php +++ b/src/Adapter/FraudAdapter.php @@ -33,11 +33,12 @@ public function retrieveValueList($listName) return $this->httpGet($path); } - public function createValueList($listName) + public function createValueList($listName, $type) { $path = "/fraud/v1/value-lists"; $request = array( - 'listName' => $listName + 'listName' => $listName, + 'type' => $type ); return $this->httpPost($path, $request); } @@ -48,20 +49,15 @@ public function deleteValueList($listName) return $this->httpDelete($path); } - public function addValueToValueList($listName, $value, $expireInSeconds = null) + public function addValueToValueList($request) { $path = "/fraud/v1/value-lists"; - $request = array( - 'listName' => $listName, - 'value' => $value, - 'durationInSeconds' => $expireInSeconds - ); return $this->httpPost($path, $request); } - public function removeValueFromValueList($listName, $value) + public function removeValueFromValueList($listName, $valueId) { - $path = "/fraud/v1/value-lists/" . $listName . "/values/" . $value; + $path = "/fraud/v1/value-lists/" . $listName . "/values/" . $valueId; return $this->httpDelete($path); } } diff --git a/src/Model/FraudValueType.php b/src/Model/FraudValueType.php new file mode 100644 index 0000000..5627ab7 --- /dev/null +++ b/src/Model/FraudValueType.php @@ -0,0 +1,12 @@ + Date: Mon, 8 Jan 2024 14:42:15 +0300 Subject: [PATCH 2/2] fix config --- samples/config/sample_config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/config/sample_config.php b/samples/config/sample_config.php index e7dc4ba..e9aa50f 100644 --- a/samples/config/sample_config.php +++ b/samples/config/sample_config.php @@ -9,9 +9,9 @@ class SampleConfig public static function craftgate() { return new Craftgate(array( - 'apiKey' => 'api-key-2', + 'apiKey' => 'api-key', 'secretKey' => 'secret-key', - 'baseUrl' => 'http://localhost:8000' + 'baseUrl' => 'https://sandbox-api.craftgate.io' )); } }