/** * Retrieves a user's fraud score from the Sift Science API. * * @param $userId A user's id. This id should be the same as the user_id used in event calls. * This parameter is required. * @param $timeout (optional) The number of seconds to wait before failing the request. By default this is * configured to 2 seconds (see above). * @return null|SiftResponse */ public function score($userId, $timeout = self::DEFAULT_TIMEOUT) { $this->validateArgument($userId, 'user id', 'string'); $properties = array('api_key' => $this->api_key); try { $request = new SiftRequest(self::userScoreApiUrl($userId), SiftRequest::GET, $properties, $timeout); return $request->send(); } catch (Exception $e) { return null; } }
public static function clearMockResponse() { self::$mock = null; }
public function testSuccessfulUnlabelWithAllUserIdCharacters() { $this->client = new SiftClient(array('api_key' => SiftClient203Test::$API_KEY, 'version' => '203')); $mockUrl = 'https://api.siftscience.com/v203/users/54321' . urlencode('=.-_+@:&^%!$') . '/labels?api_key=agreatsuccess'; $mockResponse = new SiftResponse('', 204, null); SiftRequest::setMockResponse($mockUrl, SiftRequest::DELETE, $mockResponse); $response = $this->client->unlabel("54321=.-_+@:&^%!\$"); $this->assertTrue($response->isOk()); }
public function testSuccessfulUpdateNotificationConfig() { $mockUrl = 'https://partner.siftscience.com/v3/accounts/' . SiftClientTest::$PARTNER_ID . '/config'; $mockResponse = new SiftResponse($this->validConfigNotificationUrlResponseJson(), 200, null); SiftRequest::setMockResponse($mockUrl, SiftRequest::PUT, $mockResponse); $response = $this->client->updateNotificationConfig($this->validConfigNotificationUrl, $this->validConfigNotificationThreshold); $this->assertTrue($response->isOk()); $this->assertEquals($response->body['http_notification_url'], $this->validConfigNotificationUrl); $this->assertEquals($response->body['http_notification_threshold'], $this->validConfigNotificationThreshold); }
/** Updates the configuration which controls http notifications for all merchant * accounts under this partner. * * == Parameters * httpNotificationUrl * A url to send POST notifications to. The value of the notification_url will be a url containing the string '%s' exactly once. * * httpNotificationThreshold * The notification threshold should be a double between 0.0 and 1.0 */ public function updateNotificationConfig($httpNotificationUrl = null, $httpNotificationThreshold = null) { $this->validateArgument($httpNotificationUrl, 'notification url', 'string'); $this->validateArgument($httpNotificationThreshold, 'notification threshold', 'double'); $body = array(); $body['http_notification_url'] = $httpNotificationUrl; $body['http_notification_threshold'] = $httpNotificationThreshold; try { $request = new SiftRequest(self::notificationConfigUrl(), SiftRequest::PUT, $body, $this->apiKey, $this->timeout); return $request->send(); } catch (Exception $e) { return null; } }
public function testGetOrderDecisions() { $mockUrl = 'https://api3.siftscience.com/v3/accounts/90201c25e39320c45b3da37b/orders/example_order/decisions'; $mockResponse = new SiftResponse('{"decisions":{"payment_abuse":{"decision":{"id":"order_decisionz"},"time":1468599638005,"webhook_succeeded":false},"account_abuse":{"decision":{"id":"good_order"},"time":1468517407135,"webhook_succeeded":true}}}', 200, null); SiftRequest::setMockResponse($mockUrl, SiftRequest::GET, $mockResponse); $response = $this->client->getOrderDecisions('example_order', array('timeout' => 4)); $this->assertTrue($response->isOk()); }
public function testSuccessfulLabelUser() { $mockUrl = 'https://api.siftscience.com/v203/users/54321/labels'; $mockResponse = new SiftResponse('{"status": 0, "error_message": "OK"}', 200, null); SiftRequest::setMockResponse($mockUrl, SiftRequest::POST, $mockResponse); $response = $this->client->label("54321", $this->label_properties); $this->assertTrue($response->isOk()); $this->assertEquals($response->apiErrorMessage, 'OK'); }
/** * Gets the latest decision for a user for each abuse type. * * @param string $user_id The ID of a user. * * @param array $opts Array of optional parameters for this request: * - string 'account_id': by default, this client's account ID is used. * - int 'timeout': By default, this client's timeout is used. */ public function getOrderDecisions($order_id, $opts = array()) { $this->mergeArguments($opts, array('account_id' => $this->account_id, 'timeout' => $this->timeout)); $this->validateArgument($order_id, 'order id', 'string'); $url = self::API3_ENDPOINT . '/v3/accounts/' . $opts['account_id'] . '/orders/' . $order_id . '/decisions'; try { $request = new SiftRequest($url, SiftRequest::GET, $opts['timeout'], self::API3_VERSION, array('auth' => $this->api_key . ':')); return $request->send(); } catch (Exception $e) { return null; } }
/** * Retrieve Device * * @param $userId A device's id. * This parameter is required. * @param $accountId A device's id. * This parameter is required. * @param $timeout (optional) The number of seconds to wait before failing the request. By default this is * configured to 2 seconds (see above). * @return null|SiftResponse */ public function getUserDevices($userId, $accountId, $timeout = self::DEFAULT_TIMEOUT) { $this->validateArgument($userId, 'user id', 'string'); $this->validateArgument($accountId, 'account id', 'string'); $properties = array('api_key' => $this->api_key); try { $request = new SiftRequest(self::userDevicesApiUrl($userId, $accountId), SiftRequest::GET, $properties, $timeout); return $request->send(); } catch (Exception $e) { return $e->getMessage(); } }