Skip to content
Draft
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
6 changes: 6 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ Create composer.json
php composer.phar install
```

### Testing
Run in root
```
php vendor/bin/phpunit synapse_rest/test.php
```

## License

The MIT License (MIT)
Expand Down
23 changes: 15 additions & 8 deletions synapse_rest/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ function get($headersObj, $url , $options = null){
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
$response_body = curl_exec($ch);
$obj = json_decode($response_body);
$response_code = $obj->http_code;
if ($response_code == '401'){
echo('yes the oauthkey has expired');
// $newOuathkey = refresh($headersObj, $userid);
return $response_code;
if(isset($obj->http_code)){
$response_code = $obj->http_code;
if ($response_code == '401'){
echo('yes the oauthkey has expired');
// $newOuathkey = refresh($headersObj, $userid);
return $response_code;
}
}

return $obj;
}

Expand Down Expand Up @@ -74,12 +77,16 @@ function post($headersObj, $url, $body, $options = null){
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response_body = curl_exec($ch);
$obj = json_decode($response_body);
$response_code = $obj->http_code;

if ($response_code == '401'){
return $response_code;
if(isset($obj->http_code)){
$response_code = $obj->http_code;
if ($response_code == '401'){
return $response_code;
}
}

return $obj;

}

function delete($headersObj, $url, $options = null){
Expand Down
28 changes: 17 additions & 11 deletions synapse_rest/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ function __construct($clientObj) {
'XSPUSER' => '|' . $this->fingerPrint,
'ContentType' => 'application/json',
'base_url' => $this->base_url,
'XSPIDEMPOTENCYKEY' => $clientObj->$idempotency_key
//this was asking for a $clientObj.$idempotency_key in the client object, which never gets defined, causing issues in the constructor. idempotency_key is often passed as a function argument
'XSPIDEMPOTENCYKEY' => $clientObj->idempotency_key
];
$httpclient = new HttpClient($this->headersObj);
}
Expand Down Expand Up @@ -89,7 +90,9 @@ function get_user($userid, $newFingerPrint=null ,$full_dehydrate= null){
var_dump($this->headersObj);
$userObj = $http->get($this->headersObj, $url);
try{
$this->checkForErrors($userObj->http_code, $userObj->error->en, $userObj->error_code, $userObj);
if(isset($userObj->http_code)){
$this->checkForErrors($userObj->http_code, $userObj->error->en, $userObj->error_code, $userObj);
}
}
catch(SynapseException $e){
return $e;
Expand Down Expand Up @@ -149,7 +152,7 @@ function checkForErrors($http_code, $error_message, $error_code, $response){
}

//this function returns a user object
function create_user($body, $idempotency_key=null, $newFingerPrint=null) {
function create_user($body, $idempotency_key=null, $newFingerPrint=null) {

$url = $this->base_url . "users";
$http = new HttpClient();
Expand All @@ -163,15 +166,18 @@ function create_user($body, $idempotency_key=null, $newFingerPrint=null) {
$this->headersObj->XSPUSER = $newFingerPrint;
}
$newUser = $http->post($this->headersObj, $url, $body);
$errormessage = $newUser->error->en;
$errorcode = $newUser->error_code;
$httpcode= $newUser->http_code;
try{
$this->checkForErrors($httpcode, $errormessage, $errorcode, $newUser);
}
catch(SynapseException $e){
return $e;
if(isset($newUser->error)){
$errormessage = $newUser->error->en;
$errorcode = $newUser->error_code;
$httpcode= $newUser->http_code;
try{
$this->checkForErrors($httpcode, $errormessage, $errorcode, $newUser);
}
catch(SynapseException $e){
return $e;
}
}

$refreshtoken = $newUser->refresh_token;
$userid = $newUser->_id;
$ouathkey = $this->refresh($userid);
Expand Down
42 changes: 42 additions & 0 deletions synapse_rest/customModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!-- This file will be deleted and was create for CF-544 -->
<!-- Run "php synapse_rest/customModule.php" to create a user on integrationy via PHP script -->
<!-- Run "php vendor/bin/phpunit synapse_rest/test.php" to create a user on integrationy via Test class -->
<?php
include('client.php');

$clientObj = (object) [
'client_id' => 'client_id_QRtPbYMHNiLho603gF9uGcDWmj7Upva52IAyEfle',
'client_secret' => 'client_secret_QCOoA2a5FyiLUtGKJu8vzX14DjNV7Ee9b0BlnSwk',
'fingerprint' => '0347b64bb332a9d688057acb1a6b2b57',
'ip_address' => '108.235.114.35',
'devmode' => True,
'logging' => True,
'handle202' => True,
'full_dehydrate' => False,
'idempotency_key' => 'testData'
];

$logins_array = array();
$logins_array[] = (object) [
'email' => 'mr.t@synapsefi.com',
];

$legalnames_array = array();
$legalnames_array[] = 'Synapse PHP SDK User';
$phoneNumbers_array = array();
$phoneNumbers_array[] = '777.111.1111';

$body = (object)[
'logins' => $logins_array,
'legal_names' => $legalnames_array,
'phone_numbers' => $phoneNumbers_array
];


$client = new Client($clientObj);
$testObj = $client->create_user($body);


print_r($testObj);

?>
Loading