Plugin Directory

Changeset 3025245


Ignore:
Timestamp:
01/22/2024 03:45:00 PM (2 years ago)
Author:
revolutbusiness
Message:

Update plugin sources to version 4.9.6

Location:
revolut-gateway-for-woocommerce/trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • revolut-gateway-for-woocommerce/trunk/api/class-revolut-webhook-controller.php

    r2964057 r3025245  
    155155        $wc_order_status = empty( $wc_order->get_status() ) ? '' : $wc_order->get_status();
    156156        $check_wc_status = 'processing' === $wc_order_status || 'completed' === $wc_order_status;
    157         $check_capture   = isset( get_post_meta( $wc_order_id['wc_order_id'], 'revolut_capture' )[0] ) ? get_post_meta( $wc_order_id['wc_order_id'], 'revolut_capture' )[0] : '';
     157        $check_capture   = isset( $wc_order->get_meta( 'revolut_capture' )[0] ) ? $wc_order->get_meta( 'revolut_capture' )[0] : '';
    158158
    159159        $data = array();
     
    164164                    $wc_order->add_order_note( sprintf( __( 'Payment has been successfully captured (Order ID: %s)', 'revolut-gateway-for-woocommerce' ), $order_id ) );
    165165                    $wc_order->payment_complete( $order_id );
    166                     update_post_meta( $wc_order_id['wc_order_id'], 'revolut_capture', 'yes' );
     166                    $wc_order->update_meta_data( 'revolut_capture', 'yes', $wc_order_id['wc_order_id'] );
     167                    $wc_order->save();
    167168                    $data = array(
    168169                        'status'   => 'OK',
  • revolut-gateway-for-woocommerce/trunk/assets/js/revolut-payment-request.js

    r2974726 r3025245  
    1515
    1616    sendRequest(getAjaxURL('set_error_message'), {
     17      security: wc_revolut_payment_request_params.nonce.set_error_message,
    1718      revolut_payment_request_error: message,
    1819    })
     
    2930      getAjaxURL('log_error'),
    3031      {
     32        security: wc_revolut_payment_request_params.nonce.log_errors,
    3133        revolut_payment_request_error: message,
    3234      },
     
    250252    data['revolut_gateway'] = revolut_gateway
    251253    data['revolut_public_id'] = wc_revolut_payment_request_params.revolut_public_id
     254    data['security'] = wc_revolut_payment_request_params.nonce.process_payment_result
    252255    data['revolut_payment_error'] = errorMessage
    253256    data['wc_order_id'] = wc_order_id
     
    279282        payment_method: payment_method,
    280283        _wpnonce: wc_revolut_payment_request_params.nonce.checkout,
     284        security: wc_revolut_payment_request_params.nonce.create_order,
    281285        shipping_method: [orderSelectedShippingOption],
    282286        payment_request_type: paymentRequestType,
  • revolut-gateway-for-woocommerce/trunk/assets/js/revolut.js

    r2977523 r3025245  
    271271    let data = {}
    272272    data['revolut_gateway'] = currentPaymentMethod.methodId
     273    data['security'] = wc_revolut.nonce.process_payment_result
    273274    data['revolut_public_id'] = currentPaymentMethod.publicId
    274275    data['revolut_payment_error'] = errorMessage
  • revolut-gateway-for-woocommerce/trunk/gateway-revolut.php

    r2995266 r3025245  
    77 * Author URI: https://www.revolut.com/business/online-payments
    88 * Text Domain: revolut-gateway-for-woocommerce
    9  * Version: 4.9.5
     9 * Version: 4.9.6
    1010 * Requires at least: 4.4
    1111 * Tested up to: 6.1
     
    1616defined( 'ABSPATH' ) || exit;
    1717define( 'REVOLUT_PATH', plugin_dir_path( __FILE__ ) );
    18 define( 'WC_GATEWAY_REVOLUT_VERSION', '4.9.5' );
     18define( 'WC_GATEWAY_REVOLUT_VERSION', '4.9.6' );
    1919define( 'WC_GATEWAY_PUBLIC_KEY_ENDPOINT', '/public-key/latest' );
    2020define( 'WC_GATEWAY_REVPAY_INDEX', 'USE_REVOLUT_PAY_2_0' );
     
    5353    add_action( 'init', 'woocommerce_revolut_load_rest_api' );
    5454    add_action( 'wp_loaded', 'rest_api_includes' );
     55    add_action( 'before_woocommerce_init', 'declare_features_compatibility' );
    5556}
    5657
     
    6364}
    6465
     66/**
     67 * Declare compatibility with plugins and features.
     68 */
     69function declare_features_compatibility() {
     70    if ( class_exists( Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
     71        Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
     72    }
     73}
    6574/**
    6675 * Load API function
  • revolut-gateway-for-woocommerce/trunk/includes/abstract/class-wc-payment-gateway-revolut.php

    r2974726 r3025245  
    8484        $this->api_client = new WC_Revolut_API_Client( $this->api_settings );
    8585
     86        add_filter( 'query_vars', array( $this, 'revolut_plugin_public_query_vars' ) );
    8687        add_filter( 'wc_revolut_settings_nav_tabs', array( $this, 'admin_nav_tab' ) );
    8788        add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
     
    9899
    99100    /**
     101     * Init required query params
     102     *
     103     * @param array $qvars Query vars.
     104     */
     105    public function revolut_plugin_public_query_vars( $qvars ) {
     106        return array_merge( $qvars, array( 'key', 'pay_for_order', 'change_payment_method', '_rp_oid', '_rp_fr' ) );
     107    }
     108
     109    /**
    100110     * Validates if the WooCommerce order created successfully.
    101111     *
     
    107117     */
    108118    public function woocommerce_checkout_revolut_order_processed( $order_id, $posted_data, $order ) {
    109         if ( ! $this->check_is_post_data_submitted( 'revolut_create_wc_order' ) || $posted_data['payment_method'] !== $this->id ) {
     119        $nonce_value = wc_get_var( $_REQUEST['woocommerce-process-checkout-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // phpcs:ignore
     120        $revolut_create_wc_order = isset( $_POST['revolut_create_wc_order'] ) ? (bool) wc_clean( wp_unslash( $_POST['revolut_create_wc_order'] ) ) : false;
     121
     122        if ( ! wp_verify_nonce( $nonce_value, 'woocommerce-process_checkout' ) ) {
     123            wc_add_notice( __( 'Payment was not taken. Please try again', 'revolut-gateway-for-woocommerce' ), 'error' );
     124
     125            wp_send_json(
     126                array(
     127                    'refresh-checkout' => true,
     128                    'result'           => 'revolut_wc_order_created',
     129                )
     130            );
    110131            return;
    111132        }
    112133
     134        if ( ! $revolut_create_wc_order || $posted_data['payment_method'] !== $this->id ) {
     135            return;
     136        }
     137
    113138        try {
    114             $billing_phone       = $this->get_post_request_data( 'billing_phone' );
    115             $billing_email       = $this->get_post_request_data( 'billing_email' );
     139            $billing_phone = isset( $_POST['billing_phone'] ) ? wc_clean( wp_unslash( $_POST['billing_phone'] ) ) : '';
     140            $billing_email = isset( $_POST['billing_email'] ) ? wc_clean( wp_unslash( $_POST['billing_email'] ) ) : '';
     141
    116142            $revolut_customer_id = $this->get_or_create_revolut_customer( $billing_phone, $billing_email );
    117143            $this->update_revolut_customer( $revolut_customer_id, $billing_phone );
     
    122148        WC()->session->set( 'order_awaiting_payment', $order_id );
    123149
    124         $order_total            = $order->get_total();
    125         $order_currency         = $order->get_currency();
    126         $public_id              = $this->get_post_request_data( 'revolut_public_id' );
    127         $is_express_checkout    = (bool) $this->get_post_request_data( 'is_express_checkout' );
    128         $revolut_pay_redirected = (bool) $this->get_post_request_data( 'revolut_pay_redirected' );
     150        $order_total    = $order->get_total();
     151        $order_currency = $order->get_currency();
     152
     153        $public_id              = isset( $_POST['revolut_public_id'] ) ? wc_clean( wp_unslash( $_POST['revolut_public_id'] ) ) : '';
     154        $is_express_checkout    = isset( $_POST['is_express_checkout'] ) ? (bool) wc_clean( wp_unslash( $_POST['is_express_checkout'] ) ) : false;
     155        $revolut_pay_redirected = isset( $_POST['revolut_pay_redirected'] ) ? (bool) wc_clean( wp_unslash( $_POST['revolut_pay_redirected'] ) ) : false;
    129156
    130157        if ( ! $is_express_checkout ) {
     
    153180        $revolut_order_id = $this->get_revolut_order_by_public_id( $public_id );
    154181        $this->save_wc_order_id( $public_id, $revolut_order_id, $order_id );
     182
     183        $wc_order = wc_get_order( $order_id );
     184        $order->update_meta_data( 'revolut_payment_public_id', $public_id );
     185        $order->save();
     186
    155187        if ( ! $revolut_pay_redirected ) {
    156188            wp_send_json(
     
    162194            );
    163195        }
     196
     197        $order->update_meta_data( 'revolut_pay_redirected', 1 );
     198        $order->save();
    164199    }
    165200
     
    281316                'promotion_banner_html' => $this->get_upsell_banner_html(),
    282317                'nonce'                 => array(
    283                     'billing_info'        => wp_create_nonce( 'wc-revolut-get-billing-info' ),
    284                     'customer_info'       => wp_create_nonce( 'wc-revolut-get-customer-info' ),
    285                     'get_order_public_id' => wp_create_nonce( 'wc-revolut-get-order-public-id' ),
     318                    'process_payment_result' => wp_create_nonce( 'wc-revolut-process-payment-result' ),
     319                    'billing_info'           => wp_create_nonce( 'wc-revolut-get-billing-info' ),
     320                    'customer_info'          => wp_create_nonce( 'wc-revolut-get-customer-info' ),
     321                    'get_order_public_id'    => wp_create_nonce( 'wc-revolut-get-order-public-id' ),
    286322                ),
    287323            )
     
    402438     */
    403439    public function save_payment_method_requested() {
    404         return false;
    405     }
    406 
    407     /**
    408      * Check if saved payment method requested for making the payment.
    409      *
    410      * @abstract
    411      *
    412      * @return bool
    413      */
    414     public function is_using_saved_payment_method() {
    415440        return false;
    416441    }
     
    514539    public function add_payment_method() {
    515540        try {
     541            check_ajax_referer( 'woocommerce-add-payment-method', 'woocommerce-add-payment-method-nonce' );
     542
    516543            // find public_id.
    517             $revolut_payment_public_id = $this->get_post_request_data( 'revolut_public_id' );
     544            $revolut_payment_public_id               = isset( $_POST['revolut_public_id'] ) ? wc_clean( wp_unslash( $_POST['revolut_public_id'] ) ) : '';
     545            $update_all_subscriptions_payment_method = isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) || isset( $_POST['update_all_subscriptions_payment_method'] );
     546
    518547            if ( empty( $revolut_payment_public_id ) ) {
    519548                throw new Exception( 'Missing revolut_public_id parameter' );
     
    531560            }
    532561
    533             $this->handle_add_payment_method( null, $wc_token, get_current_user_id() );
     562            $this->handle_add_payment_method( null, $wc_token, get_current_user_id(), $update_all_subscriptions_payment_method );
    534563
    535564            return array(
     
    549578     * Process the payment and return the result.
    550579     *
    551      * @param int $wc_order_id WooCommerce order id.
     580     * @param int    $wc_order_id WooCommerce order id.
     581     * @param string $revolut_payment_public_id Revolut payment public id.
     582     * @param bool   $is_express_checkout Express checkout identifier.
     583     * @param string $revolut_payment_error Payment error.
     584     * @param bool   $reload_checkout Indicates if the page should reloaded.
     585     * @param bool   $revolut_pay_redirected Indicates Revolut Pay webflow redirection.
     586     * @param bool   $is_using_saved_payment_method Indicates payments by payment token.
     587     * @param bool   $save_payment_method_requested Indicates if payment token should be saved.
     588     * @param int    $wc_token_id WooCommerce token id.
    552589     *
    553590     * @return array
     
    555592     * @throws Exception Exception.
    556593     */
    557     public function process_payment( $wc_order_id ) {
     594    public function process_payment(
     595                        $wc_order_id,
     596                        $revolut_payment_public_id = '',
     597                        $is_express_checkout = false,
     598                        $revolut_payment_error = '',
     599                        $reload_checkout = false,
     600                        $revolut_pay_redirected = false,
     601                        $is_using_saved_payment_method = false,
     602                        $save_payment_method_requested = false,
     603                        $wc_token_id = 0 ) {
    558604        $wc_order = wc_get_order( $wc_order_id );
    559605
    560606        try {
    561             // find public_id.
    562             $is_express_checkout       = (bool) $this->get_posted_integer_data( 'is_express_checkout' );
    563             $revolut_payment_public_id = $this->get_post_request_data( 'revolut_public_id' );
     607            if ( empty( $revolut_payment_public_id ) ) {
     608                $revolut_payment_public_id = $wc_order->get_meta( 'revolut_payment_public_id' );
     609                $revolut_pay_redirected    = (int) $wc_order->get_meta( 'revolut_pay_redirected' );
     610                $this->log_error( 'Get public id from order: ' . $revolut_payment_public_id . ' - revolut_pay_redirected: ' . $revolut_pay_redirected );
     611            }
     612
    564613            if ( empty( $revolut_payment_public_id ) ) {
    565614                throw new Exception( 'Missing revolut_public_id parameter' );
    566615            }
    567616
    568             $revolut_payment_error = $this->get_post_request_data( 'revolut_payment_error' );
    569 
    570617            if ( empty( $revolut_payment_error ) ) {
    571                 $revolut_payment_error = $this->get_request_data( '_rp_fr' );
     618                $revolut_payment_error = get_query_var( '_rp_fr' );
    572619            }
    573620
     
    588635
    589636            // check if it needs to process payment with previously saved method.
    590             $previously_saved_wc_token = $this->maybe_pay_by_saved_method( $revolut_order_id );
     637            $previously_saved_wc_token = $this->maybe_pay_by_saved_method( $revolut_order_id, $is_using_saved_payment_method, $wc_token_id );
    591638
    592639            $this->save_wc_order_id( $revolut_payment_public_id, $revolut_order_id, $wc_order_id );
     
    601648            $this->handle_revolut_order_result( $wc_order, $revolut_order_id );
    602649            // check save method requested.
    603             $newly_saved_wc_token = $this->maybe_save_payment_method( $revolut_order_id, $wc_order );
     650            $newly_saved_wc_token = $this->maybe_save_payment_method( $revolut_order_id, $wc_order, $is_using_saved_payment_method, $save_payment_method_requested );
    604651            // check if there is any saved or used payment token.
    605652            $wc_token = null;
     
    610657            }
    611658
    612             update_post_meta( $wc_order_id, 'revolut_payment_public_id', $revolut_payment_public_id );
    613659            $this->save_payment_token_to_order( $wc_order, $wc_token, get_current_user_id() );
    614660            $this->verify_order_total( $revolut_order_id, $wc_order );
    615661            $this->update_payment_method_title( $revolut_order_id, $wc_order );
    616662
    617             return $this->checkout_return( $wc_order, $revolut_order_id );
     663            return $this->checkout_return( $wc_order, $revolut_order_id, $revolut_pay_redirected );
    618664        } catch ( Exception $e ) {
    619665            $this->log_error( $e->getMessage() );
     
    626672
    627673            // if page will be reloaded add the error message as notice, otherwise they're lost in the page reload.
    628             if ( $this->get_posted_integer_data( 'reload_checkout' ) || $this->get_posted_integer_data( 'revolut_pay_redirected' ) ) {
     674            if ( $reload_checkout || $revolut_pay_redirected ) {
    629675                unset( WC()->session->reload_checkout );
    630676                wc_add_notice( $error_message_for_user, 'error' );
     
    827873                if ( isset( $order['state'] ) && ! $check_wc_status ) {
    828874                    if ( 'COMPLETED' === $order['state'] && 'authorize_and_capture' === $mode ) {
    829                         update_post_meta( $wc_order_id, 'revolut_capture', 'yes' );
     875                        $wc_order->update_meta_data( 'revolut_capture', 'yes', $wc_order_id );
     876                        $wc_order->save();
    830877                        $wc_order->payment_complete( $revolut_order_id );
    831878                        $wc_order->add_order_note( 'Payment has been successfully captured (Order ID: ' . $revolut_order_id . ').' );
     
    893940        $revolut_customer_id  = $this->get_or_create_revolut_customer();
    894941        $descriptor           = new WC_Revolut_Order_Descriptor( WC()->cart->get_total( '' ), get_woocommerce_currency(), $revolut_customer_id );
    895         $display_tokenization = ! empty( $revolut_customer_id ) && $this->supports( 'tokenization' ) && ( is_checkout() || $this->get_request_data( 'pay_for_order' ) ) && $this->revolut_saved_cards;
     942        $display_tokenization = ! empty( $revolut_customer_id ) && $this->supports( 'tokenization' ) && ( is_checkout() || get_query_var( 'pay_for_order' ) ) && $this->revolut_saved_cards;
    896943
    897944        if ( $display_tokenization ) {
     
    10221069     *
    10231070     * @param string $revolut_order_id Revolut order id.
    1024      */
    1025     protected function maybe_pay_by_saved_method( $revolut_order_id ) {
    1026         if ( $this->is_using_saved_payment_method() ) {
    1027             $wc_token = $this->get_selected_payment_token();
     1071     * @param bool   $is_using_saved_payment_method Indicates payments by payment token.
     1072     * @param int    $wc_token_id WooCommerce token id.
     1073     */
     1074    protected function maybe_pay_by_saved_method( $revolut_order_id, $is_using_saved_payment_method, $wc_token_id ) {
     1075        if ( $is_using_saved_payment_method ) {
     1076            $wc_token = $this->get_selected_payment_token( $wc_token_id );
    10281077            return $this->pay_by_saved_method( $revolut_order_id, $wc_token );
    10291078        }
     
    10541103     * @param string   $revolut_order_id Revolut order id.
    10551104     * @param WC_Order $wc_order WooCommerce order.
    1056      */
    1057     protected function maybe_save_payment_method( $revolut_order_id, $wc_order ) {
    1058         if ( $this->save_payment_method_requested() && ! $this->is_using_saved_payment_method() ) {
     1105     * @param bool     $is_using_saved_payment_method Indicates payments by payment token.
     1106     * @param bool     $save_payment_method_requested Indicates if payment token should be saved.
     1107     */
     1108    protected function maybe_save_payment_method( $revolut_order_id, $wc_order, $is_using_saved_payment_method, $save_payment_method_requested ) {
     1109        if ( $save_payment_method_requested && ! $is_using_saved_payment_method ) {
    10591110            try {
    10601111                return $this->save_payment_method( $revolut_order_id );
     
    11031154            foreach ( $subscriptions as $subscription ) {
    11041155                $subscription_id = $subscription->get_id();
    1105                 update_post_meta( $subscription_id, '_payment_token', $wc_token->get_token() );
    1106                 update_post_meta( $subscription_id, '_payment_token_id', $id_payment_token );
    1107                 update_post_meta( $subscription_id, '_wc_customer_id', $wc_customer_id );
     1156                $subscription->update_meta_data( '_payment_token', $wc_token->get_token(), $subscription_id );
     1157                $subscription->update_meta_data( '_payment_token_id', $id_payment_token, $subscription_id );
     1158                $subscription->update_meta_data( '_wc_customer_id', $wc_customer_id, $subscription_id );
     1159                $subscription->save();
    11081160            }
    11091161        }
     
    11131165     * Updates all active subscriptions payment method.
    11141166     *
     1167     * @param  WC_Subscription $current_subscription WooCommerce Subscription.
     1168     * @param  object          $wc_token WooCommerce Payment Token.
     1169     * @param  int             $wc_customer_id WooCommerce Customer id.
     1170     * @param  bool            $update_all_subscriptions_payment_method Indicates if payment methods should be updated for all subscriptions.
     1171     * @return bool
     1172     */
     1173    public function handle_add_payment_method( $current_subscription, $wc_token, $wc_customer_id, $update_all_subscriptions_payment_method ) {
     1174        return false;
     1175    }
     1176
     1177    /**
     1178     * Grab selected payment token from Request
     1179     *
    11151180     * @abstract
    1116      *
    1117      * @param WC_Subscription $current_subscription WooCommerce Subscription.
    1118      * @param object          $wc_token WooCommerce Payment Token.
    1119      * @param int             $wc_customer_id WooCommerce Customer id.
    1120      * @return bool
    1121      */
    1122     public function handle_add_payment_method( $current_subscription, $wc_token, $wc_customer_id ) {
    1123         return false;
    1124     }
    1125 
    1126     /**
    1127      * Grab selected payment token from Request
    1128      *
    1129      * @abstract
    1130      *
     1181     * @param int $wc_token_id WooCommerce token id.
    11311182     * @return String
    11321183     */
    1133     public function get_selected_payment_token() {
     1184    public function get_selected_payment_token( $wc_token_id ) {
    11341185        return '';
    11351186    }
     
    11401191     * @param int    $wc_order WooCommerce order id.
    11411192     * @param String $revolut_order_id Revolut order id.
    1142      *
     1193     * @param bool   $revolut_pay_redirected Indicates Revolut Pay webflow redirection.
    11431194     * @return array
    11441195     */
    1145     public function checkout_return( $wc_order, $revolut_order_id ) {
     1196    public function checkout_return( $wc_order, $revolut_order_id, $revolut_pay_redirected ) {
    11461197        $this->clear_temp_session( $revolut_order_id );
    11471198        $this->unset_revolut_public_id();
     
    11511202        }
    11521203
    1153         if ( $this->get_posted_integer_data( 'revolut_pay_redirected' ) ) {
     1204        if ( $revolut_pay_redirected ) {
    11541205            wp_safe_redirect( $this->get_return_url( $wc_order ) );
    11551206            exit;
     
    12251276                    $wc_order->payment_complete( $revolut_order_id );
    12261277                    $wc_order->add_order_note( __( 'Payment amount has been captured successfully.', 'revolut-gateway-for-woocommerce' ) );
    1227                     update_post_meta( $order_id, 'revolut_capture', 'yes' );
     1278                    $wc_order->update_meta_data( 'revolut_capture', 'yes', $order_id );
     1279                    $wc_order->save();
    12281280                } else {
    12291281                    $wc_order->add_order_note( __( 'Order capture wasn\'t successful. Please try again or check your Revolut Business web portal for more information', 'revolut-gateway-for-woocommerce' ) );
  • revolut-gateway-for-woocommerce/trunk/includes/api/class-wc-revolut-api-client.php

    r2976441 r3025245  
    4747
    4848    /**
    49      * Merchant management Api urls
    50      *
    51      * @var array
    52      */
    53     public $mgmt_api_urls = array(
    54         'live'    => 'https://merchant-mgmt.revolut.com',
    55         'dev'     => 'https://merchant-mgmt.revolut.codes',
    56         'sandbox' => 'https://sandbox-merchant-mgmt.revolut.com',
    57     );
    58 
    59     /**
    6049     * Api mode live|sandbox|develop
    6150     *
     
    9180     */
    9281    public $api_url;
    93 
    94     /**
    95      * Public Api url
    96      *
    97      * @var string
    98      */
    99     public $mgmt_api_url;
    10082
    10183    /**
     
    128110
    129111        // switch to the new api if required.
    130         $this->api_url      = $new_api ? $this->base_url . '/api' : $this->base_url . '/api/1.0';
    131         $this->mgmt_api_url = $this->mgmt_api_urls[ $this->mode ];
     112        $this->api_url = $new_api ? $this->base_url . '/api' : $this->base_url . '/api/1.0';
    132113    }
    133114
     
    135116     * Send post to API.
    136117     *
    137      * @param String     $path Api path.
     118     * @param string     $path Api path.
    138119     * @param array|null $body Request body.
    139      * @param bool       $is_mgmt_endpoint Management API indicator.
     120     * @param bool       $public Public API indicator.
    140121     * @param bool       $new_api New API indicator.
    141122     *
     
    143124     * @throws Exception Exception.
    144125     */
    145     public function post( $path, $body = null, $is_mgmt_endpoint = false, $new_api = false ) {
    146         return $this->request( $path, 'POST', $body, $is_mgmt_endpoint, $new_api );
     126    public function post( $path, $body = null, $public = false, $new_api = false ) {
     127        return $this->request( $path, 'POST', $body, $public, $new_api );
    147128    }
    148129
     
    150131     * Send request to API
    151132     *
    152      * @param String     $path             Api path.
    153      * @param String     $method           Request method.
     133     * @param string     $path             Api path.
     134     * @param string     $method           Request method.
    154135     * @param array|null $body             Request body.
    155      * @param bool       $is_mgmt_api_endpoint Management API endpoint indicator.
     136     * @param bool       $public Public API indicator.
    156137     * @param bool       $new_api New API indicator.
    157      * @param bool       $is_mgmt_endpoint Management endpoint indicator.
    158      *
    159      * @return mixed
    160      * @throws Exception Exception.
    161      */
    162     private function request( $path, $method, $body = null, $is_mgmt_api_endpoint = false, $new_api = false, $is_mgmt_endpoint = false ) {
     138     * @return mixed
     139     * @throws Exception Exception.
     140     */
     141    private function request( $path, $method, $body = null, $public = false, $new_api = false ) {
    163142        global $wp_version;
    164143        global $woocommerce;
     
    169148
    170149        $api_key = $this->api_key;
    171 
    172         if ( $is_mgmt_api_endpoint && WC_GATEWAY_PUBLIC_KEY_ENDPOINT !== $path ) {
     150        $url     = $this->api_url . $path;
     151
     152        if ( $new_api ) {
     153            $url = $this->base_url . '/api' . $path;
     154        }
     155
     156        if ( $public ) {
    173157            $api_key = $this->public_key;
     158            $url     = $this->base_url . '/api/public' . $path;
    174159        }
    175160
     
    188173        }
    189174
    190         $url = $this->api_url . $path;
    191 
    192         if ( $new_api ) {
    193             $url = $this->base_url . '/api' . $path;
    194         }
    195 
    196         if ( $is_mgmt_api_endpoint ) {
    197             $url = $this->mgmt_api_url . '/api' . $path;
    198         }
    199 
    200         if ( $is_mgmt_endpoint ) {
    201             $url = $this->mgmt_api_url . $path;
    202         }
    203 
    204175        $response      = wp_remote_request( $url, $request );
    205176        $response_body = wp_remote_retrieve_body( $response );
     
    215186
    216187    /**
    217      * Send request to public API
    218      *
    219      * @param String     $path             Api path.
    220      * @param array      $headers          Request method.
    221      * @param String     $method           Request method.
    222      * @param array|null $body             Request body.
    223      *
    224      * @return mixed
    225      * @throws Exception Exception.
    226      */
    227     public function public_request( $path, $headers, $method = 'POST', $body = null ) {
    228         global $wp_version;
    229         global $woocommerce;
    230 
    231         $headers['User-Agent']   = 'Revolut Payment Gateway/' . WC_GATEWAY_REVOLUT_VERSION . ' WooCommerce/' . $woocommerce->version . ' Wordpress/' . $wp_version . ' PHP/' . PHP_VERSION;
    232         $headers['Content-Type'] = 'application/json';
    233 
    234         $request = array(
    235             'headers' => $headers,
    236             'method'  => $method,
    237         );
    238 
    239         if ( null !== $body ) {
    240             $request['body'] = wp_json_encode( $body );
    241         }
    242 
    243         $url = $this->mgmt_api_url . '/public/' . $path;
    244 
    245         $response      = wp_remote_request( $url, $request );
    246         $response_body = wp_remote_retrieve_body( $response );
    247 
    248         if ( wp_remote_retrieve_response_code( $response ) >= 400 && wp_remote_retrieve_response_code( $response ) < 500 && 'GET' !== $method ) {
    249             $this->log_error( "Failed request to URL $method $url" );
    250             $this->log_error( $response_body );
    251             throw new Exception( "Something went wrong: $method $url\n" . $response_body );
    252         }
    253 
    254         return json_decode( $response_body, true );
    255     }
    256 
    257     /**
    258188     * Send GET request to API
    259189     *
    260      * @param String $path Request path.
    261      * @param Boolean $is_mgmt_api Management API endpoint indicator.
    262      * @param Boolean $is_mgmt Management API indicator.
    263      *
    264      * @return mixed
    265      * @throws Exception Exception.
    266      */
    267     public function get( $path, $is_mgmt_api = false, $is_mgmt = false ) {
    268         return $this->request( $path, 'GET', null, $is_mgmt_api, false, $is_mgmt );
     190     * @param string $path Request path.
     191     * @param bool   $public Public API indicator.
     192     * @param bool   $new_api API version indicator.
     193     *
     194     * @return mixed
     195     * @throws Exception Exception.
     196     */
     197    public function get( $path, $public = false, $new_api = false ) {
     198        return $this->request( $path, 'GET', null, $public, $new_api );
    269199    }
    270200
     
    272202     * Revolut API patch
    273203     *
    274      * @param String     $path Request path.
     204     * @param string     $path Request path.
    275205     * @param array|null $body Request body.
    276206     *
     
    285215     * Revolut API delete
    286216     *
    287      * @param String $path Request path.
     217     * @param string $path Request path.
    288218     *
    289219     * @return mixed
     
    297227     * Set Revolut Merchant Public Key
    298228     *
    299      * @param String $public_key public key.
     229     * @param string $public_key public key.
    300230     *
    301231     * @return void
  • revolut-gateway-for-woocommerce/trunk/includes/class-wc-revolut-apple-pay-onboarding.php

    r2990122 r3025245  
    151151     */
    152152    public function admin_notices() {
    153         $page    = $this->get_request_data( 'page' );
    154         $section = $this->get_request_data( 'section' );
     153        $page    = isset( $_GET['page'] ) ? wc_clean( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore
     154        $section = isset( $_GET['section'] ) ? wc_clean( wp_unslash( $_GET['section'] ) ) : ''; // phpcs:ignore
    155155
    156156        if ( ! empty( $page ) && ! empty( $section ) ) {
     
    233233     */
    234234    public function maybe_onboard_apple_pay_merchant() {
    235         $action = $this->get_post_request_data( 'action' );
     235        $action = isset( $_POST['action'] ) ? wc_clean( wp_unslash( $_POST['action'] ) ) : ''; // phpcs:ignore
    236236
    237237        if ( ! empty( $action ) && 'wc_revolut_onboard_applepay_domain' === $action ) {
     
    380380        $this->success_messages[] = $message;
    381381    }
    382 
    383     /**
    384      * Safe get posted data
    385      *
    386      * @param string $post_key request key.
    387      */
    388     public function get_post_request_data( $post_key ) {
    389         if ( ! isset( $_POST[ $post_key ] ) ) { // phpcs:ignore
    390             return null;
    391         }
    392 
    393         return $this->recursive_sanitize_text_field( $_POST[ $post_key ]);  // phpcs:ignore
    394     }
    395 
    396     /**
    397      * Safe get request data
    398      *
    399      * @param string $get_key request key.
    400      */
    401     public function get_request_data( $get_key ) {
    402         if ( ! isset( $_GET[ $get_key ] ) ) { // phpcs:ignore
    403             return null;
    404         }
    405 
    406         return $this->recursive_sanitize_text_field( $_GET[ $get_key ] ); // phpcs:ignore
    407     }
    408 
    409     /**
    410      * Clear data.
    411      *
    412      * @param mixed $var data for cleaning.
    413      */
    414     public function recursive_sanitize_text_field( $var ) {
    415         if ( is_array( $var ) ) {
    416             return array_map( array( $this, 'recursive_sanitize_text_field' ), $var );
    417         } else {
    418             return sanitize_text_field( wp_unslash( $var ) );
    419         }
    420     }
    421382}
  • revolut-gateway-for-woocommerce/trunk/includes/class-wc-revolut-order-descriptor.php

    r2891412 r3025245  
    4545     */
    4646    public function __construct( $amount, $currency, $revolut_customer_id ) {
    47         if ( $this->check_is_get_data_submitted( 'pay_for_order' ) && ! empty( $this->get_request_data( 'key' ) ) ) {
     47        if ( (bool) get_query_var( 'pay_for_order' ) && ! empty( get_query_var( 'key' ) ) ) {
    4848            global $wp;
    4949            $order  = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) );
  • revolut-gateway-for-woocommerce/trunk/includes/class-wc-revolut-payment-ajax-controller.php

    r2956658 r3025245  
    4242        add_action( 'wc_ajax_revolut_payment_request_set_error_message', array( $this, 'revolut_payment_request_ajax_set_error_message' ) );
    4343        add_action( 'wc_ajax_revolut_payment_request_log_error', array( $this, 'revolut_payment_request_ajax_log_error' ) );
    44         add_action( 'wc_ajax_revolut_payment_request_log_error', array( $this, 'revolut_payment_request_ajax_log_error' ) );
    4544
    4645        if ( is_admin() ) {
    47             add_action( 'wp_ajax_wc_revolut_set_webhook', array( $this, 'wc_revolut_set_webhook' ) );
    4846            add_action( 'wp_ajax_wc_revolut_clear_records', array( $this, 'wc_revolut_clear_records' ) );
    49             add_action(
    50                 'wp_ajax_wc_revolut_onboard_applepay_domain',
    51                 array( $this, 'wc_revolut_onboard_applepay_domain' )
    52             );
    53         }
    54 
     47            add_action( 'wp_ajax_wc_revolut_onboard_applepay_domain', array( $this, 'wc_revolut_onboard_applepay_domain' ) );
     48        }
    5549    }
    5650
     
    6155     */
    6256    public function wc_revolut_process_payment_result() {
    63         try {
    64             $wc_order_id      = $this->get_posted_integer_data( 'wc_order_id' );
    65             $selected_gateway = $this->get_post_request_data( 'revolut_gateway' );
    66 
    67             if ( empty( $wc_order_id ) || empty( $selected_gateway ) || empty( $this->get_post_request_data( 'revolut_public_id' ) ) ) {
     57        check_ajax_referer( 'wc-revolut-process-payment-result', 'security' );
     58
     59        try {
     60            $wc_order_id                   = isset( $_POST['wc_order_id'] ) ? (int) wc_clean( wp_unslash( $_POST['wc_order_id'] ) ) : 0;
     61            $selected_gateway              = isset( $_POST['revolut_gateway'] ) ? wc_clean( wp_unslash( $_POST['revolut_gateway'] ) ) : '';
     62            $is_express_checkout           = isset( $_POST['is_express_checkout'] ) ? (bool) wc_clean( wp_unslash( $_POST['is_express_checkout'] ) ) : false;
     63            $reload_checkout               = isset( $_POST['reload_checkout'] ) ? (bool) wc_clean( wp_unslash( $_POST['reload_checkout'] ) ) : false;
     64            $revolut_payment_public_id     = isset( $_POST['revolut_public_id'] ) ? wc_clean( wp_unslash( $_POST['revolut_public_id'] ) ) : '';
     65            $revolut_payment_error         = isset( $_POST['revolut_payment_error'] ) ? wc_clean( wp_unslash( $_POST['revolut_payment_error'] ) ) : '';
     66            $wc_payment_token_id           = isset( $_POST[ 'wc-' . WC_Gateway_Revolut_CC::GATEWAY_ID . '-payment-token' ] ) ? wc_clean( wp_unslash( $_POST[ 'wc-' . WC_Gateway_Revolut_CC::GATEWAY_ID . '-payment-token' ] ) ) : '';
     67            $save_payment_method_requested = isset( $_POST['revolut_save_payment_method'] ) ? (bool) wc_clean( wp_unslash( $_POST['revolut_save_payment_method'] ) ) : false;
     68            $is_using_saved_payment_method = ! empty( $wc_payment_token_id ) && 'new' !== $wc_payment_token_id;
     69
     70            if ( empty( $wc_order_id ) || empty( $selected_gateway ) || empty( $revolut_payment_public_id ) ) {
    6871                $this->log_error(
    6972                    array(
    7073                        'wc_order_id'       => $wc_order_id,
    7174                        'selected_gateway'  => $selected_gateway,
    72                         'revolut_public_id' => $this->get_post_request_data( 'revolut_public_id' ),
     75                        'revolut_public_id' => $revolut_payment_public_id,
    7376                    )
    7477                );
    75 
    76                 $revolut_payment_error = $this->get_post_request_data( 'revolut_payment_error' );
    7778
    7879                if ( empty( $revolut_payment_error ) ) {
     
    9091            }
    9192
    92             $result = $revolut_gateway->process_payment( $wc_order_id );
    93 
     93            $result = $revolut_gateway->process_payment(
     94                $wc_order_id,
     95                $revolut_payment_public_id,
     96                $is_express_checkout,
     97                $revolut_payment_error,
     98                $reload_checkout,
     99                false,
     100                $is_using_saved_payment_method,
     101                $save_payment_method_requested,
     102                $wc_payment_token_id
     103            );
    94104        } catch ( Exception $e ) {
    95105            $result = array(
     
    111121
    112122        wp_send_json( $result );
    113     }
    114 
    115     /**
    116      * Setup webhook
    117      *
    118      * @throws Exception Exception.
    119      */
    120     public function wc_revolut_set_webhook() {
    121         try {
    122             if ( $this->check_is_post_data_submitted( 'apiKey' ) || empty( $this->get_post_request_data( 'apiKey' ) ) ) {
    123                 wp_die( false );
    124             }
    125 
    126             if ( ! $this->check_is_post_data_submitted( 'mode' ) || empty( $this->get_post_request_data( 'mode' ) ) ) {
    127                 wp_die( false );
    128             }
    129 
    130             $web_hook_url = get_site_url( null, '/wp-json/wc/v3/revolut', 'https' );
    131 
    132             $body = array(
    133                 'url'    => $web_hook_url,
    134                 'events' => array(
    135                     'ORDER_COMPLETED',
    136                     'ORDER_AUTHORISED',
    137                 ),
    138             );
    139 
    140             $mode = $this->get_post_request_data( 'mode' );
    141 
    142             if ( 'live' === $mode ) {
    143                 $this->api_client->api_url = $this->api_client->api_url_live;
    144             } elseif ( 'sandbox' === $mode ) {
    145                 $this->api_client->api_url = $this->api_client->api_url_sandbox;
    146             } elseif ( 'dev' === $mode ) {
    147                 $this->api_client->api_url = $this->api_client->api_url_dev;
    148             }
    149 
    150             $this->api_client->api_url .= '/api/1.0';
    151             $this->api_client->api_key  = $this->get_post_request_data( 'apiKey' );
    152 
    153             $web_hook_url_list = $this->api_client->get( '/webhooks' );
    154             if ( ! empty( $web_hook_url_list ) ) {
    155                 $web_hook_url_list = array_column( $web_hook_url_list, 'url' );
    156 
    157                 if ( in_array( $web_hook_url, $web_hook_url_list, true ) ) {
    158                     wp_send_json(
    159                         array(
    160                             'success' => true,
    161                         )
    162                     );
    163                 }
    164             }
    165 
    166             $response = $this->api_client->post( '/webhooks', $body );
    167 
    168             if ( isset( $response['id'] ) && ! empty( $response['id'] ) ) {
    169                 wp_send_json(
    170                     array(
    171                         'success' => true,
    172                     )
    173                 );
    174             }
    175         } catch ( Exception $e ) {
    176             $this->log_error( $e->getMessage() );
    177             wp_send_json(
    178                 array(
    179                     'success' => false,
    180                     'message' => $e->getMessage(),
    181                 )
    182             );
    183         }
    184 
    185         wp_send_json(
    186             array(
    187                 'success' => true,
    188             )
    189         );
    190123    }
    191124
     
    328261    public function wc_revolut_validate_order_pay_form() {
    329262        try {
    330             $nonce_value = wc_get_var( $this->get_post_request_data( 'woocommerce-pay-nonce' ), $this->get_post_request_data( '_wpnonce' ) );
     263            $nonce_value = wc_get_var( $_REQUEST['woocommerce-pay-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // phpcs:ignore
    331264
    332265            if ( ! wp_verify_nonce( $nonce_value, 'woocommerce-pay' ) ) {
     
    334267            }
    335268
    336             $order_key = $this->get_post_request_data( 'wc_order_key' );
    337             $order_id  = $this->get_posted_integer_data( 'wc_order_id' );
    338             $order     = wc_get_order( $order_id );
     269            $order_id    = isset( $_POST['wc_order_id'] ) ? (int) wc_clean( wp_unslash( $_POST['wc_order_id'] ) ) : 0;
     270            $terms_field = isset( $_POST['terms-field'] ) ? (int) wc_clean( wp_unslash( $_POST['terms-field'] ) ) : 0;
     271            $order_key   = isset( $_POST['wc_order_key'] ) ? wc_clean( wp_unslash( $_POST['wc_order_key'] ) ) : '';
     272            $terms       = isset( $_POST['terms'] ) ? wc_clean( wp_unslash( $_POST['terms'] ) ) : '';
     273            $order       = wc_get_order( $order_id );
    339274
    340275            if ( $order_id === $order->get_id() && hash_equals( $order->get_order_key(), $order_key ) && $order->needs_payment() ) {
    341276                do_action( 'woocommerce_before_pay_action', $order );
    342                 if ( ! empty( $this->get_posted_integer_data( 'terms-field' ) && empty( $this->get_post_request_data( 'terms' ) ) ) ) {
     277                if ( ! empty( $terms_field ) && empty( $terms ) ) {
    343278                    throw new Exception( __( 'Please read and accept the terms and conditions to proceed with your order.', 'woocommerce' ) );
    344279                }
     
    372307        check_ajax_referer( 'wc-revolut-get-billing-info', 'security' );
    373308
    374         $order_id  = $this->get_posted_integer_data( 'order_id' );
    375         $order_key = $this->get_post_request_data( 'order_key' );
    376         $order     = wc_get_order( $order_id );
     309        $order_id  = isset( $_POST['order_id'] ) ? (int) wc_clean( wp_unslash( $_POST['order_id'] ) ) : 0;
     310        $order_key = isset( $_POST['order_key'] ) ? wc_clean( wp_unslash( $_POST['order_key'] ) ) : '';
     311
     312        $order = wc_get_order( $order_id );
    377313        // validate order key.
    378314        if ( $order && $order_key === $order->get_order_key() ) {
     
    428364    public function revolut_payment_request_ajax_cancel_order() {
    429365        check_ajax_referer( 'wc-revolut-cancel-order', 'security' );
    430         $revolut_public_id = $this->get_post_request_data( 'revolut_public_id' );
    431         $revolut_order_id  = $this->get_revolut_order_by_public_id( $revolut_public_id );
     366        $revolut_public_id = isset( $_POST['revolut_public_id'] ) ? wc_clean( wp_unslash( $_POST['revolut_public_id'] ) ) : '';
     367
     368        $revolut_order_id = $this->get_revolut_order_by_public_id( $revolut_public_id );
    432369
    433370        try {
     
    453390     */
    454391    public function revolut_payment_request_ajax_set_error_message() {
    455         $error_message = $this->get_post_request_data( 'revolut_payment_request_error' );
     392        check_ajax_referer( 'wc-revolut-set-error-message', 'security' );
     393        $error_message = isset( $_POST['revolut_payment_request_error'] ) ? wc_clean( wp_unslash( $_POST['revolut_payment_request_error'] ) ) : '';
    456394
    457395        if ( empty( $error_message ) ) {
     
    466404     */
    467405    public function revolut_payment_request_ajax_log_error() {
    468         $error_message = $this->get_post_request_data( 'revolut_payment_request_error' );
     406        check_ajax_referer( 'wc-revolut-log-errors', 'security' );
     407        $error_message = isset( $_POST['revolut_payment_request_error'] ) ? wc_clean( wp_unslash( $_POST['revolut_payment_request_error'] ) ) : '';
    469408        $this->log_error( $error_message );
    470409    }
  • revolut-gateway-for-woocommerce/trunk/includes/class-wc-revolut-privacy.php

    r2680985 r3025245  
    9797        if ( 0 < count( $orders ) ) {
    9898            foreach ( $orders as $order ) {
     99                $wc_order         = $this->wc_get_order( $order->get_id() );
    99100                $data_to_export[] = array(
    100101                    'group_id'    => 'woocommerce_orders',
     
    104105                        array(
    105106                            'name'  => __( 'Revolut token', 'revolut-gateway-for-woocommerce' ),
    106                             'value' => get_post_meta( $order->get_id(), '_revolut_pre_order_token', true ),
     107                            'value' => $wc_order->get_meta( '_revolut_pre_order_token', true ),
    107108                        ),
    108109                    ),
     
    157158     * Handle eraser of data tied to Orders
    158159     *
    159      * @param WC_Order $order WooCommerce Order.
     160     * @param WC_Order $wc_order WooCommerce Order.
    160161     *
    161162     * @return array
    162163     */
    163     protected function maybe_handle_order( $order ) {
    164         $order_id      = $order->get_id();
    165         $revolut_token = get_post_meta( $order_id, '_revolut_pre_order_token', true );
     164    protected function maybe_handle_order( $wc_order ) {
     165        $order_id      = $wc_order->get_id();
     166        $revolut_token = $wc_order->get_meta( '_revolut_pre_order_token', true );
    166167
    167168        if ( empty( $revolut_token ) ) {
     
    169170        }
    170171
    171         delete_post_meta( $order_id, '_revolut_pre_order_token' );
     172        $wc_order->delete_meta_data( '_revolut_pre_order_token' );
    172173
    173174        return array( true, false, array( __( 'Revolut Order Data Erased.', 'revolut-gateway-for-woocommerce' ) ) );
  • revolut-gateway-for-woocommerce/trunk/includes/gateways/class-wc-gateway-revolut-cc.php

    r2976441 r3025245  
    257257     * Process the payment and return the result.
    258258     *
    259      * @param int $wc_order_id WooCommerce Order order id.
     259     * @param int    $wc_order_id WooCommerce order id.
     260     * @param string $revolut_payment_public_id Revolut payment public id.
     261     * @param bool   $is_express_checkout Express checkout identifier.
     262     * @param string $revolut_payment_error Payment error.
     263     * @param bool   $reload_checkout Indicates if the page should reloaded.
     264     * @param bool   $revolut_pay_redirected Indicates Revolut Pay webflow redirection.
     265     * @param bool   $is_using_saved_payment_method Indicates payments by payment token.
     266     * @param bool   $save_payment_method_requested Indicates if payment token should be saved.
     267     * @param int    $wc_token_id WooCommerce token id.
    260268     *
    261269     * @throws Exception Exception.
    262270     */
    263     public function process_payment( $wc_order_id ) {
     271    public function process_payment( $wc_order_id, $revolut_payment_public_id = '', $is_express_checkout = false, $revolut_payment_error = '', $reload_checkout = false, $revolut_pay_redirected = false, $is_using_saved_payment_method = false, $save_payment_method_requested = false, $wc_token_id = 0 ) {
    264272        if ( $this->has_subscription( $wc_order_id ) ) {
    265             if ( $this->is_subs_change_payment() ) {
    266                 return $this->change_subs_payment_method( $wc_order_id );
    267             }
    268 
    269             // Regular payment with force customer enabled.
    270             return parent::process_payment( $wc_order_id );
    271         } else {
    272             return parent::process_payment( $wc_order_id );
    273         }
     273            if ( isset( $_POST['_wcsnonce'] ) && wp_verify_nonce( wc_clean( wp_unslash( $_POST['_wcsnonce'] ) ), 'wcs_change_payment_method' ) ) {
     274                if ( isset( $_POST['woocommerce_change_payment'] ) ) {
     275                    return $this->change_subs_payment_method( $wc_order_id );
     276                }
     277            }
     278        }
     279
     280        return parent::process_payment( $wc_order_id, $revolut_payment_public_id, $is_express_checkout, $revolut_payment_error, $reload_checkout, $revolut_pay_redirected, $is_using_saved_payment_method, $save_payment_method_requested, $wc_token_id );
    274281    }
    275282
     
    304311    public function change_subs_payment_method( $wc_order_id ) {
    305312        try {
    306             $subscription              = wc_get_order( $wc_order_id );
    307             $revolut_payment_public_id = $this->get_post_request_data( 'revolut_public_id' );
     313            if ( ! isset( $_POST['_wcsnonce'] ) || ! wp_verify_nonce( wc_clean( wp_unslash( $_POST['_wcsnonce'] ) ), 'wcs_change_payment_method' ) ) {
     314                return;
     315            }
     316
     317            $subscription = wc_get_order( $wc_order_id );
     318
     319            $revolut_payment_public_id               = isset( $_POST['revolut_public_id'] ) ? wc_clean( wp_unslash( $_POST['revolut_public_id'] ) ) : '';
     320            $wc_payment_token_id                     = isset( $_POST[ 'wc-' . $this->id . '-payment-token' ] ) ? wc_clean( wp_unslash( $_POST[ 'wc-' . $this->id . '-payment-token' ] ) ) : '';
     321            $is_using_saved_payment_method           = ! empty( $wc_payment_token_id ) && 'new' !== $wc_payment_token_id;
     322            $update_all_subscriptions_payment_method = isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) || isset( $_POST['update_all_subscriptions_payment_method'] );
    308323
    309324            if ( empty( $revolut_payment_public_id ) ) {
     
    318333            }
    319334
    320             if ( $this->is_using_saved_payment_method() ) {
    321                 $wc_token = $this->get_selected_payment_token();
     335            if ( $is_using_saved_payment_method ) {
     336                $wc_token = $this->get_selected_payment_token( $wc_payment_token_id );
    322337            } else {
    323338                $wc_token = $this->save_payment_method( $revolut_order_id );
     
    328343
    329344            $this->save_payment_token_to_order( $subscription, $wc_token, get_current_user_id() );
    330             $this->handle_add_payment_method( $subscription, $wc_token, get_current_user_id() );
     345            $this->handle_add_payment_method( $subscription, $wc_token, get_current_user_id(), $update_all_subscriptions_payment_method );
    331346
    332347            return array(
     
    345360     * Updates all active subscriptions payment method.
    346361     *
    347      * @param WC_Subscription $current_subscription WooCommerce Subscription.
    348      * @param object          $wc_token WooCommerce Payment Token.
    349      * @param int             $wc_customer_id WooCommerce Customer id.
     362     * @param  WC_Subscription $current_subscription WooCommerce Subscription.
     363     * @param  object          $wc_token WooCommerce Payment Token.
     364     * @param  int             $wc_customer_id WooCommerce Customer id.
     365     * @param  bool            $update_all_subscriptions_payment_method Indicates if payment methods should be updated for all subscriptions.
    350366     * @return bool
    351367     */
    352     public function handle_add_payment_method( $current_subscription, $wc_token, $wc_customer_id ) {
     368    public function handle_add_payment_method( $current_subscription, $wc_token, $wc_customer_id, $update_all_subscriptions_payment_method ) {
    353369        // remove public ID after saving the card.
    354370        $this->unset_revolut_public_id();
    355371
    356         if ( $this->update_all_subscriptions_payment_method() ) {
     372        if ( $update_all_subscriptions_payment_method ) {
    357373            $all_subs = wcs_get_users_subscriptions();
    358374
     
    416432     */
    417433    public function delete_resubscribe_meta( $resubscribe_order ) {
    418         delete_post_meta( $resubscribe_order->get_id(), '_payment_token' );
    419         delete_post_meta( $resubscribe_order->get_id(), '_payment_token_id' );
    420         delete_post_meta( $resubscribe_order->get_id(), '_wc_customer_id' );
     434        $resubscribe_order->delete_meta_data( $resubscribe_order->get_id(), '_payment_token' );
     435        $resubscribe_order->delete_meta_data( $resubscribe_order->get_id(), '_payment_token_id' );
     436        $resubscribe_order->delete_meta_data( $resubscribe_order->get_id(), '_wc_customer_id' );
    421437    }
    422438
     
    457473     */
    458474    public function update_failing_payment_method( $subscription, $renewal_order ) {
    459         update_post_meta( $subscription->get_id(), '_payment_token', $renewal_order->get_meta( '_payment_token' ) );
    460         update_post_meta( $subscription->get_id(), '_payment_token_id', $renewal_order->get_meta( '_payment_token_id' ) );
    461         update_post_meta( $subscription->get_id(), '_wc_customer_id', $renewal_order->get_meta( '_wc_customer_id' ) );
     475        $subscription->update_meta_data( '_payment_token', $renewal_order->get_meta( '_payment_token' ), $subscription->get_id() );
     476        $subscription->update_meta_data( '_payment_token_id', $renewal_order->get_meta( '_payment_token_id' ), $subscription->get_id() );
     477        $subscription->update_meta_data( '_wc_customer_id', $renewal_order->get_meta( '_wc_customer_id' ), $subscription->get_id() );
     478        $subscription->save();
    462479    }
    463480
     
    471488    public function update_changed_subscription_token( $subscription, $new_token ) {
    472489        if ( $new_token->get_gateway_id() === $this->id ) {
    473             update_post_meta( $subscription->get_id(), '_payment_token', $new_token->get_token() );
    474             update_post_meta( $subscription->get_id(), '_payment_token_id', $new_token->get_id() );
     490            $subscription_id = $subscription->get_id();
     491            $subscription->update_meta_data( '_payment_token', $new_token->get_token(), $subscription_id );
     492            $subscription->update_meta_data( '_payment_token_id', $new_token->get_id(), $subscription_id );
     493            $subscription->save();
    475494        }
    476495    }
     
    489508
    490509    /**
    491      * Update all subscriptions payment methods
    492      *
    493      * @return bool
    494      */
    495     public function update_all_subscriptions_payment_method() {
    496         return $this->check_is_post_data_submitted( 'wc-' . $this->id . '-update-subs-payment-method-card' ) || $this->check_is_post_data_submitted( 'update_all_subscriptions_payment_method' );
    497     }
    498 
    499     /**
    500      * Check if it is using saved payment method
    501      *
    502      * @return bool
    503      */
    504     public function is_using_saved_payment_method() {
    505         return ( $this->check_is_post_data_submitted( 'wc-' . $this->id . '-payment-token' ) && ! empty( $this->get_post_request_data( 'wc-' . $this->id . '-payment-token' ) && 'new' !== $this->get_post_request_data( 'wc-' . $this->id . '-payment-token' ) ) );
    506     }
    507 
    508     /**
    509510     * Grab selected payment token from Request
    510511     *
     512     * @param int $wc_token_id WooCommerce payment token id.
    511513     * @return string
    512514     * @throws Exception Exception.
    513515     */
    514     public function get_selected_payment_token() {
    515         $wc_token_id       = $this->get_posted_integer_data( 'wc-' . $this->id . '-payment-token' );
     516    public function get_selected_payment_token( $wc_token_id ) {
    516517        $wc_token          = WC_Payment_Tokens::get( $wc_token_id );
    517518        $payment_method_id = $wc_token->get_token();
     
    522523
    523524        return $wc_token;
    524     }
    525 
    526     /**
    527      * Check if save payment method requested
    528      */
    529     public function save_payment_method_requested() {
    530         return $this->get_posted_integer_data( 'revolut_save_payment_method' );
    531525    }
    532526
     
    549543        $total                 = $this->get_revolut_order_total( $total, $currency );
    550544        $mode                  = $this->api_settings->get_option( 'mode' );
    551         $hide_fieldset         = $this->get_option( 'card_widget_type' ) === 'popup' || $this->get_request_data( 'pay_for_order' ) ? 'height:0px;padding:0' : '';
     545        $hide_fieldset         = $this->get_option( 'card_widget_type' ) === 'popup' || get_query_var( 'pay_for_order' ) ? 'height:0px;padding:0' : '';
    552546        $shipping_total        = $this->get_cart_total_shipping();
    553547        $hide_payment_method   = ! empty( $hide_fieldset ) && ! $display_tokenization ? true : false;
     
    615609        }
    616610
    617         return $this->check_is_get_data_submitted( 'change_payment_method' ) || $this->cart_contains_subscription();
     611        return get_query_var( 'change_payment_method' ) || $this->cart_contains_subscription();
    618612    }
    619613
  • revolut-gateway-for-woocommerce/trunk/includes/gateways/class-wc-gateway-revolut-pay.php

    r2976441 r3025245  
    4444        }
    4545
    46         add_action( 'wp_loaded', array( $this, 'check_revolut_pay_payment_result' ) );
     46        add_action( 'wp', array( $this, 'check_revolut_pay_payment_result' ) );
    4747        add_filter( 'wc_revolut_settings_nav_tabs', array( $this, 'admin_nav_tab' ), 3 );
    4848        add_action( 'wp_enqueue_scripts', array( $this, 'wc_revolut_pay_enqueue_scripts' ) );
     
    5757     */
    5858    public function check_revolut_pay_payment_result() {
    59         if ( empty( $this->get_request_data( '_rp_oid' ) ) ) {
     59        if ( empty( get_query_var( '_rp_oid' ) ) ) {
    6060            return;
    6161        }
    6262
    63         $public_id = $this->get_request_data( '_rp_oid' );
     63        $public_id = get_query_var( '_rp_oid' );
    6464
    6565        global $wpdb;
     
    9595        $this->log_error( 'order processing - public_id: ' . $public_id . ' - wc_order_id: ' . $wc_order_id );
    9696
    97         $_POST['revolut_public_id']      = $public_id;
    98         $_POST['revolut_pay_redirected'] = 1;
    99         $this->process_payment( $wc_order_id );
     97        $this->process_payment( $wc_order_id, $public_id, false, '', false, true );
    10098    }
    10199
     
    108106    public function process_revolut_pay_fc_payment( $revolut_public_id ) {
    109107        try {
    110             if ( ! empty( $this->get_request_data( '_rp_fr' ) ) ) {
    111                 wc_add_notice( $this->get_request_data( '_rp_fr' ), 'error' );
     108            if ( ! empty( get_query_var( '_rp_fr' ) ) ) {
     109                wc_add_notice( get_query_var( '_rp_fr' ), 'error' );
    112110                return;
    113111            }
     
    245243            check_ajax_referer( 'wc-revolut-load-order-data', 'security' );
    246244
    247             $revolut_public_id = $this->get_post_request_data( 'revolut_public_id' );
     245            $revolut_public_id = isset( $_POST['revolut_public_id'] ) ? wc_clean( wp_unslash( $_POST['revolut_public_id'] ) ) : '';
    248246
    249247            wp_send_json(
     
    442440        $total = WC()->cart->get_total( '' );
    443441
    444         if ( $this->check_is_get_data_submitted( 'pay_for_order' ) && ! empty( $this->get_request_data( 'key' ) ) ) {
     442        if ( get_query_var( 'pay_for_order' ) && ! empty( get_query_var( 'key' ) ) ) {
    445443            global $wp;
    446444            $order = wc_get_order( wc_clean( $wp->query_vars['order-pay'] ) );
  • revolut-gateway-for-woocommerce/trunk/includes/gateways/class-wc-gateway-revolut-payment-request.php

    r2976441 r3025245  
    170170     */
    171171    public function is_available() {
    172         if ( ( 'yes' === $this->enabled && is_product() ) || ( $this->check_is_post_data_submitted( 'payment_method' ) && $this->get_post_request_data( 'payment_method' ) === $this->id ) ) {
     172        $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( wp_unslash( $_POST['payment_method'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
     173
     174        if ( ( 'yes' === $this->enabled && is_product() ) || $payment_method === $this->id ) {
    173175            return true;
    174176        }
     
    283285        );
    284286
    285         if ( $this->get_option( 'apple_pay_merchant_onboarded' ) === 'no' ) {
     287        if ( $this->get_option( 'apple_pay_merchant_onboarded' ) !== 'yes' ) {
    286288            $this->form_fields['onboard_applepay'] = array(
    287289                'title'       => __( 'Onboard shop domain for Apple Pay', 'revolut-gateway-for-woocommerce' ),
     
    332334    /**
    333335     * Ajax endpoint in order to create WooCommerce order
     336     *
     337     * @throws Exception Exception.
    334338     */
    335339    public function revolut_payment_request_ajax_create_order() {
     340        check_ajax_referer( 'wc-revolut-create-order', 'security' );
    336341
    337342        if ( WC()->cart->is_empty() ) {
     
    346351
    347352        try {
    348             $wc_order_data = $this->get_wc_order_details();
     353            $public_id = isset( $_POST['revolut_public_id'] ) ? wc_clean( wp_unslash( $_POST['revolut_public_id'] ) ) : '';
     354
     355            if ( empty( $public_id ) ) {
     356                throw new Exception( 'Public ID is missing for the session' );
     357            }
     358
     359            $order_id = $this->get_revolut_order_by_public_id( $public_id );
     360
     361            if ( empty( $order_id ) ) {
     362                throw new Exception( 'Can not find revolut order id' );
     363            }
     364
     365            $address_info          = isset( $_POST['address_info'] ) ? wc_clean( wp_unslash( $_POST['address_info'] ) ) : '';
     366            $shipping_required     = isset( $_POST['shipping_required'] ) ? wc_clean( wp_unslash( $_POST['shipping_required'] ) ) : '';
     367            $revolut_gateway       = isset( $_POST['revolut_gateway'] ) ? wc_clean( wp_unslash( $_POST['address_info'] ) ) : '';
     368            $revolut_payment_error = isset( $_POST['revolut_payment_error'] ) ? wc_clean( wp_unslash( $_POST['revolut_payment_error'] ) ) : '';
     369
     370            if ( empty( $address_info ) ) {
     371                throw new Exception( 'Address information is missing' );
     372            }
     373
     374            $wc_order_data = $this->format_wc_order_details(
     375                $address_info,
     376                $shipping_required,
     377                $revolut_gateway
     378            );
     379
     380            foreach ( $errors->errors as $code => $messages ) {
     381                $data = $errors->get_error_data( $code );
     382                foreach ( $messages as $message ) {
     383                    wc_add_notice( $message, 'error', $data );
     384                }
     385            }
     386
     387            if ( 0 === wc_notice_count( 'error' ) ) {
     388                $_POST = array_merge( $_POST, $wc_order_data );
     389                unset( $_POST['address_info'] );
     390                $_POST['_wpnonce'] = wp_create_nonce( 'woocommerce-process_checkout' );
     391                WC()->checkout()->process_checkout();
     392            }
     393
     394            $messages = wc_print_notices( true );
     395
     396            $this->log_error( '->>> start messages  - ' . $messages );
     397
     398            wp_send_json(
     399                array(
     400                    'result'   => 'failure',
     401                    'messages' => $messages,
     402                )
     403            );
    349404        } catch ( Exception $e ) {
    350             $this->log_error( $e->getMessage() );
    351405            $errors->add( 'payment', __( 'Something went wrong', 'woocommerce' ) );
    352             if ( ! empty( $this->get_post_request_data( 'revolut_payment_error' ) ) ) {
    353                 $errors->add( 'payment', $this->get_post_request_data( 'revolut_payment_error' ) );
    354                 $this->log_error( $this->get_post_request_data( 'revolut_payment_error' ) );
    355             }
    356         }
    357 
    358         foreach ( $errors->errors as $code => $messages ) {
    359             $data = $errors->get_error_data( $code );
    360             foreach ( $messages as $message ) {
    361                 wc_add_notice( $message, 'error', $data );
    362             }
    363         }
    364 
    365         if ( 0 === wc_notice_count( 'error' ) ) {
    366             $_POST = array_merge( $_POST, $wc_order_data ); // phpcs:ignore
    367             unset( $_POST['address_info'] ); // phpcs:ignore
    368             $_POST['_wpnonce'] = wp_create_nonce( 'woocommerce-process_checkout' );
    369             WC()->checkout()->process_checkout();
    370         }
    371 
    372         $messages = wc_print_notices( true );
    373 
    374         wp_send_json(
    375             array(
    376                 'result'   => 'failure',
    377                 'messages' => $messages,
    378             )
    379         );
    380     }
    381 
    382     /**
    383      * Get order details
    384      *
    385      * @throws Exception Exception.
    386      */
    387     public function get_wc_order_details() {
    388         $public_id = $this->get_post_request_data( 'revolut_public_id' );
    389 
    390         if ( empty( $public_id ) ) {
    391             throw new Exception( 'Public ID is missing for the session' );
    392         }
    393 
    394         $order_id = $this->get_revolut_order_by_public_id( $public_id );
    395 
    396         if ( empty( $order_id ) ) {
    397             throw new Exception( 'Can not find revolut order id' );
    398         }
    399 
    400         $address_info = $this->get_post_request_data( 'address_info' );
    401 
    402         if ( empty( $address_info ) ) {
    403             throw new Exception( 'Address information is missing' );
    404         }
    405 
    406         return $this->format_wc_order_details(
    407             $this->get_post_request_data( 'address_info' ),
    408             $this->get_posted_integer_data( 'shipping_required' ),
    409             $this->get_post_request_data( 'revolut_gateway' )
    410         );
     406            if ( ! empty( $revolut_payment_error ) ) {
     407                $errors->add( 'payment', $revolut_payment_error );
     408                $this->log_error( 'revolut_payment_request_ajax_create_order: ' . $revolut_payment_error );
     409            }
     410        }
    411411    }
    412412
     
    420420            check_ajax_referer( 'wc-revolut-pr-add-to-cart', 'security' );
    421421
    422             $revolut_public_id = $this->get_post_request_data( 'revolut_public_id' );
     422            $revolut_public_id = isset( $_POST['revolut_public_id'] ) ? wc_clean( wp_unslash( $_POST['revolut_public_id'] ) ) : '';
    423423
    424424            if ( empty( $revolut_public_id ) ) {
     
    432432            WC()->shipping->reset_shipping();
    433433
    434             $product_id     = $this->get_posted_integer_data( 'product_id' );
    435             $is_revolut_pay = $this->get_posted_integer_data( 'is_revolut_pay' );
    436             $qty            = ! $this->check_is_post_data_submitted( 'qty' ) ? 1 : $this->get_posted_integer_data( 'qty' );
    437             $product        = wc_get_product( $product_id );
    438             $product_type   = $product->get_type();
    439             $global_cart    = WC()->cart;
    440 
    441             if ( ! $this->get_posted_integer_data( 'add_to_cart' ) ) {
     434            $product_id            = isset( $_POST['product_id'] ) ? wc_clean( wp_unslash( $_POST['product_id'] ) ) : 0;
     435            $is_revolut_pay        = isset( $_POST['is_revolut_pay'] ) ? wc_clean( wp_unslash( $_POST['is_revolut_pay'] ) ) : 0;
     436            $qty                   = isset( $_POST['qty'] ) ? wc_clean( wp_unslash( $_POST['qty'] ) ) : 0;
     437            $is_add_to_cart_action = isset( $_POST['add_to_cart'] ) ? wc_clean( wp_unslash( $_POST['add_to_cart'] ) ) : 0;
     438            $attributes            = isset( $_POST['attributes'] ) ? wc_clean( wp_unslash( $_POST['attributes'] ) ) : '';
     439            $product               = wc_get_product( $product_id );
     440            $product_type          = $product->get_type();
     441            $global_cart           = WC()->cart;
     442
     443            if ( ! $is_add_to_cart_action ) {
    442444                WC()->cart = clone WC()->cart;
    443445            }
     
    447449            if ( 'simple' === $product_type || 'subscription' === $product_type ) {
    448450                WC()->cart->add_to_cart( $product->get_id(), $qty );
    449             } elseif ( $this->check_is_post_data_submitted( 'attributes' ) && ( 'variable' === $product_type || 'variable-subscription' === $product_type ) ) {
    450                 $attributes   = $this->get_post_request_data( 'attributes' );
     451            } elseif ( $attributes && ( 'variable' === $product_type || 'variable-subscription' === $product_type ) ) {
    451452                $data_store   = WC_Data_Store::load( 'product' );
    452453                $variation_id = $data_store->find_matching_product_variation( $product, $attributes );
     
    460461            $is_cart_empty = ! WC()->cart->is_empty();
    461462
    462             if ( ! $this->get_posted_integer_data( 'add_to_cart' ) ) {
     463            if ( ! $is_add_to_cart_action ) {
    463464                WC()->cart = $global_cart;
    464465            }
     
    487488        try {
    488489
    489             $revolut_public_id = $this->get_post_request_data( 'revolut_public_id' );
     490            $revolut_public_id = isset( $_POST['revolut_public_id'] ) ? wc_clean( wp_unslash( $_POST['revolut_public_id'] ) ) : '';
    490491
    491492            if ( empty( $revolut_public_id ) ) {
     
    542543            }
    543544
    544             $revolut_public_id = $this->get_post_request_data( 'revolut_public_id' );
     545            $revolut_public_id = isset( $_POST['revolut_public_id'] ) ? wc_clean( wp_unslash( $_POST['revolut_public_id'] ) ) : '';
    545546
    546547            if ( empty( $revolut_public_id ) ) {
     
    577578
    578579        try {
    579             $revolut_public_id = $this->get_post_request_data( 'revolut_public_id' );
     580            $revolut_public_id = isset( $_POST['revolut_public_id'] ) ? wc_clean( wp_unslash( $_POST['revolut_public_id'] ) ) : '';
    580581
    581582            if ( empty( $revolut_public_id ) ) {
  • revolut-gateway-for-woocommerce/trunk/includes/settings/class-wc-revolut-settings-api.php

    r2977523 r3025245  
    394394
    395395            if ( $this->get_option( 'revolut_pay_synchronous_webhook_domain_' . $mode . '_' . $location_id ) === $web_hook_url ) {
     396                $this->update_option( 'revolut_' . $mode . '_location_id', $location_id );
    396397                return true;
    397398            }
     399
    398400            $body = array(
    399401                'url'         => $web_hook_url,
     
    453455     */
    454456    public function check_is_get_data_submitted( $submit ) {
    455         return isset( $_GET[ $submit ] );  // phpcs:ignore
     457        return isset( $_GET[ $submit ] ); // phpcs:ignore
    456458    }
    457459
     
    462464     */
    463465    public function get_request_data( $get_key ) {
    464         if ( ! isset( $_GET[ $get_key ] ) ) { // phpcs:ignore
    465             return null;
    466         }
    467 
    468         return $this->recursive_sanitize_text_field( $_GET[ $get_key ] ); // phpcs:ignore
    469     }
    470 
    471     /**
    472      * Clear data.
    473      *
    474      * @param mixed $var data for cleaning.
    475      */
    476     public function recursive_sanitize_text_field( $var ) {
    477         if ( is_array( $var ) ) {
    478             return array_map( array( $this, 'recursive_sanitize_text_field' ), $var );
    479         } else {
    480             return sanitize_text_field( wp_unslash( $var ) );
    481         }
     466        return isset( $_GET[ $get_key ] ) ? wc_clean( wp_unslash( $_GET[ $get_key ] ) ) : ''; // phpcs:ignore
    482467    }
    483468}
  • revolut-gateway-for-woocommerce/trunk/includes/traits/wc-revolut-express-checkout-helper-trait.php

    r2964057 r3025245  
    219219                $attribute_key = 'attribute_' . sanitize_title( $attribute_name );
    220220
    221                 if ( $this->check_is_get_data_submitted( $attribute_key ) ) {
     221                if ( isset( $_GET[ $attribute_key ] ) ) { // phpcs:ignore
    222222                    $attributes[ $attribute_key ] = sanitize_text_field( wp_unslash( $_GET[ $attribute_key ] ) ); // phpcs:ignore
    223223                } else {
     
    336336                    'update_order_total'          => wp_create_nonce( 'wc-revolut-update-order-total' ),
    337337                    'load_order_data'             => wp_create_nonce( 'wc-revolut-load-order-data' ),
     338                    'create_order'                => wp_create_nonce( 'wc-revolut-create-order' ),
    338339                    'cancel_order'                => wp_create_nonce( 'wc-revolut-cancel-order' ),
    339340                    'get_express_checkout_params' => wp_create_nonce( 'wc-revolut-get-express-checkout-params' ),
     
    343344                    'get_selected_product_data'   => wp_create_nonce( 'wc-revolut-get-selected-product-data' ),
    344345                    'log_errors'                  => wp_create_nonce( 'wc-revolut-log-errors' ),
     346                    'set_error_message'           => wp_create_nonce( 'wc-revolut-set-error-message' ),
    345347                    'clear_cart'                  => wp_create_nonce( 'wc-revolut-clear-cart' ),
     348                    'process_payment_result'      => wp_create_nonce( 'wc-revolut-process-payment-result' ),
    346349                ),
    347350                'is_product_page'               => $this->is_product(),
     
    357360            );
    358361        } catch ( Exception $e ) {
    359             $this->log_error( $e->getMessage() );
     362            $this->log_error( 'get_wc_revolut_payment_request_params : ' . $e->getMessage() );
    360363        }
    361364    }
  • revolut-gateway-for-woocommerce/trunk/includes/traits/wc-revolut-helper-trait.php

    r2995266 r3025245  
    595595            }
    596596
    597             $merchant_public_key = $this->api_client->get( WC_GATEWAY_PUBLIC_KEY_ENDPOINT, true );
     597            $merchant_public_key = $this->api_client->get( WC_GATEWAY_PUBLIC_KEY_ENDPOINT, false, true );
    598598            $merchant_public_key = isset( $merchant_public_key['public_key'] ) ? $merchant_public_key['public_key'] : '';
    599599
     
    635635     */
    636636    public function is_subs_change_payment() {
    637         return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); // phpcs:ignore
     637        return get_query_var( 'pay_for_order' ) && get_query_var( 'change_payment_method' );
    638638    }
    639639
     
    828828
    829829    /**
    830      * Check is data submitted for GET request.
    831      *
    832      * @param string $submit request key.
    833      */
    834     public function check_is_get_data_submitted( $submit ) {
    835         return isset( $_GET[ $submit ] );  // phpcs:ignore
    836     }
    837 
    838     /**
    839      * Check is data submitted for POST request.
    840      *
    841      * @param string $submit request key.
    842      */
    843     public function check_is_post_data_submitted( $submit ) {
    844         return isset( $_POST[ $submit ] );  // phpcs:ignore
    845     }
    846 
    847     /**
    848      * Safe get posted integer data
    849      *
    850      * @param string $post_key request key.
    851      */
    852     public function get_posted_integer_data( $post_key ) {
    853         if ( ! isset( $_POST[ $post_key ] ) ) { // phpcs:ignore
    854             return 0;
    855         }
    856 
    857         return (int) $_POST[ $post_key ];  // phpcs:ignore
    858     }
    859 
    860     /**
    861      * Safe get posted data
    862      *
    863      * @param string $post_key request key.
    864      */
    865     public function get_post_request_data( $post_key ) {
    866         if ( ! isset( $_POST[ $post_key ] ) ) { // phpcs:ignore
    867             return null;
    868         }
    869 
    870         return $this->recursive_sanitize_text_field( $_POST[ $post_key ]);  // phpcs:ignore
    871     }
    872 
    873     /**
    874      * Safe get request data
    875      *
    876      * @param string $get_key request key.
    877      */
    878     public function get_request_data( $get_key ) {
    879         if ( ! isset( $_GET[ $get_key ] ) ) { // phpcs:ignore
    880             return null;
    881         }
    882 
    883         return $this->recursive_sanitize_text_field( $_GET[ $get_key ] ); // phpcs:ignore
    884     }
    885 
    886     /**
    887      * Clear data.
    888      *
    889      * @param mixed $var data for cleaning.
    890      */
    891     public function recursive_sanitize_text_field( $var ) {
    892         if ( is_array( $var ) ) {
    893             return array_map( array( $this, 'recursive_sanitize_text_field' ), $var );
    894         } else {
    895             return sanitize_text_field( wp_unslash( $var ) );
    896         }
    897     }
    898 
    899     /**
    900830     * Get two-digit language iso code.
    901831     */
     
    936866    public function get_available_card_brands( $public_id ) {
    937867        try {
    938             $order_details = $this->api_client->get( "/orders/token/{$public_id}", false, true );
    939             if ( ! isset( $order_details['availableCardBrands'] ) || empty( $order_details['availableCardBrands'] ) ) {
     868            $order_details = $this->api_client->get( '/available-payment-methods', true );
     869            if ( ! isset( $order_details['available_card_brands'] ) || empty( $order_details['available_card_brands'] ) ) {
    940870                return '';
    941871            }
    942 
    943             return implode( ',', array_map( 'strtolower', $order_details['availableCardBrands'] ) );
     872            return implode( ',', array_map( 'strtolower', $order_details['available_card_brands'] ) );
    944873        } catch ( Exception $e ) {
    945874            $this->log_error( 'get_available_card_brands: ' . $e->getMessage() );
  • revolut-gateway-for-woocommerce/trunk/readme.txt

    r2995266 r3025245  
    44Requires at least: 4.4
    55Tested up to: 6.3
    6 Stable tag: 4.9.5
     6Stable tag: 4.9.6
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    9898
    9999== Changelog ==
     100= 4.9.6 =
     101* Added Woocommerce High-Performance Order Storage (HPOS) compatibility.
     102* Added additional security improvements.
     103
    100104= 4.9.5 =
    101105* Fixed creating customer objects
Note: See TracChangeset for help on using the changeset viewer.