Payment Providers
Payment Provider Interface
<?php
namespace Plugins\MyPlugin\Provider;
use App\Core\Payment\PaymentProviderInterface;
use App\Core\Payment\DTO\PaymentSessionDTO;
class MyPaymentProvider implements PaymentProviderInterface
{
public function __construct(
private readonly MyPaymentAdapter $adapter,
private readonly LoggerInterface $logger,
) {}
public function getIdentifier(): string
{
return 'my-provider';
}
public function getDisplayName(): string
{
return 'My Payment Provider';
}
public function isConfigured(): bool
{
// Check if required settings are present
$apiKey = $this->pluginSettings->get('my-plugin', 'api_key');
return !empty($apiKey);
}
public function createSession(
string $userId,
float $amount,
string $currency,
array $metadata = []
): ?PaymentSessionDTO {
try {
$session = $this->adapter->createPaymentSession(
amount: $amount,
currency: $currency,
metadata: $metadata
);
return new PaymentSessionDTO(
id: $session['id'],
status: $session['status'],
amount: $amount,
currency: $currency,
checkoutUrl: $session['checkout_url'],
metadata: $metadata
);
} catch (\Exception $e) {
$this->logger->error('Payment session creation failed', [
'provider' => $this->getIdentifier(),
'error' => $e->getMessage()
]);
return null;
}
}
public function retrieveSession(string $sessionId): ?PaymentSessionDTO
{
try {
$session = $this->adapter->getSession($sessionId);
return new PaymentSessionDTO(
id: $session['id'],
status: $session['status'],
amount: $session['amount'],
currency: $session['currency'],
checkoutUrl: $session['checkout_url'],
metadata: $session['metadata']
);
} catch (\Exception $e) {
$this->logger->error('Payment session retrieval failed', [
'provider' => $this->getIdentifier(),
'session_id' => $sessionId,
'error' => $e->getMessage()
]);
return null;
}
}
public function getIcon(): string
{
return 'fab fa-cc-stripe'; // FontAwesome icon
}
public function getDescription(): string
{
return 'Accept payments via My Payment Provider';
}
public function getSupportedCurrencies(): array
{
return ['USD', 'EUR', 'GBP', 'PLN'];
}
public function getMetadata(): array
{
return [
'website' => 'https://myprovider.com',
'support_email' => '[email protected]',
];
}
public function getSuccessCallbackRoute(): string
{
return 'plugin_my_plugin_payment_success';
}
public function getCancelCallbackRoute(): string
{
return 'plugin_my_plugin_payment_cancel';
}
public function extractSessionIdFromCallback(Request $request): ?string
{
return $request->query->get('session_id');
}
public function buildSuccessUrl(string $baseUrl): string
{
return $baseUrl . '?status=success';
}
public function buildCancelUrl(string $baseUrl): string
{
return $baseUrl . '?status=cancelled';
}
}Required Interface Methods
Core Methods
Session Management
Callback Handling
Payment Adapter Pattern
Webhook Handling
Service Registration
External SDK Integration
Configuration Schema
Testing Payment Provider
Error Handling
Security Best Practices
Related Guides
Last updated