0

I am struggling making a woocommerce gateway for cofidis. This institution needs that I post via form a set of variables and after confirmation is made, it sends back, via get a set of variables informing if the operation was successful. So following the woocommerce documentation and google and stackoverflow, and many other sites, I am stucked. Here is my code:

function cofidis_init_gateway_class() {

    class WC_Cofidis_Gateway extends WC_Payment_Gateway {

        private $SUCCESS_CALLBACK_URL = "cofidis_payment_success";
        private $FAILURE_CALLBACK_URL = "cofidis_payment_failure";
        private $REJECTED_CALLBACK_URL = "cofidis_payment_rejected";
        private $CONFIRM_CALLBACK_URL = "cofidis_payment_confirm";
        private $SUCCESS_REDIRECT_URL = "/checkout/order-received/";
        private $FAILURE_REDIRECT_URL = "/checkout/order-received/";
        private $API_HOST = " ";
        private $API_SESSION_CREATE_ENDPOINT = "/checkout/v1/session/create";


        /**
         * Constructor for the gateway.
         */
        public function __construct() {

            $this->id                 = 'cofidis';
            $this->icon               = '';
            $this->has_fields         = true;
            $this->method_title       = 'Finance your shopping with cofidis';
            $this->method_description = 'Allows finnancing as a method of payment. Orders are marked as "on-hold" when received.';

            $this->supports = array('products');

            // Method with all the options fields.
            $this->init_form_fields();

            // Load the settings.
            $this->init_settings();
            $this->title = $this->get_option( 'title' );
            $this->description = $this->get_option( 'description' );
            $this->enabled = $this->get_option( 'enabled' );

            //Get the local server url
            $this->siteUrl = get_site_url();

            //Testmode property stores if we are in test mode or not.
            $this->testmode = 'yes' === $this->get_option( 'testmode' ); 

            //If we are in test mode we store test field values if not we store normal fields
            $this->url_cofidis = $this->testmode ? $this->get_option( 'test_url_cofidis' ) : $this->get_option( 'url_cofidis' );
            $this->vendor_code = $this->testmode ? $this->get_option( 'test_vendor_code' ) : $this->get_option( 'vendor_code' );
            $this->product_code = $this->testmode ? $this->get_option( 'test_product_code' ) : $this->get_option( 'product_code' );

            // We need custom JavaScript to obtain a token
            //add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );

            // Actions
            // This action hook saves the settings
            add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );

            //register the callback hooks which we will use to receive the payment response from the gateway.
            add_action( 'woocommerce_api_'. $this->SUCCESS_CALLBACK_URL, array( $this, 'payment_success'));
            add_action( 'woocommerce_api_' . $this->FAILURE_CALLBACK_URL, array( $this, 'payment_failure'));
            add_action ('woocommerce_api_' . $this->REJECTED_CALLBACK_URL, array( $this, 'payment_rejected'));
            add_action ('woocommerce_api_' . $this->CONFIRM_CALLBACK_URL, array( $this, 'payment_confirm'));    
        }



 private function payment_success($order_id) {
     //Do something
     var_dump($order_id)
    }

According to that, everytime I call 'url: mysite.com/wc-api/cofidis_payment_success, it should trigger the payment_success method, but I can't achive that instead I allways get a white page with -1. Is that I am understanding this wrong?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.