PHP code example of manza / manza-php

1. Go to this page and download the library: Download manza/manza-php 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/ */

    

manza / manza-php example snippets


use Manza\Client;

$client = new Client(apiKey: getenv('MANZA_API_KEY'));

// The base URL defaults to https://ma.manza.finance (Morocco). For South
// Africa, point at https://za.manza.finance:
$za = new Client(apiKey: getenv('MANZA_API_KEY'), baseUrl: 'https://za.manza.finance');

$entity = $client->entity->get();

$page = $client->accounts->list();
foreach ($page->data as $account) {
    echo $account['id'], ' ', $account['name'], PHP_EOL;
}

// Initiate a transfer. It goes to your enrolled transfer authorizer when it
// is inside your authorization envelope, and to your workspace's in-app
// approvers otherwise; creating it never executes it.
$draft = $client->payments->create([
    'account_id' => $accountId,
    'beneficiary_id' => $beneficiaryId,
    'amount' => '150.00',
    'payment_reference' => 'INV-000042',
    'client_reference' => 'po_1042', // unique per entity; a duplicate is a `conflict` ApiException
    'transfer_method' => 'standard',  // optional rail: eft/rtc (ZA), standard/instant (MA); omitted → the default
]);
$client->payments->get($draft->body['id']); // authorization: status, refusal_reason
// $client->transferDrafts is a deprecated alias of $client->payments (same methods, /api/payments)

// The enrolled transfer authorizer: status, suspension_reason, limits,
// daily_authorized_total, trust_new_payees, new_payee_limit. A `not_found`
// ApiException when none is enrolled.
$client->transferAuthorizer->get();

// Invoices are paid into one of your accounts: account_id is 

   $client->webhookEndpoints->create(['url' => 'https://your-name.ngrok.app/', 'events' => ['transfer.executed']]);
   

   $client->payeeTrustRequests->create([$externalAccountId]);
   

use Manza\Webhook;

try {
    $event = Webhook::constructEvent(file_get_contents('php://input'), $_SERVER, $signingSecret);
} catch (\InvalidArgumentException $e) {
    http_response_code(401);
    exit($e->getMessage());
}
// Laravel: Webhook::constructEvent($request->getContent(), $request->headers->all(), $signingSecret)

use Manza\TransferAuthorization;

// $draft: your own record of the draft, e.g. the ->body of $client->payments->create() you stored

$input = TransferAuthorization::signatureInput(
    paymentId: $draft['id'],
    nonce: $event['data']['authorization']['nonce'],
    amount: $draft['amount'],                // the API's decimal string, e.g. "2500.0"
    currencyCode: $draft['currency_code'],
    accountId: $draft['account_id'],
    payee: TransferAuthorization::payeeFor(externalAccountId: $draft['external_account_id']),
    clientReference: $draft['client_reference'],
    transferMethod: $draft['transfer_method'],   // 
bash
composer