Introduce New Payment Gateway:

add_filter("payment_method", "wpdmpp_new_payment_method");

function wpdmpp_new_payment_method($methods)
{
    $methods[] = "PaymentMethodClassName";
    return $methods;
}

Class Implementation:

if (!class_exists('PaymentMethodClassName') && class_exists('CommonVars')) {
    class PaymentMethodClassName extends CommonVars
    {
        var $TestMode;
        var $GatewayUrl = "https://gatewaturl";
        var $GatewayUrl_TestMode = "https://sandbox.gatewayurl";        
        var $ReturnUrl;
        var $NotifyUrl;
        var $CancelUrl;         
        var $Enabled;       
        var $VarName;
        var $GatewayName = "Gateway Name";

        function __construct()
        {
                $this->TestMode = $TestMode;            
                $this->Enabled = get_wpdmpp_option('PaymentMethodClassName/enabled');
                $this->ReturnUrl = wpdmpp_orders_page();                
                $this->NotifyUrl = home_url('?action=wpdmpp-payment-notification&class=PaymentMethodClassName');
                $this->CancelUrl = wpdmpp_cart_page();
                $this->ParameterName = get_wpdmpp_option('PaymentMethodClassName/VariableName');
                $this->TestMode = get_wpdmpp_option('PaymentMethodClassName/Mode');
                if($this->TestMode=='1') $this->GatewayUrl = $this->GatewayUrl_TestMode;
                $this->Secret_word = get_wpdmpp_option('PaymentMethodClassName/secret_word');
                $this->Currency = wpdmpp_currency_code();
            }
          
        }


        function ConfigOptions()
        {

            $options = array(

                'Mode'=> array(
                    'label'         =>      __("Payment Gateway Mode:","text-domain"),
                    'type'          =>      'select',
                    'options'       =>      array('1'=>'Live','0'=>'Test'),
                    'selected'      =>      $this->TestMode
                ),
                'VarName'=> array(
                    'label'         =>      __("Text Label","text-domain"),
                    'type'          =>      'text',                    
                    'placeholder'   => '',
                    'value'         =>      $this->VarName
                )
// Add more variables as your payment gateway settings requires
                
            );

            return $options;


        }

        function ShowPaymentForm()
        {
            global $current_user;             
            $sbtn = "";
            $hide = "";
            if ($AutoSubmit == 1) $hide = "display:none;'";
            else $sbtn = "";
            $this->Amount = number_format($this->Amount, 2);
            $WPDM_2Checkout = plugins_url() . '/wpdm-premium-packages/images/WPDM_2Checkout.png';
            $Form = "
                    Payment Form / Code to redirect to payment gateway... 

        ";
            return $Form;


        }


        function VerifyNotification()
        {

         //IPN Code to verify payment and retun data true/false
          $valid = true;
           return $valid;
        }
    }
}


Leave a Reply