Plugin Directory

Changeset 2520555


Ignore:
Timestamp:
04/23/2021 06:20:13 PM (5 years ago)
Author:
marekgach
Message:

Add support for new success and error URLs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • axima-payment-gateway/trunk/src/Plugin.php

    r2473231 r2520555  
    2828
    2929        $checks = array(
    30             'Your Wordpress version is not compatible with Smartlook plugin which requires at least version 3.1. Please update your Wordpress or insert Smartlook chat code into your website manually (you will find the chat code in the email we have sent you upon registration)' => version_compare($wp_version, '3.1', '<'),
     30            'Your Wordpress version is not compatible with Pays plugin which requires at least version 3.1.)' => version_compare($wp_version, '3.1', '<'),
    3131            'This plugin requires at least PHP version 5.5.0, your version: ' . PHP_VERSION . '. Please ask your hosting company to bring your PHP version up to date.' => version_compare(PHP_VERSION, '5.5.0', '<'),
    3232            'You need WooCommerce plugin installed and activated to run this plugin.' => !in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')), TRUE),
     
    268268
    269269        add_action('plugins_loaded', function () use ($that) {
    270             $handler = array($that, 'confirmPayment');
    271             add_action('wp_ajax_nopriv_pays-confirmation', $handler);
    272             add_action('wp_ajax_pays-confirmation', $handler);
     270            $handlerConfirm = array($that, 'confirmPayment');
     271            $handlerSuccess = array($that, 'successPayment');
     272            $handlerError = array($that, 'errorPayment');
     273
     274            add_action('wp_ajax_nopriv_pays-confirmation', $handlerConfirm);
     275            add_action('wp_ajax_pays-confirmation', $handlerConfirm);
     276
     277            add_action('wp_ajax_nopriv_pays-success', $handlerSuccess);
     278            add_action('wp_ajax_pays-success', $handlerSuccess);
     279
     280            add_action('wp_ajax_nopriv_pays-error', $handlerError);
     281            add_action('wp_ajax_pays-error', $handlerError);
    273282
    274283            call_user_func(function () {
     
    283292    }
    284293
    285 
    286     public function confirmPayment()
     294    private function getOrderFromParams()
    287295    {
    288296        $get = function ($name, $default = NULL) {
     
    300308            wp_die('ERR: MerchantOrderNumber not in database', '', 400);
    301309        }
    302         $order = wc_get_order($item->order);
     310        return wc_get_order($item->order);
     311    }
     312
     313    public function confirmPayment()
     314    {
     315        $get = function ($name, $default = NULL) {
     316            return isset($_GET[$name]) ? $_GET[$name] : $default;
     317        };
     318
     319        $order = $this->getOrderFromParams();
    303320
    304321        $status = $get('PaymentOrderStatusID', 2);
     
    327344    }
    328345
     346    public function successPayment()
     347    {
     348        $order = $this->getOrderFromParams();
     349        wp_redirect($order->get_checkout_order_received_url());
     350        exit;
     351    }
     352
     353    public function errorPayment()
     354    {
     355        $order = $this->getOrderFromParams();
     356        wp_redirect($order->get_checkout_payment_url(false));
     357        exit;
     358    }
    329359
    330360    private function render($template, $vars = array())
Note: See TracChangeset for help on using the changeset viewer.