dbp/relay-mono-connector-campusonline-bundle
Install the Bundle Add the package to your Laravel project via Composer:
composer require dbp/relay-mono-connector-campusonline-bundle
Ensure the bundle is enabled in config/bundles.php:
return [
// ...
DigitalBlueprint\RelayMonoConnectorCampusonlineBundle\DigitalBlueprintRelayMonoConnectorCampusonlineBundle::class => ['all' => true],
];
Publish Configuration Publish the default configuration to customize API endpoints, credentials, and behavior:
php artisan vendor:publish --provider="DigitalBlueprint\RelayMonoConnectorCampusonlineBundle\DigitalBlueprintRelayMonoConnectorCampusonlineBundle" --tag="config"
Edit the published config at config/relay_mono_connector_campusonline.php.
First Use Case: Payment Processing Use the connector to initiate a CampusOnline payment via Relay’s Mono bundle:
use DigitalBlueprint\RelayMonoConnectorCampusonlineBundle\Service\CampusOnlinePaymentService;
$paymentService = app(CampusOnlinePaymentService::class);
$payment = $paymentService->createPayment([
'amount' => 100.00,
'currency' => 'EUR',
'reference' => 'ORDER-12345',
'metadata' => ['user_id' => 1],
]);
Check the documentation for request/response structures.
Payment Initiation
CampusOnlinePaymentService to create payments, refunds, or captures.$paymentService->refundPayment($paymentId, ['reason' => 'Customer request']);
Webhook Handling
routes/api.php:
Route::post('/campusonline/webhook', [CampusOnlineWebhookController::class, 'handle']);
CampusOnlineWebhookController to validate and process events (e.g., payment.succeeded).Integration with Relay Mono
RelayMonoBundle is configured to route CampusOnline-specific requests:
# config/relay_mono.yaml
connectors:
campusonline:
enabled: true
service_id: 'campusonline-connector'
Logging and Debugging
'debug' => env('APP_DEBUG', false),
\Log::debug('CampusOnline payment request', ['data' => $requestData]);
spatie/laravel-retryable) for transient failures.idempotency_key in requests to avoid duplicate processing.PaymentProcessed) after connector operations:
event(new PaymentProcessed($payment));
Configuration Overrides
config/relay_mono_connector_campusonline.php is merged correctly with environment variables (e.g., CAMPUSONLINE_API_KEY).config('relay_mono_connector_campusonline.api_key') to avoid hardcoding.Webhook Validation
CampusOnlineWebhookValidator service:
$validator = app(CampusOnlineWebhookValidator::class);
if (!$validator->isValid($request)) {
abort(403, 'Invalid webhook signature');
}
Rate Limiting
$this->retry(3, function () use ($paymentService) {
return $paymentService->createPayment($data);
}, 1000); // 1-second delay
Currency/Amount Formatting
100.00 → 10000 for EUR cents).$amountInCents = (int) ($amount * 100);
'debug' => true in config to log raw API calls.config['sandbox'] = true).\Log::error('CampusOnline error', [
'response' => $response->getContent(),
'status' => $response->getStatusCode(),
]);
Custom Services
CampusOnlinePaymentService to add domain-specific logic:
class CustomCampusOnlineService extends CampusOnlinePaymentService {
public function customPaymentFlow(array $data) {
// ...
}
}
$this->app->bind(CampusOnlinePaymentService::class, CustomCampusOnlineService::class);
Event Listeners
CampusOnlinePaymentCreated or CampusOnlineWebhookReceived events to extend functionality:
public function handle(CampusOnlinePaymentCreated $event) {
// Update your CRM or send notifications
}
Custom Webhook Handlers
$this->app->bind(
CampusOnlineWebhookController::class,
CustomCampusOnlineWebhookController::class
);
CAMPUSONLINE_ (e.g., CAMPUSONLINE_API_KEY).timeout = 30 seconds). Adjust in config if needed.'verify_ssl' => false), never in production.
```markdown
## Additional Notes for Laravel Developers
- **Service Container**: The bundle leverages Laravel’s DI container. Inject dependencies explicitly (e.g., `HttpClient`, `Logger`) for testing.
- **Testing**: Use `RelayMonoConnectorCampusonlineBundleTestCase` as a base for unit tests to mock HTTP clients.
- **Queue Jobs**: Offload long-running operations (e.g., webhook processing) to queues:
```php
dispatch(new ProcessCampusOnlineWebhook($payload));
client config if versioning is required.How can I help you explore Laravel packages today?