PHP code example of iberbanco / php-sdk
1. Go to this page and download the library: Download iberbanco/php-sdk 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/ */
iberbanco / php-sdk example snippets
berbanco\SDK\IberbancoClient;
// Recommended: Use sandbox boolean for environment switching
$client = IberbancoClient::create([
'sandbox' => true, // Set to false for production
'username' => $_ENV['IBERBANCO_USERNAME'] ?? 'your_agent_username',
'timeout' => 30,
'verify_ssl' => true
]);
// Sandbox environment (for testing)
$client = IberbancoClient::create([
'sandbox' => true,
'username' => 'your_agent_username'
]);
// Production environment
$client = IberbancoClient::create([
'sandbox' => false,
'username' => 'your_agent_username'
]);
$client = IberbancoClient::createFromEnvironment();
// Authenticate using environment variables
$authResponse = $client->authenticate(
$_ENV['IBERBANCO_USERNAME'] ?? '',
$_ENV['IBERBANCO_PASSWORD'] ?? ''
);
// Method 1: Direct authentication
$authResponse = $client->authenticate('your_username', 'your_password');
$token = $authResponse['data']['token']; // Token is automatically set
// Method 2: Using environment variables
$authResponse = $client->authenticate(
$_ENV['IBERBANCO_USERNAME'],
$_ENV['IBERBANCO_PASSWORD']
);
// Method 3: Manual token setting (if you already have a token)
$client->setAuthToken('your_existing_token');
// Supported Currency IDs
1 => 'USD' // US Dollar
2 => 'EUR' // Euro
3 => 'GBP' // British Pound
4 => 'CHF' // Swiss Franc
5 => 'RUB' // Russian Ruble
6 => 'TRY' // Turkish Lira
7 => 'AED' // UAE Dirham
8 => 'CNH' // Chinese Yuan
9 => 'AUD' // Australian Dollar
10 => 'CZK' // Czech Koruna
11 => 'PLN' // Polish Zloty
12 => 'CAD' // Canadian Dollar
13 => 'USDT' // Tether (USDT)
14 => 'HKD' // Hong Kong Dollar
15 => 'SGD' // Singapore Dollar
16 => 'JPY' // Japanese Yen
// Always use internal IDs in requests
$accountData = [
'user_number' => 'USER123456',
'currency' => 1, // USD
'reference' => 'Primary USD account'
];
use Iberbanco\SDK\DTOs\Account\CreateAccountDTO;
use Iberbanco\SDK\DTOs\Account\SearchAccountsDTO;
// Create account with DTO
$accountDTO = CreateAccountDTO::fromArray([
'user_number' => 'USER123456',
'currency' => 1, // USD (internal ID)
'reference' => 'Primary account'
]);
$account = $client->accounts()->create($accountDTO);
use Iberbanco\SDK\DTOs\Card\CreateCardDTO;
// Create card with DTO
$cardDTO = CreateCardDTO::fromArray([
'user_number' => 'USER123456',
'account_number' => 'ACC123456789',
'amount' => 1000.00,
'currency' => 1, // USD (internal ID)
'shipping_address' => '123 Main Street',
'shipping_city' => 'New York',
'shipping_state' => 'NY',
'shipping_country_code' => 'US',
'shipping_post_code' => '10001',
'delivery_method' => 'Standard'
]);
$card = $client->cards()->create($cardDTO);
use Iberbanco\SDK\DTOs\Transaction\CreateSwiftTransactionDTO;
use Iberbanco\SDK\DTOs\Transaction\CreateSepaTransactionDTO;
// SWIFT transaction
$swiftDTO = CreateSwiftTransactionDTO::fromArray([
'account_number' => 'ACC123456789',
'amount' => 1500.00,
'reference' => 'International payment',
'iban_code' => 'DE89370400440532013000',
'beneficiary_name' => 'John Smith',
'beneficiary_country' => 'Germany',
'beneficiary_city' => 'Frankfurt',
'beneficiary_address' => '789 International Blvd',
'beneficiary_zip_code' => '60311',
'beneficiary_email' => '[email protected] ',
'swift_code' => 'DEUTDEFF',
'bank_name' => 'Deutsche Bank',
'bank_country' => 'Germany',
'bank_city' => 'Frankfurt',
'bank_address' => 'Taunusanlage 12',
'bank_zip_code' => '60325'
]);
$transaction = $client->transactions()->create('swift', $swiftDTO);
use Iberbanco\SDK\DTOs\CryptoTransaction\CreatePaymentLinkDTO;
// Create crypto payment link
$paymentLinkDTO = CreatePaymentLinkDTO::fromArray([
'email' => '[email protected] ',
'order_id' => 'ORDER_' . time(),
'fiat_amount' => 250.00,
'fiat_currency' => 'USD',
'redirect_url' => 'https://yoursite.com/payment/success'
]);
$paymentLink = $client->cryptoTransactions()->createPaymentLink($paymentLinkDTO);
// List accounts
$accounts = $client->accounts()->list([
'per_page' => 50,
'currency' => 1 // USD
]);
// Get account details
$account = $client->accounts()->show('ACC123456789');
// Get total balance
$balance = $client->accounts()->totalBalance(['currency' => 1]);
// List cards
$cards = $client->cards()->list(['visibility' => 'active']);
// Get card details
$card = $client->cards()->show('CARD123456');
// Get card transactions
$transactions = $client->cards()->transactions([
'remote_id' => 'CARD123456',
'userNumber' => 'USER123456',
'san' => 'SAN123456',
'year' => 2024,
'month' => 12
]);
// Request physical card
$physicalCard = $client->cards()->requestPhysical([
'remote_id' => 'CARD123456'
]);
// List transactions
$transactions = $client->transactions()->list([
'per_page' => 50
]);
// Get transaction details
$transaction = $client->transactions()->show('TXN123456789');
// Search transactions
$searchResults = $client->transactions()->search([
'amount_min' => 100.00,
'date_from' => '2024-01-01',
'date_to' => '2024-12-31'
]);
// Get exchange rate
$rate = $client->exchange()->getRate([
'from' => 'USD',
'to' => 'EUR',
'amount' => 1000.00
]);
bash
composer