Step 2: Update CustomPaymentConfig.php

Overview

The CustomPaymentConfig.php file handles the configuration settings for your payment gateway. Here’s a breakdown of the parts of the code and what they do:

Class Declaration and Namespaces

The class is located under the CustomPayment namespace, and it extends from BaseConfig and implements the ConfigContract.

namespace CustomPayment;

use Tutor\Ecommerce\Settings;
use Ollyo\PaymentHub\Core\Payment\BaseConfig;
use Tutor\PaymentGateways\Configs\PaymentUrlsTrait;
use Ollyo\PaymentHub\Contracts\Payment\ConfigContract;
  • BaseConfig is the core architecture class that handles basic configuration functionalities.
  • ConfigContract is an interface, ensuring that the class implements necessary contract methods for configuration.

Class Properties

The configuration properties such as public_key, secret_key, environment, etc., are defined as private properties in the class. Define the required fields of your payment gateway here.

private $environment;
private $public_key;
private $secret_key;
private $client_id;
protected $name = 'custompayment';

These fields are provided by the payment gateway and can be filled in by the user via the WordPress admin panel (through the Payment settings in Tutor LMS).

What to Update in CustomPaymentConfig.php

Step 1: Update the Class Name and Namespace

  • If you’re integrating a new payment gateway, you will need to update the class name and namespace to reflect that gateway.

Step 2: Update Configuration Fields

  • If the new gateway requires different fields (e.g., merchant ID, currency type, etc.), you need to define them in the class. Add the new fields as private properties.

Example:

private $merchant_id;
private $currency_type;

Then, update the method get_custompayment_config_keys() to reflect the new fields added.

private function get_custompayment_config_keys() {
       return array(
           'environment' => 'environment',
           'secret_key'  => 'secret_key',
           'public_key'  => 'secret_key',
           'client_id'   => 'secret_key',
           'merchant_id'   => 'secret_key',   // New field
       );
}

Add Getter Methods

  • To allow access to these fields, add getter methods for each configuration setting.

Example for the merchant ID:

private function getMerchantID(): string {
       return $this->merchant_id;
}

Verify the Configuration

The is_configured() method is used to check if all required fields are present. If you add new fields, ensure they are included in this check. 

Before checking is_configured, you need to ensure that the merchant_id (and any other new fields) are properly initialized in createConfig

Here’s how you can update the code:

  1. Define the merchant_id in createConfig().
public function createConfig(): void {
       parent::createConfig();
       $config = array( 'merchant_id' => $this->getMerchantID() );
       $this->updateConfig( $config );
}
  1. Update the is_configured() method to include merchant_id.
public function is_configured() {
       return $this->secret_key && $this->public_key && $this->merchant_id;
}

Summary of Changes for CustomPaymentConfig.php:

  • Class Name and Namespace: Update the class name and namespace to reflect the new gateway.
  • Configuration Fields: Add new fields as needed (e.g., merchant_id, currency_type).
  • Constructor: Ensure the constructor correctly loads the settings for the new fields.
  • Getter Methods: Add getter methods for new fields.
  • is_configured Method: Include the new fields in the configuration validation.

Was this helpful?