Last active
July 5, 2018 12:12
-
-
Save leoauri/1acd476e957df2d405fb4e84d7a32ec8 to your computer and use it in GitHub Desktop.
Demonstrate the usage of the Basiq API PHP SDK for the test data. Creates a connection to the API and fetches accounts data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// -------------------------------------------------------------------------------------- | |
// | |
// Demonstrate the usage of the Basiq API PHP SDK for the test data | |
// https://github.com/basiqio/basiq-sdk-php | |
// Creates a connection to the API and fetches accounts data | |
// | |
// Install SDK with: | |
// composer require basiqio/basiq-sdk-php | |
// If you experience problems with the classes not defined try running this workaround: | |
// composer dump-autoload -o | |
// GitHub issue: https://github.com/basiqio/basiq-sdk-php/issues/6 | |
// | |
// -------------------------------------------------------------------------------------- | |
// Set arguments: | |
// The API key from your Basiq.io dashboard: | |
$API_key = ""; | |
// Email and mobile can be *anything* I believe, docs use these example values, which | |
// work: | |
$email = "[email protected]"; | |
$mobile = "+61410888666"; | |
// login and password of the test data to be used. | |
// Valid settings for test data available at: https://basiq.io/api/#connect-api | |
// Since this snippet *creates* a new connection with each run, you probably shouldn't | |
// use it unmodified with real users... | |
// In order to prevent this, "institutionId" => "AU00000" is hardwired into the code. | |
$loginid = ""; | |
$password = ""; | |
// | |
// -------------------------------------------------------------------------------------- | |
// using composer to load the basiq API SDK and dependencies.. | |
require_once dirname( __FILE__ ) . '/vendor/autoload.php'; | |
use Basiq\Session; | |
use Basiq\Services\UserService; | |
use Basiq\Services\ConnectionService; | |
echo basiq_fetch_test_accounts( $API_key, $email, $mobile, $loginid, $password ); | |
function basiq_fetch_test_accounts( $API_key, $email, $mobile, $loginid, $password ) { | |
if ( !($API_key && $email && $mobile && $loginid && $password) ) { | |
return "Please configure the file with valid test parameters"; | |
} | |
$bfaoutput = ""; | |
// Open a session with Basiq API | |
$session = new Session($API_key); | |
// Create a user | |
$userService = new UserService($session); | |
$user = $userService->create(["email" => $email, "mobile" => $mobile]); | |
// Create connection | |
$connService = new ConnectionService($session, $user); | |
$job = $connService->create([ | |
"institutionId" => "AU00000", | |
"loginId" => $loginid, | |
"password" => $password, | |
]); | |
// Let's see the job id | |
$showjobid = $job->id; | |
$bfaoutput .= " | |
<p>Created connection: </br> | |
Login: $loginid </br> | |
Password: $password </br> | |
</br> | |
Got Job ID: $showjobid | |
</p> | |
"; | |
// Poll our server to wait for the transactions step to be evaluated | |
$connection = $job->waitForTransactions(1000, 90); | |
// Now we should have a connection populated with account data | |
$accounts = $connection->accounts; | |
$showthem = print_r( $accounts['data'], true ); | |
$bfaoutput .= " | |
<p>Returned following accounts:</p> | |
<pre> | |
$showthem | |
</pre> | |
"; | |
return $bfaoutput; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment