Files
WooNooW/includes/Api/Routes.php
dwindown 247b2c6b74 feat: Implement Payment Gateways backend foundation
 Phase 1 Backend Complete:

📦 PaymentGatewaysProvider.php:
- Read WC gateways from WC()->payment_gateways()
- Transform to clean JSON format
- Categorize: manual/provider/other
- Extract settings: basic/api/advanced
- Check requirements (SSL, extensions)
- Generate webhook URLs
- Respect WC bone structure (WC_Payment_Gateway)

📡 PaymentsController.php:
- GET /woonoow/v1/payments/gateways (list all)
- GET /woonoow/v1/payments/gateways/{id} (single)
- POST /woonoow/v1/payments/gateways/{id} (save settings)
- POST /woonoow/v1/payments/gateways/{id}/toggle (enable/disable)
- Permission checks (manage_woocommerce)
- Error handling with proper HTTP codes
- Response caching (5 min)

🔌 Integration:
- Registered in Api/Routes.php
- Auto-discovers all WC-compliant gateways
- No new hooks - listens to WC structure

📋 Checklist Progress:
- [x] PaymentGatewaysProvider.php
- [x] PaymentsController.php
- [x] REST API registration
- [ ] Frontend components (next)
2025-11-05 21:09:49 +07:00

50 lines
1.7 KiB
PHP

<?php
namespace WooNooW\Api;
use WP_REST_Request;
use WP_REST_Response;
use WooNooW\Api\CheckoutController;
use WooNooW\Api\OrdersController;
use WooNooW\Api\AnalyticsController;
use WooNooW\Api\AuthController;
use WooNooW\API\PaymentsController;
class Routes {
public static function init() {
// Initialize controllers (register action hooks)
OrdersController::init();
add_action('rest_api_init', function () {
$namespace = 'woonoow/v1';
// Auth endpoints (public - no permission check)
register_rest_route( $namespace, '/auth/login', [
'methods' => 'POST',
'callback' => [ AuthController::class, 'login' ],
'permission_callback' => '__return_true',
] );
register_rest_route( $namespace, '/auth/logout', [
'methods' => 'POST',
'callback' => [ AuthController::class, 'logout' ],
'permission_callback' => '__return_true',
] );
register_rest_route( $namespace, '/auth/check', [
'methods' => 'GET',
'callback' => [ AuthController::class, 'check' ],
'permission_callback' => '__return_true',
] );
// Defer to controllers to register their endpoints
CheckoutController::register();
OrdersController::register();
AnalyticsController::register_routes();
// Payments controller
$payments_controller = new PaymentsController();
$payments_controller->register_routes();
});
}
}