A comprehensive PHP wrapper for the Dintero payment provider with seamless Laravel integration.
- 🚀 Complete API Coverage - All Dintero API endpoints supported
- 🎯 Laravel Integration - Service provider, facade, and configuration
- 🔒 Secure Webhooks - Built-in webhook verification and handling
- 💎 Fluent API - Intuitive and easy-to-use interface
- 🛡️ Type Safety - Full type hints and DTOs
- ⚡ Performance - HTTP client with retry logic and caching
- 📊 Logging - Comprehensive request/response logging
- 🧪 Thoroughly Tested - Comprehensive test suite
- Payment Sessions - Create and manage checkout sessions
- Split Payouts - Marketplace payments with multiple recipients
- Payment Links - Generate payment URLs and QR codes
- Recurring Billing - Subscription and invoice management
- Virtual Cards - Gift cards, vouchers, and wallet functionality
- Loyalty Programs - Discount codes, points, and stamp cards
- Transaction Management - Direct transaction control and monitoring
- Comprehensive Reporting - Revenue, analytics, and reconciliation reports
- Profile Management - Merchant settings and checkout configuration
- Multi-currency Support - Handle payments in multiple currencies
- Fraud Protection - Risk analysis and fraud detection
- Real-time Events - Webhook handling for instant notifications
- API Versioning - Support for different API versions
Install the package via Composer:
composer require andreaskviby/dintero-php-wrapperThe package will automatically register itself in Laravel 5.5+.
Publish the configuration file:
php artisan vendor:publish --provider="Dintero\Laravel\DinteroServiceProvider" --tag="dintero-config"Add your Dintero credentials to your .env file:
DINTERO_ENVIRONMENT=sandboxDINTERO_API_KEY=your_api_key_here# OR use OAuth2 credentialsDINTERO_CLIENT_ID=your_client_idDINTERO_CLIENT_SECRET=your_client_secret# Optional: Account ID (for sandbox, use T- prefix or let the wrapper add it automatically)DINTERO_ACCOUNT_ID=your_account_id# Webhook configurationDINTERO_WEBHOOK_SECRET=your_webhook_secretuseDintero\DinteroClient;
$dintero = newDinteroClient([
'environment' => 'sandbox', // or 'production''api_key' => 'your_api_key_here',
'account_id' => 'your_account_id', // Optional: for sandbox, T- prefix will be added automatically
]);
// Test connectionif ($dintero->ping()) {
echo"Connected to Dintero!";
}useDintero\Laravel\Facades\Dintero;
// Using the facade$session = Dintero::paymentSessions()->create([
'order' => [
'amount' => 10000, // 100.00 NOK'currency' => 'NOK',
'items' => [
[
'name' => 'Product Name',
'amount' => 10000,
'quantity' => 1,
]
]
],
'url' => [
'return_url' => 'https://your-site.com/return',
'callback_url' => 'https://your-site.com/callback',
]
]);useDintero\DinteroClient;
class PaymentController extends Controller
{
publicfunctioncreatePayment(DinteroClient$dintero)
{
$session = $dintero->paymentSessions->create([
// Payment data
]);
returnredirect($session['url']['hosted_payment_page']);
}
}// Create payment session$session = $dintero->paymentSessions->create([
'order' => [
'amount' => 10000,
'currency' => 'NOK',
],
'url' => [
'return_url' => 'https://example.com/return',
]
]);
// Get payment session$session = $dintero->paymentSessions->get('session-id');
// Update payment session$session = $dintero->paymentSessions->update('session-id', $data);
// Capture payment$capture = $dintero->paymentSessions->capture('session-id');
// Cancel payment$cancel = $dintero->paymentSessions->cancel('session-id');
// List all sessions$sessions = $dintero->paymentSessions->list();
// Get all sessions (paginated)foreach ($dintero->paymentSessions->all() as$session) {
// Process each session
}// Create split payout for marketplace$splits = [
['recipient_id' => 'seller_123', 'amount' => 7000],
['recipient_id' => 'platform', 'amount' => 3000]
];
$payout = $dintero->payouts->createSplit('transaction_123', $splits);
// Create payout with multiple recipients$recipients = [
['recipient_id' => 'seller_1', 'amount' => 5000],
['recipient_id' => 'seller_2', 'amount' => 3000]
];
$payout = $dintero->payouts->createWithRecipients($recipients);
// Get payout status$status = $dintero->payouts->getStatus('payout-id');
// Download payout report$report = $dintero->payouts->downloadReport('report-id', 'csv');// Create quick payment link$link = $dintero->paymentLinks->createQuick(10000, 'NOK', [
'description' => 'Invoice payment',
'expires_at' => '2024-12-31 23:59:59'
]);
// Generate QR code for payment link$qrCode = $dintero->paymentLinks->getQrCode('link-id', [
'size' => '300x300',
'format' => 'png'
]);
// Create recurring payment link$recurringLink = $dintero->paymentLinks->createRecurring([
'amount' => 29900,
'currency' => 'NOK',
'interval' => 'monthly'
]);
// Share payment link via email$dintero->paymentLinks->shareViaEmail('link-id', [
'recipient_email' => 'customer@example.com',
'subject' => 'Payment Request'
]);// Create subscription$subscription = $dintero->billing->createSubscription([
'customer_id' => 'customer-123',
'plan_id' => 'premium-plan',
'trial_period_days' => 14
]);
// Create billing plan$plan = $dintero->billing->createPlan([
'name' => 'Premium Plan',
'amount' => 29900,
'currency' => 'NOK',
'interval' => 'monthly'
]);
// Cancel subscription$dintero->billing->cancelSubscription('subscription-id');
// Create and send invoice$invoice = $dintero->billing->createInvoice($invoiceData);
$dintero->billing->sendInvoice('invoice-id');// Create gift card$giftCard = $dintero->cards->createGiftCard(50000, [
'currency' => 'NOK',
'recipient_email' => 'recipient@example.com',
'message' => 'Happy Birthday!'
]);
// Create virtual card$virtualCard = $dintero->cards->create([
'type' => 'virtual',
'initial_balance' => 25000,
'currency' => 'NOK'
]);
// Load balance to card$dintero->cards->loadBalance('card-id', 10000);
// Reserve amount on card$reservation = $dintero->cards->reserve('card-id', 5000);
// Capture reserved amount$dintero->cards->capture('card-id', 'reservation-id');// Create discount code$discount = $dintero->loyalty->createDiscount([
'code' => 'SAVE20',
'type' => 'percentage',
'value' => 20,
'minimum_amount' => 10000
]);
// Award loyalty points$dintero->loyalty->awardPoints('customer-id', 100, [
'reason' => 'Purchase reward'
]);
// Create stamp card$stampCard = $dintero->loyalty->createStampCard([
'name' => 'Coffee Loyalty Card',
'stamps_required' => 10,
'reward_description' => 'Free coffee'
]);
// Add stamp to card$dintero->loyalty->addStamp('stamp-card-id');// Get transaction$transaction = $dintero->transactions->get('transaction-id');
// Capture transaction$capture = $dintero->transactions->capture('transaction-id', [
'amount' => 8000// Partial capture
]);
// Void transaction$void = $dintero->transactions->void('transaction-id', 'Customer request');
// Get transaction events$events = $dintero->transactions->getEvents('transaction-id');
// Check transaction status$isSuccessful = $dintero->transactions->isSuccessful('transaction-id');// Get revenue reports$revenue = $dintero->reports->getRevenueReports([
'start_date' => '2024-01-01',
'end_date' => '2024-01-31',
'group_by' => 'day'
]);
// Get dashboard analytics$analytics = $dintero->reports->getDashboardAnalytics([
'period' => 'last_30_days'
]);
// Generate custom report$report = $dintero->reports->generateCustomReport([
'metrics' => ['revenue', 'transactions'],
'filters' => ['currency' => 'NOK']
]);
// Schedule report$schedule = $dintero->reports->scheduleReport([
'type' => 'revenue',
'frequency' => 'weekly',
'email' => 'admin@example.com'
]);// Get merchant profile$profile = $dintero->profiles->get();
// Update checkout configuration$config = $dintero->profiles->updateCheckoutConfig([
'theme' => 'dark',
'primary_color' => '#007bff',
'logo_url' => 'https://example.com/logo.png'
]);
// Get payment methods$methods = $dintero->profiles->getPaymentMethods();
// Enable payment method$dintero->profiles->enablePaymentMethod('vipps');
// Update branding$dintero->profiles->updateBranding([
'company_name' => 'My Company',
'primary_color' => '#ff6b35'
]);useDintero\Support\Builders\PaymentSessionBuilder;
$sessionData = (newPaymentSessionBuilder())
->withReturnUrl('https://example.com/return')
->withCallbackUrl('https://example.com/callback')
->withOrderData([
'amount' => 10000,
'currency' => 'NOK',
])
->withCustomerEmail('customer@example.com')
->withCustomerName('John', 'Doe')
->withMetadata(['order_id' => '12345'])
->build();
$session = $dintero->paymentSessions->create($sessionData);// Create customer$customer = $dintero->customers->create([
'email' => 'customer@example.com',
'first_name' => 'John',
'last_name' => 'Doe',
]);
// Get customer$customer = $dintero->customers->get('customer-id');
// Update customer$customer = $dintero->customers->update('customer-id', $data);
// List customers$customers = $dintero->customers->list();
// Search customers$customers = $dintero->customers->search('john@example.com');// Create order$order = $dintero->orders->create([
'amount' => 10000,
'currency' => 'NOK',
'items' => [
[
'name' => 'Product',
'amount' => 10000,
'quantity' => 1,
]
]
]);
// Get order$order = $dintero->orders->get('order-id');
// Add item to order$item = $dintero->orders->addItem('order-id', [
'name' => 'Additional Product',
'amount' => 5000,
'quantity' => 1,
]);// Create refund$refund = $dintero->refunds->create([
'transaction_id' => 'transaction-id',
'amount' => 5000, // Partial refund'reason' => 'Customer request',
]);
// Full refund$refund = $dintero->refunds->full('transaction-id');
// Partial refund$refund = $dintero->refunds->partial('transaction-id', 5000);
// Get refund$refund = $dintero->refunds->get('refund-id');// Verify webhook signature$isValid = $dintero->webhooks->verifySignature($payload, $signature, $secret);
// Handle webhook$event = $dintero->webhooks->handleEvent($payload, $signature, $secret, function($event) {
// Process the eventmatch ($event['type']) {
'transaction.completed' => handlePaymentCompleted($event),
'transaction.failed' => handlePaymentFailed($event),
default => null,
};
});
// Create webhook endpoint$webhook = $dintero->webhooks->createEndpoint('https://example.com/webhooks', [
'transaction.completed',
'transaction.failed',
]);The package automatically sets up webhook routes when used with Laravel:
// config/dintero.phpreturn [
'webhook_middleware' => ['api'],
'webhook_route_prefix' => 'dintero/webhooks',
'verify_webhooks' => true,
'webhook_secret' => env('DINTERO_WEBHOOK_SECRET'),
];Listen for webhook events:
// In your EventServiceProviderprotected$listen = [
'dintero.webhook.transaction.completed' => [
PaymentCompletedListener::class,
],
'dintero.webhook.transaction.failed' => [
PaymentFailedListener::class,
],
];# RequiredDINTERO_ENVIRONMENT=sandbox# or productionDINTERO_API_KEY=your_api_key# OR OAuth2 (alternative to API key)DINTERO_CLIENT_ID=your_client_idDINTERO_CLIENT_SECRET=your_client_secret# OptionalDINTERO_ACCOUNT_ID=your_account_id# Account ID (T- prefix added automatically for sandbox)DINTERO_TIMEOUT=30DINTERO_RETRY_ATTEMPTS=3DINTERO_LOG_REQUESTS=falseDINTERO_WEBHOOK_SECRET=your_webhook_secretDINTERO_DEFAULT_CURRENCY=NOKThe wrapper uses the same API URL (https://api.dintero.com/v1) for both environments. For sandbox testing:
- Set
DINTERO_ENVIRONMENT=sandbox - Use your account ID with or without the
T-prefix - the wrapper will automatically add theT-prefix for sandbox environments - For production, the wrapper will remove any
T-prefix from the account ID
// Sandbox configuration - both of these work the same way:$sandboxConfig1 = [
'environment' => 'sandbox',
'account_id' => 'ACCOUNT123', // Will become 'T-ACCOUNT123'
];
$sandboxConfig2 = [
'environment' => 'sandbox', 'account_id' => 'T-ACCOUNT123', // Stays 'T-ACCOUNT123'
];
// Production configuration$productionConfig = [
'environment' => 'production',
'account_id' => 'ACCOUNT123', // Stays 'ACCOUNT123'
];$config = [
'environment' => 'sandbox',
'api_key' => 'your_api_key',
'account_id' => 'your_account_id',
'timeout' => 30,
'retry_attempts' => 3,
'log_requests' => true,
];
$dintero = newDinteroClient($config);The package provides specific exception classes:
useDintero\Exceptions\{
DinteroException,
AuthenticationException,
ValidationException,
RateLimitException
};
try {
$session = $dintero->paymentSessions->create($data);
} catch (ValidationException$e) {
// Handle validation errors$errors = $e->getErrors();
} catch (AuthenticationException$e) {
// Handle authentication errors
} catch (RateLimitException$e) {
// Handle rate limiting
} catch (DinteroException$e) {
// Handle general Dintero errors
}composer testPlease see CONTRIBUTING for details.
If you discover any security-related issues, please email security@kviby.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
Please see CHANGELOG for more information about recent changes.