PHP code example of stallion / finfactor

1. Go to this page and download the library: Download stallion/finfactor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stallion / finfactor example snippets


use Stallion\Finfactor\Client;

$client = new Client([
    'pfm_base_url'      => 'https://your-tenant.fiu.finfactor.in/pfm/api/v2',
    'pfm_user_id'       => 'your-pfm-user-id',
    'pfm_password'      => 'your-pfm-password',
    'finsense_base_url' => 'https://your-tenant.fiu.finfactor.in/finsense/API/V2',
    'finsense_user_id'  => 'your-finsense-user-id',
    'finsense_password' => 'your-finsense-password',
    'redirect_url'      => 'https://yourapp.com/portfolio/success',
]);

// Step 1: Subscribe user (call once per new user)
$client->subscription->create($mobile, $mobile);

// Step 2: Get the Account Aggregator redirect URL
$result = $client->consent->request($mobile, uniqid('session_'));

// Step 3: Redirect the user to the AA portal
header('Location: ' . $result['redirect_url']);

$details = $client->data->userDetails($mobile);
$mf      = $client->data->mutualFundInsights($mobile);
$equity  = $client->data->equityAccounts($mobile);

use Stallion\Finfactor\TokenStore\FileTokenStore;

$client = new Client($config, new FileTokenStore('/var/www/storage'));

use Stallion\Finfactor\TokenStore\DatabaseTokenStore;

$pdo    = new PDO('mysql:host=localhost;dbname=myapp', 'user', 'pass');
$client = new Client($config, new DatabaseTokenStore($pdo));

new DatabaseTokenStore($pdo, 'my_custom_tokens_table');

interface TokenStoreInterface
{
    public function get(): ?string;
    public function set(string $token, int $expiresAt): void;
    public function clear(): void;
}

// Register a user before initiating consent. Safe to call multiple times.
$client->subscription->create(string $uniqueIdentifier, string $mobileNumber): bool

// Submit a consent request. Returns redirect_url, consent_handle, customer_id.
$client->consent->request(string $mobileNumber, string $userSessionId): array

// Check consent status for a given handle.
$client->consent->status(string $consentHandle, string $custId): array

// Get full consent details by consent ID.
$client->consent->details(string $consentId): array

// Trigger a data fetch for all consented accounts.
$client->data->triggerFetch(string $uniqueIdentifier): array

// Get user details and FI data summary.
$client->data->userDetails(string $uniqueIdentifier): array

// Get mutual fund insights.
$client->data->mutualFundInsights(string $uniqueIdentifier): array

// Get mutual fund linked accounts with holdings.
$client->data->mutualFundAccounts(string $uniqueIdentifier, bool $filterZero = false): array

// Get mutual fund analysis.
$client->data->mutualFundAnalysis(string $uniqueIdentifier): array

// Get equity linked accounts (demat holdings).
$client->data->equityAccounts(string $uniqueIdentifier, bool $filterZero = false): array

// Get deposit insights.
$client->data->depositInsights(string $uniqueIdentifier): array

// Get ETF insights.
$client->data->etfInsights(string $uniqueIdentifier): array

// Fetch raw AA data for a specific account.
$client->data->rawAccountData(string $uniqueIdentifier, string $accountId, string $fromDate, string $toDate): array

use Stallion\Finfactor\Exceptions\ApiException;
use Stallion\Finfactor\Exceptions\AuthException;

try {
    $result = $client->consent->request($mobile, $sessionId);
} catch (AuthException $e) {
    // Token or credential issue
} catch (ApiException $e) {
    echo $e->getMessage();
    echo $e->getCode();
    print_r($e->getResponseData());
}