Step 3: Update CustomPaymentGateway.php

Overview

The CustomPaymentGateway.php file is responsible for processing payments via the configured gateway. It interacts with the payment processor, handles payment requests, and manages responses.

The CustomPaymentGateway class extends the GatewayBase class, which contains the general functionality for payment gateways. By extending this class, you inherit reusable methods, allowing you to focus only on the specifics of your payment gateway.

Key Properties

The CustomPaymentGateway.php file contains the following properties that help manage the configuration, directory structure, and payment handling for your custom payment gateway.

  • $dir_name: Specifies the core payment class name for your payment gateway. This will be the folder where all your payment gateway files reside.
  • $config_class: References the configuration class for the custom payment gateway. This is the class that manages the payment gateway settings (such as secret keys, public keys, etc.). In this case, it references CustomPaymentConfig::class.
  • $payment_class: References the payment core class that processes transactions. Here, it points to Custompayment::class, which contains the logic for handling the payment transactions.

Methods Overview

The class includes several methods to retrieve directory names, configuration settings, and payment processing logic.

get_root_dir_name(): Returns the root directory name where the payment gateway files are stored.

get_payment_class(): Returns the class that handles the actual payment processing.

get_config_class(): Returns the configuration class, which contains the necessary settings (such as API keys and environment settings).

get_autoload_file(): Returns the path to the autoload file for the payment gateway, which is used to load all the dependencies required for your gateway.

What to Update in CustomPaymentGateway.php

  1. Gateway Class Reference:

The $payment_class and $config_class properties are set to reference Custompayment and CustomPaymentConfig classes by default. These properties should be updated to reflect the specific classes that handle the payment transactions and configurations for your gateway.

  1. Gateway Directory Name:

The $dir_name property is set to 'Custompayment'. This corresponds to the root directory where your payment gateway files are stored. If you choose to rename your folder, make sure to update this property accordingly. 

     3. Autoload File:

The get_autoload_file() method is used to return the path to the autoload file, typically required if you’re using Composer to manage dependencies. If your gateway requires this autoloader, specify the correct path to it, like so:

public static function get_autoload_file() {
       return '/path/to/vendor/autoload.php';
}

If no autoload file is required, you can leave the method as is (returning an empty string).

Summary of Changes for CustomPaymentConfig.php:

Properties: Update $dir_name, $payment_class, and $config_class to match your gateway’s structure.

Autoload File: Update the path if using Composer for dependency management.

Was this helpful?