PHP code example of azaharizaman / nexus-payment-bank

1. Go to this page and download the library: Download azaharizaman/nexus-payment-bank 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/ */

    

azaharizaman / nexus-payment-bank example snippets


use Nexus\PaymentBank\Contracts\BankConnectionManagerInterface;

public function connect(BankConnectionManagerInterface $manager)
{
    // 1. Initiate connection flow
    $result = $manager->initiateConnection(
        providerName: 'plaid',
        tenantId: 'tenant-1',
        parameters: [
            'redirect_url' => 'https://app.example.com/callback',
            'scopes' => ['transactions', 'auth']
        ]
    );

    // Redirect user to the authorization URL from $result
    
    // 2. Complete connection after callback
    $connection = $manager->completeConnection(
        providerName: 'plaid',
        tenantId: 'tenant-1',
        callbackData: [
            'public_token' => 'public-token-from-callback',
            'institution_id' => 'ins_123'
        ]
    );
}

use Nexus\PaymentBank\Contracts\AccountServiceInterface;

public function showAccounts(AccountServiceInterface $service, string $connectionId)
{
    // Get all accounts for a connection
    $accounts = $service->getAccounts($connectionId);

    foreach ($accounts as $account) {
        echo $account->getName() . ': ' . $account->getBalance()->getAmount();
    }
    
    // Get transactions
    $transactions = $service->getTransactions(
        connectionId: $connectionId,
        accountId: $accounts[0]->getId(),
        startDate: new \DateTimeImmutable('-30 days'),
        endDate: new \DateTimeImmutable('now')
    );
}

use Nexus\PaymentBank\Contracts\VerificationServiceInterface;

public function verify(VerificationServiceInterface $service, string $connectionId, string $accountId)
{
    // Instant verification (e.g., Plaid Identity)
    $verificationResult = $service->verifyOwnership($connectionId, $accountId, [
        'name' => 'John Doe',
        'email' => '[email protected]'
    ]);
    
    // Micro-deposit verification
    $verificationId = $service->initiateMicroDeposits($connectionId, $accountId);
    
    // ... later ...
    $verified = $service->verifyMicroDeposits($connectionId, $verificationId, [0.12, 0.45]);
}

use Nexus\PaymentBank\Contracts\PaymentInitiationServiceInterface;
use Nexus\PaymentBank\ValueObjects\Beneficiary;
use Nexus\Common\ValueObjects\Money;

public function pay(PaymentInitiationServiceInterface $service, string $connectionId, string $sourceAccountId)
{
    $beneficiary = new Beneficiary(
        name: 'Acme Corp',
        iban: 'GB82WEST12345698765432',
        bic: 'WESTGB21XXX',
        address: '123 Business St, London'
    );

    $result = $service->initiatePayment(
        connectionId: $connectionId,
        sourceAccountId: $sourceAccountId,
        beneficiary: $beneficiary,
        amount: Money::of(100, 'USD'),
        reference: 'INV-001'
    );
    
    // Check status
    $status = $service->getPaymentStatus($connectionId, $result->paymentId);
}