From c1c36a8a1c9e6824d8c49124c52bd43b44bfbd40 Mon Sep 17 00:00:00 2001 From: sheilfer zepeda Date: Fri, 23 Dec 2022 13:38:31 -0800 Subject: [PATCH 1/5] fix: PHP test demo CF-544 --- Readme.md | 6 + synapse_rest/HttpClient.php | 24 +- synapse_rest/client.php | 22 +- synapse_rest/customModule.php | 40 ++ synapse_rest/test.php | 727 +++++++++++++++++----------------- 5 files changed, 448 insertions(+), 371 deletions(-) create mode 100644 synapse_rest/customModule.php diff --git a/Readme.md b/Readme.md index 5bf98fd..f605170 100644 --- a/Readme.md +++ b/Readme.md @@ -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) diff --git a/synapse_rest/HttpClient.php b/synapse_rest/HttpClient.php index 21eb7a6..991c124 100644 --- a/synapse_rest/HttpClient.php +++ b/synapse_rest/HttpClient.php @@ -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; } @@ -74,12 +77,17 @@ 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; + print_r($obj); - 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){ diff --git a/synapse_rest/client.php b/synapse_rest/client.php index 72d4d5c..e1660b4 100644 --- a/synapse_rest/client.php +++ b/synapse_rest/client.php @@ -51,7 +51,7 @@ function __construct($clientObj) { 'XSPUSER' => '|' . $this->fingerPrint, 'ContentType' => 'application/json', 'base_url' => $this->base_url, - 'XSPIDEMPOTENCYKEY' => $clientObj->$idempotency_key + 'XSPIDEMPOTENCYKEY' => $clientObj->idempotency_key ]; $httpclient = new HttpClient($this->headersObj); } @@ -158,20 +158,24 @@ function create_user($body, $idempotency_key=null, $newFingerPrint=null) { var_dump("IDEMPOTENCY is set"); } $this->headersObj->XSPIDEMPOTENCYKEY = $idempotency_key; + print_r($this->headersObj); } if(isset($newFingerPrint)){ $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); diff --git a/synapse_rest/customModule.php b/synapse_rest/customModule.php new file mode 100644 index 0000000..bd8e151 --- /dev/null +++ b/synapse_rest/customModule.php @@ -0,0 +1,40 @@ + + '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); + +?> \ No newline at end of file diff --git a/synapse_rest/test.php b/synapse_rest/test.php index c3e25a3..21784e8 100644 --- a/synapse_rest/test.php +++ b/synapse_rest/test.php @@ -1,6 +1,6 @@ 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -32,9 +32,9 @@ public function testLocalAtms(){ // //$atms = $client->locate_atms($zip , $lat , $lon , $radius , $page , $per_page ); // $atms = $client->locate_atms($zip , null , null , $radius , $page , $per_page ); // $this->assertEquals(True, is_object($atms)); - } +// } - public function testGetCryptoQuotes(){ +// public function testGetCryptoQuotes(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -47,28 +47,28 @@ public function testGetCryptoQuotes(){ // $client = new Client($clientObj); // $cyrptoquotes = $client->get_crypto_quotes(); // $this->assertEquals(True, is_object($cyrptoquotes)); - } - -public function testGetCryptoMarketData(){ - // $clientObj = (object) [ - // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', - // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', - // 'fingerprint' => '123456', - // 'ip_address' => '127.0.0.1', - // 'devmode' => True, - // 'printToConsole' => True, - // 'handle202' => True - // ]; - // $client = new Client($clientObj); - // $limit = 5; - // $currency = "BTC"; - // - // $marketdata = $client->get_crypto_market_data($limit, $currency); - // var_dump($marketdata); - // $this->assertEquals(True, is_object($marketdata)); -} +// } - public function testCreateSubnet(){ +// public function testGetCryptoMarketData(){ +// $clientObj = (object) [ +// 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', +// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', +// 'fingerprint' => '123456', +// 'ip_address' => '127.0.0.1', +// 'devmode' => True, +// 'printToConsole' => True, +// 'handle202' => True +// ]; +// $client = new Client($clientObj); +// $limit = 5; +// $currency = "BTC"; + +// $marketdata = $client->get_crypto_market_data($limit, $currency); +// var_dump($marketdata); +// $this->assertEquals(True, is_object($marketdata)); +// } + +// public function testCreateSubnet(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -85,10 +85,10 @@ public function testCreateSubnet(){ // ]; // $obj = $user->create_subnet('5c0abc754f98b000bc81c0ca', $body); // $this->assertEquals(True, is_object($obj)); -// - } -// - public function testGetSubnet(){ + +// } +// // +// public function testGetSubnet(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -102,9 +102,9 @@ public function testGetSubnet(){ // $user = $client->get_user('5c0199fe3c4e280a7d7c2a31'); // $subnet = $user->get_subnet('5c0abc754f98b000bc81c0ca', '59c9f77cd412960028b99d2b' ); // $this->assertEquals(True, is_object($subnet)); -} +// } -public function testDeleteTransaction(){ +// public function testDeleteTransaction(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -118,9 +118,9 @@ public function testDeleteTransaction(){ // $user = $client->get_user('5c0199fe3c4e280a7d7c2a31'); // $del = $user->delete_trans('5c0abc754f98b000bc81c0ca', '5c1442487bedaa008a4a347b'); // $this->assertEquals(True, is_object($del)); -} +// } -public function testDisputeTransaction(){ +// public function testDisputeTransaction(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -137,9 +137,9 @@ public function testDisputeTransaction(){ // ]; // $disp = $user->dispute_trans('5c0abc754f98b000bc81c0ca', '5c1442487bedaa008a4a347b', $disputeobj); // $this->assertEquals(True, is_object($disp)); -} +// } -public function testCommentTransaction(){ +// public function testCommentTransaction(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -156,9 +156,9 @@ public function testCommentTransaction(){ // ]; // $trans = $user->comment_trans($body); // $this->assertEquals(True, is_object($trans)); -} +// } -public function testDummyTransaction(){ +// public function testDummyTransaction(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -172,8 +172,8 @@ public function testDummyTransaction(){ // $user = $client->get_user('5c0199fe3c4e280a7d7c2a31'); // $trans = $user->dummy_tran('5c0af7541cfe2300a0fe477b'); // $this->assertEquals(True, is_object($trans)); - } - public function testCreateTransaction(){ +// } +// public function testCreateTransaction(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -203,9 +203,9 @@ public function testCreateTransaction(){ // ]; // $trans = $user->create_trans($transbody); // $this->assertEquals(True, is_object($trans)); -} +// } -public function testGetTransaction(){ +// public function testGetTransaction(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -219,9 +219,9 @@ public function testGetTransaction(){ // $user = $client->get_user('5c0199fe3c4e280a7d7c2a31'); // $trans = $user->get_trans('5c0af7541cfe2300a0fe477b', '5c13fb0c6a81c9008bc4b2bd'); // $this->assertEquals(True, is_object($trans)); -} +// } -public function testVerifyMicro(){ +// public function testVerifyMicro(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -236,9 +236,9 @@ public function testVerifyMicro(){ // $micro = (object)[0.1,0.1]; // $verifymicro = $user->verify_micro('5c0af7541cfe2300a0fe477b', $micro); // $this->assertEquals(True, is_object($verifymicro)); -} +// } -public function testShipDebit(){ +// public function testShipDebit(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -256,9 +256,9 @@ public function testShipDebit(){ // ]; // $shipdebit = $user->ship_debit('5c0af7541cfe2300a0fe477b', $ship); // $this->assertEquals(True, is_object($shipdebit)); - } +// } -public function testReinitMicro(){ +// public function testReinitMicro(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -272,9 +272,9 @@ public function testReinitMicro(){ // $user = $client->get_user('5c0199fe3c4e280a7d7c2a31'); // $shipdebit = $user->reinit_micro('5c0af7541cfe2300a0fe477b'); // $this->assertEquals(True, is_object($shipdebit)); -} +// } -public function testCreateUbo(){ +// public function testCreateUbo(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -309,13 +309,13 @@ public function testCreateUbo(){ // "compliance_contact" => $compliance, // "primary_controlling_contact" => $primary // ]; -// + // $ubo = $user->create_ubo($entitydoc); // $this->assertEquals(True, is_object($ubo)); - } +// } -public function testUpdateNode(){ +// public function testUpdateNode(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -327,35 +327,35 @@ public function testUpdateNode(){ // ]; // $client = new Client($clientObj); // $user = $client->get_user('5c0199fe3c4e280a7d7c2a31'); -// + // $updateBody = (object) [ // "supp_id"=>"new_supp_id_1234" // ]; // $testObj = $user->update_node('5c37c1245111230061707492', $updateBody); // var_dump($testObj); // $this->assertEquals("Node", get_class($testObj)); -// //$this->assertEquals(True, is_object($testObj)); -// -// -// // $updateBody = (object) [ ]; -// // $testObj = $user->update_node('5c37c1245111230061707492', $updateBody); -// // // var_dump($testObj); -// // $this->assertEquals("SynapseException", get_class($testObj)); -} +// $this->assertEquals(True, is_object($testObj)); + + +// $updateBody = (object) [ ]; +// $testObj = $user->update_node('5c37c1245111230061707492', $updateBody); +// // var_dump($testObj); +// $this->assertEquals("SynapseException", get_class($testObj)); +// } -public function testCreateNodeACHMFA(){ +// public function testCreateNodeACHMFA(){ // $clientObj = (object) [ - // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', - // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', - // 'fingerprint' => '123456', - // 'ip_address' => '127.0.0.1', - // 'devmode' => True, - // 'printToConsole' => True, - // 'handle202' => False - // ]; - // $client = new Client($clientObj); - //$user = $client->get_user('5c0199fe3c4e280a7d7c2a31'); -//create node with mfa flow +// 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', +// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', +// 'fingerprint' => '123456', +// 'ip_address' => '127.0.0.1', +// 'devmode' => True, +// 'printToConsole' => True, +// 'handle202' => False +// ]; +// $client = new Client($clientObj); +// $user = $client->get_user('5c0199fe3c4e280a7d7c2a31'); +// // create node with mfa flow // $infoachus = (object)[ // "bank_id" => "synapse_good", // "bank_pw" => "test1234", @@ -374,31 +374,31 @@ public function testCreateNodeACHMFA(){ // ]; // $testObj = $user->create_node($access); // var_dump($testObj); -//create node without mfa flow - // $infoachus = (object)[ - // "nickname" => "DEC14thAchNodes", - // "account_num" => "1232225674134", - // "routing_num" => "051000017", - // "type" => "PERSONAL", - // "class" => "CHECKING" - // ]; - // $ach = (object) [ - // "type" => "ACH-US", - // "info" => $infoachus - // ]; - // $testObj = $user->create_node($ach); - // var_dump($testObj); - // $this->assertEquals(True, is_string($testObj->node_id)); - // $this->assertEquals('5c0199fe3c4e280a7d7c2a31', ($testObj->user_id)); - // $this->assertEquals('Node', get_class($testObj->body)); +// // create node without mfa flow +// $infoachus = (object)[ +// "nickname" => "DEC14thAchNodes", +// "account_num" => "1232225674134", +// "routing_num" => "051000017", +// "type" => "PERSONAL", +// "class" => "CHECKING" +// ]; +// $ach = (object) [ +// "type" => "ACH-US", +// "info" => $infoachus +// ]; +// $testObj = $user->create_node($ach); +// var_dump($testObj); +// $this->assertEquals(True, is_string($testObj->node_id)); +// $this->assertEquals('5c0199fe3c4e280a7d7c2a31', ($testObj->user_id)); +// $this->assertEquals('Node', get_class($testObj->body)); // $achfail = (object) [ // ]; // $testObj = $user->createNode($achfail); // $this->assertEquals("SynapseException", get_class($testObj)); -// -} -public function testDeleteNode(){ +// } + +// public function testDeleteNode(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -412,9 +412,9 @@ public function testDeleteNode(){ // $user = $client->get_user('5c0199fe3c4e280a7d7c2a31'); // $testObj = $user->delete_node('5c0af7541cfe2300a0fe477b'); // $this->assertEquals(True, is_object($testObj)); - } -// - public function testCreateNodeMFA(){ +// } +// // +// public function testCreateNodeMFA(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -436,15 +436,15 @@ public function testCreateNodeMFA(){ // if($testObj->http_code == '200'){ // $this->assertEquals(True, is_object($testObj)); // } -// + // $achfail = (object) [ // ]; // $testObj = $user->createNode($achfail); // $this->assertEquals("SynapseException", get_class($testObj)); -// -} - public function testResetDebitCard(){ +// } + +// public function testResetDebitCard(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -457,7 +457,7 @@ public function testResetDebitCard(){ // $reset = (object) []; // $testObj = $user->reset_debit($reset, '5c0abc754f98b000bc81c0ca'); // $this->assertEquals(True, is_object($testObj)); -// + // $returnObj = (object) [ // //'XSPGATEWAY' =>'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW|client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', // 'XSPUSERIP' => '127.0.0.1', @@ -468,13 +468,13 @@ public function testResetDebitCard(){ // 'ContentType' => 'application/json', // 'fingerprint' => '123456' // ]; -// + // $newuser = new User($returnObj); // $testObj = $newuser->resetDebitCard($reset, '5c0abc754f98b000bc81c0ca'); // $this->assertEquals("SynapseException", get_class($testObj)); -} +// } -public function testGenerateApplePay(){ +// public function testGenerateApplePay(){ // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -492,140 +492,140 @@ public function testGenerateApplePay(){ // $result = $user->generate_apple_pay('5c0abc754f98b000bc81c0ca', $body); // $this->assertEquals(True, is_string($result->data)); // $this->assertEquals(True, is_string($result->public_key)); -// -// + + // $result = $user->generate_apple_pay('5c0abc754f98b000bc81c0ca', $body); // $this->assertEquals("SynapseException", get_class($result)); -// -// -} -public function testGetAllPlatformNodes(){ - //http status code 200 - // $clientObj = (object) [ - // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', - // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', - // 'fingerprint' => '123456', - // 'ip_address' => '127.0.0.1' - // ]; - // $client = new Client($clientObj); - // $nodes = $client->get_all_nodes(); - // - // $this->assertEquals(True, is_array($nodes->list_of_nodes)); - // $this->assertEquals(True, is_int($nodes->nodes_count)); - // $this->assertEquals(True, is_int($nodes->limit)); - // $this->assertEquals(True, is_int($nodes->page)); - // $this->assertEquals(True, is_int($nodes->page_count)); - - //trigger 400 ommit client secret - // $clientObj = (object) [ - // //'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', - // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', - // 'fingerprint' => '123456', - // 'ip_address' => '127.0.0.1' - // ]; - // $client = new Client($clientObj); - // $nodes = $client->get_all_nodes(); - // $this->assertEquals("SynapseException", get_class($nodes) ); -} -public function testGetAllSubscriptions() -{ - //http status code 200 - // $clientObj = (object) [ - // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', - // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', - // 'fingerprint' => '123456', - // 'ip_address' => '127.0.0.1' - // ]; - // $client = new Client($clientObj); - // $subs = $client->get_all_subscriptions(); - // - // $this->assertEquals(True, is_array($subs->list_of_subs)); - // $this->assertEquals(True, is_int($subs->subscriptions_count)); - // $this->assertEquals(True, is_int($subs->limit)); - // $this->assertEquals(True, is_int($subs->page)); - // $this->assertEquals(True, is_int($subs->page_count)); - - //trigger 400 ommit client secret - // $clientObj = (object) [ - // //'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', - // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', - // 'fingerprint' => '123456', - // 'ip_address' => '127.0.0.1' - // ]; - // $client = new Client($clientObj); - // $subs = $client->get_all_subscriptions(); - // $this->assertEquals("SynapseException", get_class($subs) ); -} - -public function testGetAllTransactions() -{ - //http status code 200 - // $clientObj = (object) [ - // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', - // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', - // 'fingerprint' => '123456', - // 'ip_address' => '127.0.0.1' - // ]; - // $client = new Client($clientObj); - // $trans = $client->get_all_transactions(); - // - // $this->assertEquals(True, is_array($trans->list_of_trans)); - // $this->assertEquals(True, is_int($trans->trans_count)); - // $this->assertEquals(True, is_int($trans->limit)); - // $this->assertEquals(True, is_int($trans->page)); - // $this->assertEquals(True, is_int($trans->page_count)); - - //trigger a 400 error by ommitting the client secret - // $clientObj = (object) [ - // // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', - // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', - // 'fingerprint' => '123456', - // 'ip_address' => '127.0.0.1' - // ]; - // $client = new Client($clientObj); - // $trans = $client->get_all_transactions(); - // $this->assertEquals("SynapseException", get_class($trans) ); -} +// } +// public function testGetAllPlatformNodes(){ +// // http status code 200 +// $clientObj = (object) [ +// 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', +// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', +// 'fingerprint' => '123456', +// 'ip_address' => '127.0.0.1' +// ]; +// $client = new Client($clientObj); +// $nodes = $client->get_all_nodes(); + +// $this->assertEquals(True, is_array($nodes->list_of_nodes)); +// $this->assertEquals(True, is_int($nodes->nodes_count)); +// $this->assertEquals(True, is_int($nodes->limit)); +// $this->assertEquals(True, is_int($nodes->page)); +// $this->assertEquals(True, is_int($nodes->page_count)); + +// // trigger 400 ommit client secret +// $clientObj = (object) [ +// 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', +// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', +// 'fingerprint' => '123456', +// 'ip_address' => '127.0.0.1' +// ]; +// $client = new Client($clientObj); +// $nodes = $client->get_all_nodes(); +// $this->assertEquals("SynapseException", get_class($nodes) ); +// } -public function testGetAllUsers() -{ - //http status code 200 - // $clientObj = (object) [ - // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', - // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', - // 'fingerprint' => '123456', - // 'ip_address' => '127.0.0.1' - // ]; - // $client = new Client($clientObj); - // $users = $client->get_all_users(); - // - //var_dump("users ", $users); - // //var_dump("users count ", $users->$users_count); - // $this->assertEquals(True, is_int($users->users_count)); - // $this->assertEquals(True, is_array($users->list_of_users)); - // $this->assertEquals(True, is_int($users->limit)); - // $this->assertEquals(True, is_int($users->page)); - // $this->assertEquals(True, is_int($users->page_count)); - - //trigger a 400 error by ommitting the client secret - // $clientObj = (object) [ - // //'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', - // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', - // 'fingerprint' => '123456', - // 'ip_address' => '127.0.0.1' - // ]; - // $client = new Client($clientObj); - // $users = $client->get_all_users(); - // $this->assertEquals("SynapseException", get_class($users) ); +// public function testGetAllSubscriptions() +// { +// // http status code 200 +// $clientObj = (object) [ +// 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', +// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', +// 'fingerprint' => '123456', +// 'ip_address' => '127.0.0.1' +// ]; +// $client = new Client($clientObj); +// $subs = $client->get_all_subscriptions(); + +// $this->assertEquals(True, is_array($subs->list_of_subs)); +// $this->assertEquals(True, is_int($subs->subscriptions_count)); +// $this->assertEquals(True, is_int($subs->limit)); +// $this->assertEquals(True, is_int($subs->page)); +// $this->assertEquals(True, is_int($subs->page_count)); + +// // trigger 400 ommit client secret +// $clientObj = (object) [ +// //'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', +// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', +// 'fingerprint' => '123456', +// 'ip_address' => '127.0.0.1' +// ]; +// $client = new Client($clientObj); +// $subs = $client->get_all_subscriptions(); +// $this->assertEquals("SynapseException", get_class($subs) ); +// } + +// public function testGetAllTransactions() +// { +// // http status code 200 +// $clientObj = (object) [ +// 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', +// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', +// 'fingerprint' => '123456', +// 'ip_address' => '127.0.0.1' +// ]; +// $client = new Client($clientObj); +// $trans = $client->get_all_transactions(); + +// $this->assertEquals(True, is_array($trans->list_of_trans)); +// $this->assertEquals(True, is_int($trans->trans_count)); +// $this->assertEquals(True, is_int($trans->limit)); +// $this->assertEquals(True, is_int($trans->page)); +// $this->assertEquals(True, is_int($trans->page_count)); + +// // trigger a 400 error by ommitting the client secret +// $clientObj = (object) [ +// // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', +// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', +// 'fingerprint' => '123456', +// 'ip_address' => '127.0.0.1' +// ]; +// $client = new Client($clientObj); +// $trans = $client->get_all_transactions(); +// $this->assertEquals("SynapseException", get_class($trans) ); +// } + + +// public function testGetAllUsers() +// { +// // http status code 200 +// $clientObj = (object) [ +// 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', +// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', +// 'fingerprint' => '123456', +// 'ip_address' => '127.0.0.1' +// ]; +// $client = new Client($clientObj); +// $users = $client->get_all_users(); + +// var_dump("users ", $users); +// //var_dump("users count ", $users->$users_count); +// $this->assertEquals(True, is_int($users->users_count)); +// $this->assertEquals(True, is_array($users->list_of_users)); +// $this->assertEquals(True, is_int($users->limit)); +// $this->assertEquals(True, is_int($users->page)); +// $this->assertEquals(True, is_int($users->page_count)); + +// // trigger a 400 error by ommitting the client secret +// $clientObj = (object) [ +// //'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', +// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', +// 'fingerprint' => '123456', +// 'ip_address' => '127.0.0.1' +// ]; +// $client = new Client($clientObj); +// $users = $client->get_all_users(); +// $this->assertEquals("SynapseException", get_class($users) ); -} +// } -public function testGetUser() -{ -//checking for no errors +// public function testGetUser() +// { +// // checking for no errors // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -639,7 +639,7 @@ public function testGetUser() // $this->assertEquals(True, is_string($testObj->id)); // $this->assertEquals(True, is_object($testObj->payload)); // $this->assertEquals(True, is_object($testObj->headersObj)); -//'This raises a cannot be found error'; +// // 'This raises a cannot be found error'; // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -651,7 +651,7 @@ public function testGetUser() // $testObj = $client->get_user('5bfc547cbaabfc00b46ffd0'); // $this->assertEquals("SynapseException", get_class($testObj) ); -//'Bad request to API. Missing a field or an invalid field'; +// // 'Bad request to API. Missing a field or an invalid field'; // $clientObj = (object) [ // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', // 'fingerprint' => '123456', @@ -662,37 +662,56 @@ public function testGetUser() // $testObj = $client->get_user('5bfc547cbaabfc00b46ffd00'); // $this->assertEquals("SynapseException", get_class($testObj) ); -} +// } public function testCreateUser() { -//http_code = 200 -// $clientObj = (object) [ -// 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', -// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', -// 'fingerprint' => '123456', -// 'ip_address' => '127.0.0.1', -// 'full_dehydrate' => 'True' -// ]; -// $logins_object = (object) [ -// 'email' => 'mr.t@synapsefi.com', -// 'password' => 'mr.tlovessynapsefi', -// 'scope' => 'READ_AND_WRITE' -// ]; -// $legalnames_array = array(); -// $legalnames_array[] = 'Mr.T'; -// $phoneNumbers_array = array(); -// $phoneNumbers_array[] = '777.111.1111'; -// -// $client = new Client($clientObj); -// $testObj = $client->create_user($logins_object, $phoneNumbers_array, $legalnames_array ); -// -// $this->assertEquals(True, is_string($testObj->oauth)); -// $this->assertEquals(True, is_string($testObj->id)); -// $this->assertEquals(True, is_object($testObj->payload)); -// $this->assertEquals(True, is_object($testObj->headersObj)); +// http_code = 200 +$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); + +$this->assertEquals(True, is_string($testObj->oauth)); +$this->assertEquals(True, is_string($testObj->id)); + +if(isset($testObj->payload)){ + $this->assertEquals(True, is_object($testObj->payload)); +} -//http_code = 400 'Bad request to API. Missing a field or an invalid field'; +if(isset($testObj->payload)){ + $this->assertEquals(True, is_object($testObj->headersObj)); +} + + + +// http_code = 400 'Bad request to API. Missing a field or an invalid field'; // $clientObj = (object) [ // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', // 'fingerprint' => '123456', @@ -707,15 +726,15 @@ public function testCreateUser() // $legalnames_array[] = 'Tariq Anees'; // $phoneNumbers_array = array(); // $phoneNumbers_array[] = '408.111.1111'; -// + // $testObj = $client->create_user($logins_object, $phoneNumbers_array, $legalnames_array); // $this->assertEquals("SynapseException", get_class($testObj) ); } -public function testCreateNode() -{ -//http_code = 200 +// public function testCreateNode() +// { +// // http_code = 200 // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -741,7 +760,7 @@ public function testCreateNode() // 'type' => 'DEPOSIT-US', // 'info' => $info // ]; -// + // $depositaccount = $getuserobj->create_node($deposit_account_object); // //var_dump($depositaccount); // $this->assertEquals(True, is_string($depositaccount->node_id)); @@ -749,7 +768,7 @@ public function testCreateNode() // $this->assertEquals(True, is_string($depositaccount->type)); // $this->assertEquals(True, is_object($depositaccount->body)); -//trigger 400, user obj omitted fingerprint and ip +// // trigger 400, user obj omitted fingerprint and ip // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -776,15 +795,15 @@ public function testCreateNode() // $testObj = $user->create_node($deposit_account_object); // $this->assertEquals("SynapseException", get_class($testObj) ); -//trigger 401 +// // trigger 401 // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', // 'fingerprint' => '123456', // 'ip_address' => '127.0.0.1', - // 'devmode' => True, - // 'printToConsole' => True, - // 'handle202' => True +// 'devmode' => True, +// 'printToConsole' => True, +// 'handle202' => True // ]; // $client = new Client($clientObj); // $info = (object) [ @@ -795,7 +814,7 @@ public function testCreateNode() // 'info' => $info // ]; // $getuser = $client->get_user('5bfc547cbaabfc00b46ffd00'); -// + // $returnObj = (object) [ // 'XSPGATEWAY' =>'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW|client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', // 'id' => '5bfc547cbaabfc00b46ffd00', @@ -807,12 +826,12 @@ public function testCreateNode() // $user = new User($returnObj); // $testObj = $user->create_node($deposit_account_object); // $this->assertEquals("SynapseException", get_class($testObj) ); -} +// } -public function testGetNode() -{ -//http_code= 200 +// public function testGetNode() +// { +// // http_code= 200 // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -821,7 +840,7 @@ public function testGetNode() // ]; // $client = new Client($clientObj); // $getuserobj = $client->get_user('5bfc547cbaabfc00b46ffd00'); -// + // $returnObj = (object) [ // 'XSPGATEWAY' =>'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW|client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', // 'XSPUSERIP' => '127.0.0.1', @@ -833,13 +852,13 @@ public function testGetNode() // ]; // $user = new User($returnObj); // $getNodeObj = $user->get_node('5bfc7ea3192dde00c2fd9189'); -// + // $this->assertEquals(True, is_string($getNodeObj->node_id)); // $this->assertEquals(True, is_string($getNodeObj->user_id)); // $this->assertEquals(True, is_string($getNodeObj->type)); // $this->assertEquals(True, is_object($getNodeObj->body)); -//trigger 404, incorrect userid +// // trigger 404, incorrect userid // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -848,7 +867,7 @@ public function testGetNode() // ]; // $client = new Client($clientObj); // $getuserobj = $client->get_user('5bfc547cbaabfc00b46ffd00'); -// + // $returnObj = (object) [ // 'XSPGATEWAY' =>'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW|client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', // 'XSPUSERIP' => '127.0.0.1', @@ -862,7 +881,7 @@ public function testGetNode() // $getNodeObj = $user->get_node('5bfefe49192dde00c3fdebd'); // $this->assertEquals("SynapseException", get_class($getNodeObj) ); -//trigger 400 +// // trigger 400 // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -871,7 +890,7 @@ public function testGetNode() // ]; // $client = new Client($clientObj); // $getuserobj = $client->get_user('5bfc547cbaabfc00b46ffd00'); -// + // $returnObj = (object) [ // 'XSPGATEWAY' =>'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW|client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', // 'id' => '5bfc547cbaabfc00b46ffd00', @@ -881,13 +900,13 @@ public function testGetNode() // ]; // $user = new User($returnObj); // $getNodeObj = $user->get_node('5bfefe49192dde00c3fdebd1'); -// + // $this->assertEquals("SynapseException", get_class($getNodeObj) ); -} +// } -public function testCreateSubscription() -{ -//trigger 200 +// public function testCreateSubscription() +// { +// // trigger 200 // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -895,57 +914,57 @@ public function testCreateSubscription() // 'ip_address' => '127.0.0.1' // ]; // $client = new Client($clientObj); -// + // $subarray = array(); // $subarray[] = "USERS|POST"; // $subarray[] = "USER|PATCH"; -// + // $subarray[] = "NODES|POST"; // $subarray[] = "NODE|PATCH"; -// + // $subarray[] = "TRANS|POST"; // $subarray[] = "TRAN|PATCH"; -// -// + + // $subscriptionOBJ = (object) [ // "scope" => $subarray, // "url" => "https://requestb.in/zp216zzp" // ]; -// + // $payload = $client->create_subscription($subscriptionOBJ); // $this->assertEquals(True, is_string($payload->id)); // $this->assertEquals(True, is_string($payload->url)); // $this->assertEquals(True, is_object($payload->body)); -//trigger 400 +// // trigger 400 // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'ip_address' => '127.0.0.1' // ]; // $client = new Client($clientObj); -// + // $subarray = array(); // $subarray[] = "USERS|POST"; // $subarray[] = "USER|PATCH"; -// + // $subarray[] = "NODES|POST"; // $subarray[] = "NODE|PATCH"; -// + // $subarray[] = "TRANS|POST"; // $subarray[] = "TRAN|PATCH"; -// + // $subscriptionOBJ = (object) [ // "scope" => $subarray, // "url" => "https://requestb.in/zp216zzp" // ]; -// + // $payload = $client->create_subscription($subscriptionOBJ); // $this->assertEquals("SynapseException", get_class($payload) ); -} +// } -public function testGetSubscription() -{ -//http_code 200 +// public function testGetSubscription() +// { +// // http_code 200 // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -953,13 +972,13 @@ public function testGetSubscription() // 'ip_address' => '127.0.0.1' // ]; // $client = new Client($clientObj); -// + // $newSubObj = $client->get_subscription('5bfc8c1e74d505009543b084'); // $this->assertEquals(True, is_string($newSubObj->id)); // $this->assertEquals(True, is_string($newSubObj->url)); // $this->assertEquals(True, is_object($newSubObj->body)); -//http_code 400 client secret is omitted +// // http_code 400 client secret is omitted // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'fingerprint' => '123456', @@ -968,10 +987,10 @@ public function testGetSubscription() // $client = new Client($clientObj); // $payload = $client->get_subscription('5bfc8c1e74d505009543b084'); // $this->assertEquals("SynapseException", get_class($payload) ); -} +// } -public function testIssuePublicKey(){ -// raises 200 status code +// public function testIssuePublicKey(){ +// // raises 200 status code // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -994,14 +1013,14 @@ public function testIssuePublicKey(){ // $scope = array(); // $scope[] = 'USERS|GET'; // $payload = $client->issue_public_key('YES', 'scope=USERS|GET'); -// -// + + // $this->assertEquals("SynapseException", get_class($payload) ); -} +// } -public function testUpdateInfo() -{ -//raises a 200 status code +// public function testUpdateInfo() +// { +// // raises a 200 status code // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -1009,14 +1028,14 @@ public function testUpdateInfo() // 'ip_address' => '127.0.0.1' // ]; // $client = new Client($clientObj); -// + // $getuser = $client->get_user("5bfc547cbaabfc00b46ffd00"); // $data = array("name"=>"MRMR.ROGERSROGERS", "phone_number"=>"999.111.1111", 'email' => "MR.ROGERS@test.com"); // $addNewDocs = $getuser->update_info($data); -// + // $this->assertEquals(True, is_object($addNewDocs)); -//raises a 400 status code ommitted user's client id and client secret +// // raises a 400 status code ommitted user's client id and client secret // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -1035,29 +1054,29 @@ public function testUpdateInfo() // 'ContentType' => 'application/json' // ]; // $user = new User($returnObj); -// + // $data = array("name"=>"MR.ROGERS", "phone_number"=>"999.111.1111", 'email' => "MR.ROGERS@test.com"); // $addNewDocs = $user->update_info($data); // $this->assertEquals("SynapseException", get_class($addNewDocs) ); -} - -public function testGetAllInstitution(){ -//raises a 200 http status code - // $clientObj = (object) [ - // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', - // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', - // 'fingerprint' => '123456', - // 'ip_address' => '127.0.0.1' - // ]; - // $client = new Client($clientObj); - // $getInst= $client->get_all_institutions(); - // - // $this->assertEquals(True, is_object($getInst)); -} +// } -public function testUpdateExistingDocs() -{ -//http_status code 200 +// public function testGetAllInstitution(){ +// // raises a 200 http status code +// $clientObj = (object) [ +// 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', +// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', +// 'fingerprint' => '123456', +// 'ip_address' => '127.0.0.1' +// ]; +// $client = new Client($clientObj); +// $getInst= $client->get_all_institutions(); + +// $this->assertEquals(True, is_object($getInst)); +// } + +// public function testUpdateExistingDocs() +// { +// // http_status code 200 // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -1070,14 +1089,14 @@ public function testUpdateExistingDocs() // $addNewDocs = $getuser->update_info($data); // $this->assertEquals(True, is_object($addNewDocs)); -//http_status code 400 +// // http_status code 400 // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', // 'fingerprint' => '123456', // 'ip_address' => '127.0.0.1' // ]; -// + // $client = new Client($clientObj); // $getuser = $client->get_user("5bfc547cbaabfc00b46ffd00"); // $returnObj = (object) [ @@ -1089,16 +1108,16 @@ public function testUpdateExistingDocs() // 'oauth' => $getuser->oauth, // 'ContentType' => 'application/json' // ]; -// + // $user = new User($returnObj); // $data = array("name"=>"MR.ROGERS", "phone_number"=>"999.111.1111", 'email' => "MR.ROGERS@test.com"); // $addNewDocs = $user->update_info($data); // $this->assertEquals("SynapseException", get_class($addNewDocs) ); -} +// } -public function testDeleteExistingDocs(){ -//http_status code = 200 +// public function testDeleteExistingDocs(){ +// // http_status code = 200 // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -1111,7 +1130,7 @@ public function testDeleteExistingDocs(){ // $addNewDocs = $getuser->update_info($deletedocsbody); // $this->assertEquals(True, is_object($addNewDocs)); -//http_status code 401, omitted Authentication error +// // http_status code 401, omitted Authentication error // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -1129,13 +1148,13 @@ public function testDeleteExistingDocs(){ // //'oauth' => $returnObj->oauth, // 'ContentType' => 'application/json' // ]; -// + // $user = new User($returnObj); // $deletedocsbody = array("id"=>'5bfc547cbaabfc00b46ffd00', 'permission_scope' => "DELETE_DOCUMENT"); // $delDocs = $user->update_info($deletedocsbody); // $this->assertEquals("SynapseException", get_class($delDocs) ); -//http_status code 400 +// // http_status code 400 // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -1153,30 +1172,30 @@ public function testDeleteExistingDocs(){ // 'oauth' => $returnObj->oauth, // 'ContentType' => 'application/json' // ]; -// + // $user = new User($returnObj); // $deletedocsbody = array("id"=>'5bfc547cbaabfc00b46ffd00', 'permission_scope' => "DELETE_DOCUMENT"); // $delDocs = $user->update_info($deletedocsbody); // $this->assertEquals("SynapseException", get_class($delDocs) ); -} +// } -public function testUpdateUser(){ -//http_status code 200 +// public function testUpdateUser(){ +// // http_status code 200 // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', // 'fingerprint' => '123456', // 'ip_address' => '127.0.0.1' // ]; -// + // $client = new Client($clientObj); // $getuser = $client->get_user("5bfc547cbaabfc00b46ffd00"); -// + // $data = array("name"=>"MR.ROGERS", "phone_number"=>"999.111.1111", 'email' => "MR.ROGERS@test.com"); // $addNewDocs = $getuser->update_info($data); // $this->assertEquals(True, is_object($addNewDocs)); -//http_status code 401, ommite oauth +// // http_status code 401, ommite oauth // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -1200,7 +1219,7 @@ public function testUpdateUser(){ // var_dump("add new docs failure", $addNewDocs); // $this->assertEquals("Authentication Error", $addNewDocs); -//http_status code 400, ommitted clientid and client secret +// // http_status code 400, ommitted clientid and client secret // $clientObj = (object) [ // 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', // 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', @@ -1222,7 +1241,7 @@ public function testUpdateUser(){ // $data = array("name"=>"MR.ROGERS", "phone_number"=>"999.111.1111", 'email' => "MR.ROGERS@test.com"); // $addNewDocs = $user->update_info($data); // $this->assertEquals("Bad request to API. Missing a field or an invalid field", $addNewDocs); -} +// } } From b0c46e7d4104a7c3606ab1764c3a4a5b80928702 Mon Sep 17 00:00:00 2001 From: sheilfer zepeda Date: Fri, 23 Dec 2022 13:59:59 -0800 Subject: [PATCH 2/5] refactor: idempotency_key comment CF-544 --- synapse_rest/client.php | 1 + synapse_rest/customModule.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/synapse_rest/client.php b/synapse_rest/client.php index e1660b4..6ea8d9b 100644 --- a/synapse_rest/client.php +++ b/synapse_rest/client.php @@ -51,6 +51,7 @@ function __construct($clientObj) { 'XSPUSER' => '|' . $this->fingerPrint, 'ContentType' => 'application/json', 'base_url' => $this->base_url, + //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); diff --git a/synapse_rest/customModule.php b/synapse_rest/customModule.php index bd8e151..625771e 100644 --- a/synapse_rest/customModule.php +++ b/synapse_rest/customModule.php @@ -1,3 +1,5 @@ + + Date: Fri, 23 Dec 2022 14:01:13 -0800 Subject: [PATCH 3/5] refactor: remove added print statements CF-544 --- synapse_rest/HttpClient.php | 1 - synapse_rest/client.php | 1 - 2 files changed, 2 deletions(-) diff --git a/synapse_rest/HttpClient.php b/synapse_rest/HttpClient.php index 991c124..19fd968 100644 --- a/synapse_rest/HttpClient.php +++ b/synapse_rest/HttpClient.php @@ -77,7 +77,6 @@ function post($headersObj, $url, $body, $options = null){ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response_body = curl_exec($ch); $obj = json_decode($response_body); - print_r($obj); if(isset($obj->http_code)){ $response_code = $obj->http_code; diff --git a/synapse_rest/client.php b/synapse_rest/client.php index 6ea8d9b..c1187f1 100644 --- a/synapse_rest/client.php +++ b/synapse_rest/client.php @@ -159,7 +159,6 @@ function create_user($body, $idempotency_key=null, $newFingerPrint=null) { var_dump("IDEMPOTENCY is set"); } $this->headersObj->XSPIDEMPOTENCYKEY = $idempotency_key; - print_r($this->headersObj); } if(isset($newFingerPrint)){ $this->headersObj->XSPUSER = $newFingerPrint; From be11071a4709d158539b59972d924d484cfeddd7 Mon Sep 17 00:00:00 2001 From: sheilfer zepeda Date: Fri, 23 Dec 2022 14:02:25 -0800 Subject: [PATCH 4/5] refactor: remove added print statements CF-544 --- synapse_rest/customModule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse_rest/customModule.php b/synapse_rest/customModule.php index 625771e..81e94ef 100644 --- a/synapse_rest/customModule.php +++ b/synapse_rest/customModule.php @@ -1,6 +1,6 @@ - - + + Date: Fri, 23 Dec 2022 15:42:19 -0800 Subject: [PATCH 5/5] fix: testGetUser() test case CF-544 --- synapse_rest/client.php | 6 ++- synapse_rest/test.php | 97 +++++++++++++++++++++++++---------------- 2 files changed, 63 insertions(+), 40 deletions(-) diff --git a/synapse_rest/client.php b/synapse_rest/client.php index c1187f1..6626ed5 100644 --- a/synapse_rest/client.php +++ b/synapse_rest/client.php @@ -90,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; @@ -150,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(); diff --git a/synapse_rest/test.php b/synapse_rest/test.php index 21784e8..8ee756b 100644 --- a/synapse_rest/test.php +++ b/synapse_rest/test.php @@ -623,46 +623,67 @@ // } -// public function testGetUser() -// { -// // checking for no errors -// $clientObj = (object) [ -// 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', -// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', -// 'fingerprint' => '123456', -// 'ip_address' => '127.0.0.1', -// 'full_dehydrate' => 'True' -// ]; -// $client = new Client($clientObj); -// $testObj = $client->get_user('5bfc547cbaabfc00b46ffd00'); -// $this->assertEquals(True, is_string($testObj->oauth)); -// $this->assertEquals(True, is_string($testObj->id)); -// $this->assertEquals(True, is_object($testObj->payload)); -// $this->assertEquals(True, is_object($testObj->headersObj)); -// // 'This raises a cannot be found error'; -// $clientObj = (object) [ -// 'client_id' => 'client_id_jTiLPkUSeBmqhJy8bxDzsCatdv2A0G9VfpZw1YNW', -// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', -// 'fingerprint' => '123456', -// 'ip_address' => '127.0.0.1', -// 'full_dehydrate' => 'True' -// ]; -// $client = new Client($clientObj); -// $testObj = $client->get_user('5bfc547cbaabfc00b46ffd0'); -// $this->assertEquals("SynapseException", get_class($testObj) ); +public function testGetUser() +{ +// checking for no errors +$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' +]; +$client = new Client($clientObj); +$testObj = $client->get_user('63a6248eaca72bf097c27637'); +print_r($testObj); +$this->assertEquals(True, is_string($testObj->oauth)); +$this->assertEquals(True, is_string($testObj->id)); -// // 'Bad request to API. Missing a field or an invalid field'; -// $clientObj = (object) [ -// 'client_secret' => 'client_secret_OsJtbPR3SFYjy6wqEhNWX0H2molTdDQfK8ka9Cip', -// 'fingerprint' => '123456', -// 'ip_address' => '127.0.0.1', -// 'full_dehydrate' => 'True' -// ]; -// $client = new Client($clientObj); -// $testObj = $client->get_user('5bfc547cbaabfc00b46ffd00'); -// $this->assertEquals("SynapseException", get_class($testObj) ); +if(isset($testObj->payload)){ + $this->assertEquals(True, is_object($testObj->payload)); +} -// } +if(isset($testObj->headersObj)){ + $this->assertEquals(True, is_object($testObj->headersObj)); +} + +// 'This raises a cannot be found error'; +$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' +]; +$client = new Client($clientObj); +$testObj = $client->get_user('5bfc547cbaabfc00b46ffd0'); +$this->assertEquals("SynapseException", get_class($testObj) ); + +// 'Bad request to API. Missing a field or an invalid field'; +$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' +]; +$client = new Client($clientObj); +$testObj = $client->get_user('5bfc547cbaabfc00b46ffd00'); +$this->assertEquals("SynapseException", get_class($testObj) ); + +} public function testCreateUser() {