<?php
declare(strict_types=1);
namespace OwnPay\Modules\Gateways\MyGateway;
use OwnPay\Gateway\GatewayAdapterInterface;
use OwnPay\Gateway\GatewayDefaults;
use OwnPay\Plugin\PluginInterface;
use OwnPay\Plugin\Capability;
use OwnPay\Container;
use OwnPay\Event\EventManager;
final class MyGateway implements PluginInterface, GatewayAdapterInterface
{
use GatewayDefaults;
public static function metadata(): array
{
return [
'name' => 'My Gateway',
'slug' => 'my-gateway',
'version' => '1.0.0',
'description' => 'My custom payment gateway.',
'author' => 'Your Name',
'type' => 'gateway',
];
}
public function capabilities(): array
{
return [Capability::GATEWAY];
}
public function register(EventManager $events, Container $container): void
{
// Register hooks here if needed
}
public function boot(Container $container): void {}
public function deactivate(Container $container): void {}
public function uninstall(Container $container): void {}
public function fields(): array
{
return [
[
'name' => 'api_key',
'label' => 'API Key',
'type' => 'password',
'required' => true,
],
[
'name' => 'mode',
'label' => 'Mode',
'type' => 'select',
'options' => ['sandbox' => 'Sandbox', 'live' => 'Live'],
'required' => true,
],
];
}
public function slug(): string
{
return 'my-gateway';
}
public function initiate(array $params, array $credentials): array
{
// $params: amount, currency, trx_id, redirect_url, cancel_url
// Return: redirect_url OR form_html OR session_id
}
public function verify(array $callbackData, array $credentials): array
{
// ALWAYS verify server-side with the gateway API
// Return: ['success' => bool, 'gateway_trx_id' => string, 'amount' => string|null, 'status' => string]
}
public function verifyWebhook(string $rawBody, array $headers, array $credentials): bool
{
// Validate the inbound webhook signature
}
public function refund(string $gatewayTrxId, string $amount, array $credentials): array
{
// Return: ['success' => bool, 'refund_id' => string|null, 'error' => string|null]
}
public function supports(string $feature): bool
{
return match ($feature) {
'refund', 'verification' => true,
default => false,
};
}
public function supportedCurrencies(): array
{
return []; // Empty = accepts any currency
}
}