PHP code example of jeffreyvanhees / laravel-online-payment-platform
1. Go to this page and download the library: Download jeffreyvanhees/laravel-online-payment-platform 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/ */
jeffreyvanhees / laravel-online-payment-platform example snippets
use OnlinePaymentPlatform;
use JeffreyVanHees\OnlinePaymentPlatform\Data\Requests\Merchants\CreateConsumerMerchantData;
// Create a consumer merchant using DTO
$merchantData = new CreateConsumerMerchantData(
type: 'consumer',
country: 'NLD',
emailaddress: '[email protected] ',
first_name: 'John',
last_name: 'Doe',
);
$response = OnlinePaymentPlatform::merchants()->create($merchantData);
if ($response->successful()) {
$merchant = $response->dto();
echo "Created merchant: {$merchant->uid}";
}
namespace App\Services;
use JeffreyVanHees\OnlinePaymentPlatform\OnlinePaymentPlatformConnector;
use JeffreyVanHees\OnlinePaymentPlatform\Data\Requests\Merchants\CreateConsumerMerchantData;
class PaymentService
{
public function __construct(
private OnlinePaymentPlatformConnector $opp
) {}
public function createMerchant(CreateConsumerMerchantData $merchantData): string
{
$response = $this->opp->merchants()->create($merchantData);
if (!$response->successful()) {
throw new \Exception('Failed to create merchant');
}
return $response->dto()->uid;
}
// Or create connector instances directly
public function createQuickConnection(): OnlinePaymentPlatformConnector
{
return OnlinePaymentPlatformConnector::make(
apiKey: config('opp.api_key'),
sandbox: config('opp.sandbox')
);
}
}
use OnlinePaymentPlatform;
use JeffreyVanHees\OnlinePaymentPlatform\Data\Requests\Merchants\CreateConsumerMerchantData;
use JeffreyVanHees\OnlinePaymentPlatform\Data\Requests\Transactions\CreateTransactionData;
use JeffreyVanHees\OnlinePaymentPlatform\Data\Common\ProductData;
// Create merchant using DTO
$merchantData = new CreateConsumerMerchantData(
type: 'consumer',
country: 'NLD',
emailaddress: '[email protected] ',
first_name: 'Jane',
last_name: 'Doe',
notify_url: 'https://yoursite.com/webhooks/opp'
);
$merchantResponse = OnlinePaymentPlatform::merchants()->create($merchantData);
$merchant = $merchantResponse->dto();
// Create transaction with products
$transactionData = new CreateTransactionData(
merchant_uid: $merchant->uid,
total_price: 2850, // €28.50 in cents
return_url: 'https://yoursite.com/payment/return',
notify_url: 'https://yoursite.com/webhooks/opp',
products: ProductData::collect([
[
'name' => 'Big Tasty',
'quantity' => 1,
'price' => 2500,
],
[
'name' => 'Milkshake Strawberry',
'quantity' => 1,
'price' => 350,
],
])
);
$transactionResponse = OnlinePaymentPlatform::transactions()->create($transactionData);
$transaction = $transactionResponse->dto();
echo "Payment URL: {$transaction->redirect_url}";
use JeffreyVanHees\OnlinePaymentPlatform\Data\Requests\Merchants\{
CreateConsumerMerchantData,
CreateBusinessMerchantData
};
// Create consumer merchant
$consumerData = new CreateConsumerMerchantData(
type: 'consumer',
country: 'NLD',
emailaddress: '[email protected] ',
first_name: 'John',
last_name: 'Doe',
notify_url: 'https://yoursite.com/webhooks/opp',
);
$consumer = OnlinePaymentPlatform::merchants()->create($consumerData);
// Note: For consumer merchants, name_first/name_last in requests become 'name' field in responses
// For business merchants, legal_name in requests becomes 'name' field in responses
// Create business merchant
$businessData = new CreateBusinessMerchantData(
type: 'business',
country: 'NLD',
emailaddress: '[email protected] ',
coc_nr: '12345678',
legal_name: 'Example B.V.',
notify_url: 'https://yoursite.com/webhooks/opp',
);
$business = OnlinePaymentPlatform::merchants()->create($businessData);
// Retrieve and list merchants
$merchant = OnlinePaymentPlatform::merchants()->get('mer_123456789');
$merchants = OnlinePaymentPlatform::merchants()->list(['limit' => 50]);
// Add contacts and addresses
$contact = OnlinePaymentPlatform::merchants()->contacts('mer_123456789')->add([
'type' => 'representative',
'gender' => 'm',
'title' => 'mr',
'name' => [
'first' => 'John',
'last' => 'Smith',
'initials' => 'J.S.',
'names_given' => 'John',
],
'emailaddresses' => [
['emailaddress' => '[email protected] ']
],
'phonenumbers' => [
['phonenumber' => '+31612345678']
],
]);
$address = OnlinePaymentPlatform::merchants()->addresses('mer_123456789')->add([
'type' => 'business',
'address_line_1' => 'Main Street 123',
'city' => 'Amsterdam',
'zipcode' => '1000 AA',
'country' => 'NLD',
]);
// Add bank account for merchant
$bankAccount = OnlinePaymentPlatform::merchants()->bankAccounts('mer_123456789')->add([
'return_url' => 'https://yoursite.com/bank-return',
'notify_url' => 'https://yoursite.com/bank-notify',
'is_default' => true,
'reference' => 'BANK-REF-001',
]);
// Or using DTO for type safety
use JeffreyVanHees\OnlinePaymentPlatform\Data\Requests\Merchants\CreateMerchantBankAccountData;
$bankAccountData = new CreateMerchantBankAccountData(
return_url: 'https://yoursite.com/bank-return',
notify_url: 'https://yoursite.com/bank-notify',
is_default: true,
reference: 'BANK-REF-001'
);
$bankAccount = OnlinePaymentPlatform::merchants()->bankAccounts('mer_123456789')->add($bankAccountData);
// Manage Ultimate Beneficial Owners (UBOs) for business merchants
$ubo = OnlinePaymentPlatform::merchants()->ubos('mer_123456789')->create([
'name_first' => 'John',
'name_last' => 'Doe',
'date_of_birth' => '1980-01-15',
'country_of_residence' => 'NLD',
'is_decision_maker' => true,
'percentage_of_shares' => 25.5,
]);
// Create merchant profiles for different configurations
$profile = OnlinePaymentPlatform::merchants()->profiles('mer_123456789')->create([
'name' => 'E-commerce Profile',
'description' => 'Settings for online store',
'notify_url' => 'https://store.example.com/webhook',
'return_url' => 'https://store.example.com/success',
'is_default' => false,
]);
// Update merchant information
$updated = OnlinePaymentPlatform::merchants()->update('mer_123456789', [
'emailaddress' => '[email protected] ',
'notify_url' => 'https://newdomain.com/webhook',
'return_url' => 'https://newdomain.com/return',
]);
// Migrate consumer merchant to business merchant
$migrated = OnlinePaymentPlatform::merchants()->migrate('mer_123456789', [
'type' => 'business',
'legal_name' => 'Example Business B.V.',
'coc_nr' => '12345678',
]);
// Get available payment methods for merchant
$paymentMethods = OnlinePaymentPlatform::merchants()->paymentMethods('mer_123456789')->list();
// Get merchant profile balance
$balance = OnlinePaymentPlatform::merchants()->profiles('mer_123456789')->balance('pro_987654321');
use JeffreyVanHees\OnlinePaymentPlatform\Data\Requests\Merchants;
// Update merchant address
$addressData = new Merchants\UpdateMerchantAddressData(
street: 'Updated Street 456',
housenumber: '12B',
city: 'Rotterdam',
zipcode: '3000 AA'
);
$updatedAddress = OnlinePaymentPlatform::merchants()->addresses('mer_123456789')->update('addr_123456789', $addressData);
// Retrieve a specific bank account
$bankAccountResponse = OnlinePaymentPlatform::merchants()->bankAccounts('mer_123456789')->get('ba_123456789');
$bankAccount = $bankAccountResponse->dto();
// Access bank account properties
echo "Bank Account UID: {$bankAccount->uid}";
echo "IBAN: {$bankAccount->account->account_iban}";
echo "Account Name: {$bankAccount->account->account_name}";
echo "BIC: {$bankAccount->bank->bic}";
echo "Status: {$bankAccount->status}";
echo "Verification URL: {$bankAccount->verification_url}";
// Update bank account information
$bankAccountData = new Merchants\UpdateMerchantBankAccountData(
reference: 'updated-bank-ref-123',
return_url: 'https://store.example.com/bank-return',
notify_url: 'https://store.example.com/bank-notify'
);
$updatedBankAccount = OnlinePaymentPlatform::merchants()->bankAccounts('mer_123456789')->update('ba_123456789', $bankAccountData);
// Update contact information
$contactData = new Merchants\UpdateMerchantContactData(
name: 'Jane Doe Updated',
email: '[email protected] ',
phone: '+31612345679'
);
$updatedContact = OnlinePaymentPlatform::merchants()->contacts('mer_123456789')->update('con_123456789', $contactData);
// Update merchant profile
$profileData = new Merchants\UpdateMerchantProfileData(
name: 'Updated E-commerce Profile',
description: 'Updated settings for online store',
url: 'https://store.example.com',
notify_url: 'https://store.example.com/updated-webhook',
return_url: 'https://store.example.com/updated-success'
);
$updatedProfile = OnlinePaymentPlatform::merchants()->profiles('mer_123456789')->update('pro_123456789', $profileData);
// Update UBO information
$uboData = new Merchants\UpdateMerchantUBOData(
name: 'John Doe Updated',
name_prefix: 'Mr.',
date_of_birth: '1980-01-15',
country_of_residence: 'NLD',
percentage_of_shares: 30.0
);
$updatedUBO = OnlinePaymentPlatform::merchants()->ubos('mer_123456789')->update('ubo_123456789', $uboData);
// Access UBO response data
$ubo = $updatedUBO->dto();
echo "UBO Status: {$ubo->status}";
echo "UBO UID: {$ubo->uid}";
echo "Names First: {$ubo->names_first}";
echo "Decision Maker: " . ($ubo->is_decision_maker ? 'Yes' : 'No');
echo "Decision Maker Percentage: {$ubo->decision_maker_percentage}%";
echo "Is PEP: " . ($ubo->is_pep ? 'Yes' : 'No');
// Delete operations (where supported)
$deleteResult = OnlinePaymentPlatform::merchants()->profiles('mer_123456789')->delete('pro_123456789');
// Note: These methods only work in sandbox environment and will throw
// SandboxOnlyException in production
// Update merchant status (sandbox only)
$statusResult = OnlinePaymentPlatform::merchants()->updateStatus('mer_123456789', 'live');
// Available statuses: pending, live, terminated, suspended, blocked
// Update bank account status (sandbox only)
$bankStatusResult = OnlinePaymentPlatform::merchants()->bankAccounts('mer_123456789')->updateStatus('ba_123456789', 'approved');
// Available statuses: pending, approved, disapproved
// Status flows: new -> pending -> approved/disapproved, approved -> disapproved -> approved
// Update contact status (sandbox only)
$contactStatusResult = OnlinePaymentPlatform::merchants()->contacts('mer_123456789')->updateStatus('con_123456789', 'verified');
// Available statuses: pending, verified, unverified
// Status flows: pending -> unverified/verified, unverified -> verified
// Update UBO status (sandbox only)
$uboStatusResult = OnlinePaymentPlatform::merchants()->ubos('mer_123456789')->updateStatus('ubo_123456789', 'verified');
// Available statuses: pending, verified, unverified
// Status flows: pending -> unverified/verified, unverified -> verified
// Using DTOs (recommended for type safety)
$contactData = new Merchants\UpdateMerchantContactData(
name: 'John Updated',
email: '[email protected] '
);
$result = OnlinePaymentPlatform::merchants()->contacts('mer_123')->update('con_123', $contactData);
// Using arrays (convenient for simple updates)
$result = OnlinePaymentPlatform::merchants()->contacts('mer_123')->update('con_123', [
'name' => 'John Updated',
'email' => '[email protected] '
]);
// Status updates accept DTO, array, or string
$result = OnlinePaymentPlatform::merchants()->updateStatus('mer_123', 'live'); // string
$result = OnlinePaymentPlatform::merchants()->updateStatus('mer_123', ['status' => 'live']); // array
$result = OnlinePaymentPlatform::merchants()->updateStatus('mer_123', new Merchants\UpdateMerchantStatusData('live')); // DTO
// Create transactions
$transaction = OnlinePaymentPlatform::transactions()->create([
'merchant_uid' => 'mer_123456789',
'total_price' => 1000, // €10.00 in cents
'products' => [
[
'name' => 'Product Name',
'quantity' => 1,
'price' => 1000,
],
],
'return_url' => 'https://yoursite.com/payment/return',
'notify_url' => 'https://yoursite.com/webhooks/opp',
]);
// Retrieve and list transactions
$transaction = OnlinePaymentPlatform::transactions()->get('tra_987654321');
$transactions = OnlinePaymentPlatform::transactions()->list(['limit' => 100]);
// Update transaction
$updated = OnlinePaymentPlatform::transactions()->update('tra_987654321', [
'description' => 'Updated description',
]);
use JeffreyVanHees\OnlinePaymentPlatform\Data\Requests\Transactions\CreateRefundData;
// Create a refund for a transaction
$refundData = new CreateRefundData(
amount: 1000, // €10.00 in cents
payout_description: 'Refund for defective product',
internal_reason: 'product_defect',
metadata: ['reason' => 'customer_complaint']
);
$refund = OnlinePaymentPlatform::transactions()->refunds('tra_123456789')->create($refundData);
// List all refunds for a transaction
$refunds = OnlinePaymentPlatform::transactions()->refunds('tra_123456789')->list();
// Access refund data
if ($refund->successful()) {
$refundData = $refund->dto();
echo "Refund created: {$refundData->uid}";
echo "Status: {$refundData->status}";
echo "Amount: {$refundData->amount} cents";
}
// List all platform settlements
$settlements = OnlinePaymentPlatform::settlements()->list([
'status' => 'completed',
'limit' => 50
]);
// Get detailed settlement specification rows
$settlementRows = OnlinePaymentPlatform::settlements()->specificationRows(
settlementUid: 'set_123456789',
specificationUid: 'spec_987654321'
);
// Access settlement data
foreach ($settlements->dto()->data as $settlement) {
echo "Settlement: {$settlement->uid}";
echo "Status: {$settlement->status}";
echo "Total Amount: {$settlement->total_amount}";
echo "Period: {$settlement->period_start} - {$settlement->period_end}";
}
// Access settlement row details
foreach ($settlementRows->dto()->data as $row) {
echo "Type: {$row->type}";
echo "Reference: {$row->reference}";
echo "Amount: {$row->amount}";
if ($row->amount_payable) {
echo "Amount Payable: {$row->amount_payable}";
}
}
// Create charges for balance transfers between merchants
$charge = OnlinePaymentPlatform::charges()->create([
'type' => 'balance',
'amount' => 1500, // €15.00 in cents
'from_owner_uid' => 'mer_123456789',
'to_owner_uid' => 'mer_987654321',
'description' => 'Monthly platform fee',
'metadata' => ['invoice_id' => 'INV-2024-001'],
]);
// Retrieve charge details
$charge = OnlinePaymentPlatform::charges()->get('cha_123456789');
// List charges with filters
$charges = OnlinePaymentPlatform::charges()->list([
'from_owner_uid' => 'mer_123456789',
'status' => 'completed',
'limit' => 50,
]);
// Create SEPA Direct Debit mandate
$mandate = OnlinePaymentPlatform::mandates()->create([
'merchant_uid' => 'mer_123456789',
'holder_name' => 'John Doe',
'iban' => 'NL91ABNA0417164300',
'bic' => 'ABNANL2A',
'description' => 'Monthly meal plan mandate',
'reference' => 'MEALPLAN-2024',
]);
// Retrieve mandate
$mandate = OnlinePaymentPlatform::mandates()->get('man_123456789');
// Create transaction using mandate
$transaction = OnlinePaymentPlatform::mandates()->transactions('man_123456789')->create([
'amount' => 2500, // €25.00 in cents
'description' => 'Monthly meal plan payment',
]);
// Delete mandate
OnlinePaymentPlatform::mandates()->delete('man_123456789');
// Create withdrawal to merchant's bank account
$withdrawal = OnlinePaymentPlatform::withdrawals()->create('mer_123456789', [
'amount' => 50000, // €500.00 in cents
'currency' => 'EUR',
'bank_account_uid' => 'ban_123456789',
'description' => 'Weekly payout',
'reference' => 'PAYOUT-2024-W01',
]);
// Retrieve withdrawal status
$withdrawal = OnlinePaymentPlatform::withdrawals()->get('wit_123456789');
// List withdrawals for a merchant
$withdrawals = OnlinePaymentPlatform::withdrawals()->list([
'merchant_uid' => 'mer_123456789',
'status' => 'completed',
'limit' => 25,
]);
// Cancel pending withdrawal
OnlinePaymentPlatform::withdrawals()->delete('wit_123456789');
// Create dispute for a transaction
$dispute = OnlinePaymentPlatform::disputes()->create([
'transaction_uid' => 'tra_123456789',
'amount' => 1000, // €10.00 in cents
'reason' => 'Product not received',
'message' => 'Customer claims product was never delivered',
'evidence' => [
'tracking_number' => 'TRACK123456',
'shipping_date' => '2024-01-15',
],
]);
// Retrieve dispute with transaction details
$dispute = OnlinePaymentPlatform::disputes()->get('dis_123456789', [
'
// Create file upload token
$upload = OnlinePaymentPlatform::files()->createUpload([
'filename' => 'invoice.pdf',
'purpose' => 'dispute_evidence',
]);
// Upload the actual file
$file = OnlinePaymentPlatform::files()->upload(
fileUid: $upload->dto()->uid,
token: $upload->dto()->token,
filePath: '/path/to/invoice.pdf',
fileName: 'invoice.pdf'
);
// List uploaded files
$files = OnlinePaymentPlatform::files()->list([
'purpose' => 'dispute_evidence',
'created_after' => '2024-01-01',
]);
// Get partner configuration
$config = OnlinePaymentPlatform::partners()->getConfiguration();
// Update partner settings (only notify_url is updatable)
$updated = OnlinePaymentPlatform::partners()->updateConfiguration([
'notify_url' => 'https://partner.example.com/webhooks',
]);
// Get merchant balance via partner
$merchantBalance = OnlinePaymentPlatform::partners()->getMerchantBalance('mer_123456789');
// Get single page of results
$response = OnlinePaymentPlatform::merchants()->list(['limit' => 25]);
$merchants = $response->dto();
// Process single page
foreach ($merchants->data as $merchant) {
echo "Merchant: {$merchant->uid} - {$merchant->emailaddress}\n";
}
// ✨ Magic: Iterate through ALL pages automatically
foreach (OnlinePaymentPlatform::merchants()->list(['limit' => 25])->paginate() as $response) {
$merchants = $response->dto();
foreach ($merchants->data as $merchant) {
echo "Merchant: {$merchant->uid} - {$merchant->emailaddress}\n";
}
echo "Processed page with " . count($merchants->data) . " merchants\n";
}
// The paginate() method handles all the complexity:
// - Automatically fetches next pages
// - Handles different pagination strategies
// - Stops when no more results
// - Memory efficient iteration
return [
/*
|--------------------------------------------------------------------------
| API Credentials
|--------------------------------------------------------------------------
*/
'api_key' => env('OPP_API_KEY'),
'sandbox_api_key' => env('OPP_SANDBOX_API_KEY'),
/*
|--------------------------------------------------------------------------
| Environment
|--------------------------------------------------------------------------
*/
'sandbox' => env('OPP_SANDBOX', true),
/*
|--------------------------------------------------------------------------
| HTTP Configuration
|--------------------------------------------------------------------------
*/
'timeout' => env('OPP_TIMEOUT', 30),
'retry' => [
'times' => env('OPP_RETRY_TIMES', 3),
'sleep' => env('OPP_RETRY_SLEEP', 1000),
],
];
use JeffreyVanHees\OnlinePaymentPlatform\Exceptions\{
OppException,
AuthenticationException,
ValidationException,
RateLimitException,
ApiException
};
try {
$response = OnlinePaymentPlatform::merchants()->create($invalidData);
} catch (ValidationException $e) {
// Handle validation errors
$errors = $e->getValidationErrors();
foreach ($errors as $field => $messages) {
echo "{$field}: " . implode(', ', $messages);
}
} catch (AuthenticationException $e) {
// Handle authentication issues
echo "Authentication failed: " . $e->getMessage();
} catch (RateLimitException $e) {
// Handle rate limiting
echo "Rate limit exceeded. Retry after: " . $e->getRetryAfter();
} catch (OppException $e) {
// Handle general API errors
echo "API Error: " . $e->getMessage();
}
use JeffreyVanHees\OnlinePaymentPlatform\OnlinePaymentPlatformConnector;
// Using constructor
$connector = new OnlinePaymentPlatformConnector(
apiKey: 'your-api-key',
sandbox: true
);
// Or using the static make() method
$connector = OnlinePaymentPlatformConnector::make('your-api-key', true);
$connector = OnlinePaymentPlatformConnector::make('your-api-key'); // defaults to sandbox
$connector = OnlinePaymentPlatformConnector::make('your-api-key', false); // production
// Add custom middleware
$connector->middleware()->onRequest(function ($request) {
$request->headers()->add('Custom-Header', 'value');
return $request;
});
// Add retry logic
$connector->middleware()->onResponse(function ($response) {
if ($response->status() === 429) {
sleep(1);
return $response->throw(); // Retry
}
return $response;
});
bash
php artisan vendor:publish --tag=opp-config