Extending Services

1. Extending Services (Airtime, Data, Cable, etc.)

All services in VTUPress inherit from the `Vtupress_services` abstract class (which itself extends `Vtupress_Process_Transactions`).

Base Class: `Vtupress_services`

**File:** `includes/services_class.php`

To create a brand new service (e.g., “Electricity Cards” or “International Topup”):

1. Create a new class extending `Vtupress_services` and implementing `Vtupress_History_Interface`.

2. Register your class into the VTUPress ecosystem using the `vtupress_service_registry` filter.

Example: Adding a Custom Service

```php

class Custom_Service extends Vtupress_services implements Vtupress_History_Interface {

    public function __construct() {

        $this->id = 'custom_service';

        $this->name = 'Custom Service';

        $this->icon = 'fa-solid fa-bolt';

        // Initialize other properties...

    }

    public function process_transaction($payload) {

        // Implement your custom API connection and processing logic here

    }

}

// Register the service

add_filter('vtupress_service_registry', function($registry) {

    $registry['custom_service'] = 'Custom_Service';

    return $registry;

});

```

Was this page helpful?