Plugin Directory

Changeset 3068486


Ignore:
Timestamp:
04/10/2024 12:17:17 PM (22 months ago)
Author:
revolutbusiness
Message:

Update plugin sources to version 4.11.0

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

Legend:

Unmodified
Added
Removed
  • revolut-gateway-for-woocommerce/trunk/assets/js/revolut-payment-request.js

    r3025245 r3068486  
    9292      product_data['is_revolut_pay'] = revpay ? 1 : 0
    9393      product_data['security'] = wc_revolut_payment_request_params.nonce.add_to_cart
    94       product_data['revolut_public_id'] =
    95         wc_revolut_payment_request_params.revolut_public_id
    9694      product_data['product_id'] = $('.single_add_to_cart_button').val()
    9795      product_data['qty'] = $('.quantity .qty').val()
     
    130128    let address_data = {
    131129      security: wc_revolut_payment_request_params.nonce.shipping,
    132       revolut_public_id: wc_revolut_payment_request_params.revolut_public_id,
    133130      country: address.country,
    134131      state: address.region,
     
    158155  function updateShippingOptions(shippingOption) {
    159156    let shipping_option_data = {
    160       revolut_public_id: wc_revolut_payment_request_params.revolut_public_id,
    161157      security: wc_revolut_payment_request_params.nonce.update_shipping,
    162158      shipping_method: [shippingOption.id],
     
    185181        .then(response => {
    186182          resolve(response)
    187         })
    188         .catch(error => {
    189           reject(error)
    190         })
    191     })
    192   }
    193 
    194   function udpateExpressCheckoutParams(revpay = false) {
    195     return new Promise((resolve, reject) => {
    196       sendRequest(
    197         getAjaxURL(revpay ? 'get_express_checkout_params' : 'get_payment_request_params'),
    198         {
    199           security: revpay
    200             ? wc_revolut_payment_request_params.nonce.get_express_checkout_params
    201             : wc_revolut_payment_request_params.nonce.get_payment_request_params,
    202         },
    203       )
    204         .then(response => {
    205           if (response.success) {
    206             wc_revolut_payment_request_params.revolut_public_id =
    207               response.revolut_public_id
    208             wc_revolut_payment_request_params.nonce.checkout = response.checkout_nonce
    209             return resolve()
    210           }
    211           reject('')
    212183        })
    213184        .catch(error => {
     
    353324    }
    354325
    355     udpateExpressCheckoutParams().then(function () {
    356       const RC = RevolutCheckout(wc_revolut_payment_request_params.revolut_public_id)
    357       const revolutPaymentReuqestButton = document.getElementById(
    358         'revolut-payment-request-button',
    359       )
    360 
    361       paymentRequest = RC.paymentRequest({
    362         target: revolutPaymentReuqestButton,
    363         requestShipping: wc_revolut_payment_request_params.shipping_required,
    364         shippingOptions: wc_revolut_payment_request_params.free_shipping_option,
    365         onClick() {
    366           if (!wc_revolut_payment_request_params.shipping_required) {
    367             return createCart(1)
    368           }
    369         },
    370         onShippingOptionChange: selectedShippingOption => {
    371           orderSelectedShippingOption = selectedShippingOption['id']
    372           return updateShippingOptions(selectedShippingOption)
    373         },
    374         onShippingAddressChange: selectedShippingAddress => {
    375           return createCart(1).then(function () {
    376             return getShippingOptions(selectedShippingAddress)
    377           })
    378         },
    379         onSuccess() {
    380           submitOrder()
    381         },
    382         validate(address) {
    383           address_info = address
     326    const { paymentRequest } = RevolutCheckout.payments({
     327      locale: wc_revolut_payment_request_params.locale,
     328      publicToken: wc_revolut_payment_request_params.publicToken,
     329    })
     330
     331    let paymentRequestButton = document.getElementById('revolut-payment-request-button')
     332    const request = paymentRequest.mount(paymentRequestButton, {
     333      currency: wc_revolut_payment_request_params.currency,
     334      amount: 0,
     335      requestShipping: wc_revolut_payment_request_params.shipping_required,
     336      shippingOptions: wc_revolut_payment_request_params.free_shipping_option,
     337      onClick() {
     338        if (!wc_revolut_payment_request_params.shipping_required) {
     339          return createCart(1)
     340        }
     341      },
     342      onShippingOptionChange: selectedShippingOption => {
     343        orderSelectedShippingOption = selectedShippingOption['id']
     344        return updateShippingOptions(selectedShippingOption)
     345      },
     346      onShippingAddressChange: selectedShippingAddress => {
     347        return createCart(1).then(function () {
     348          return getShippingOptions(selectedShippingAddress)
     349        })
     350      },
     351      onSuccess() {
     352        submitOrder()
     353      },
     354      validate(address) {
     355        address_info = address
     356        return getRevolutOrderPublicId().then(() => {
    384357          return submitWooCommerceOrder()
    385         },
    386         onError(error) {
    387           let errorMessage = error
    388 
    389           if (error['message']) {
    390             errorMessage = error['message']
    391           }
    392 
    393           if (errorMessage == 'Unknown') {
    394             errorMessage =
    395               wc_revolut_payment_request_params.error_messages.checkout_general
    396           }
    397 
    398           if (wc_order_id) {
    399             return submitOrder(errorMessage)
    400           }
    401 
    402           displayErrorMessage(errorMessage)
    403         },
    404         buttonStyle: {
    405           action: wc_revolut_payment_request_params.payment_request_button_type,
    406           size: wc_revolut_payment_request_params.payment_request_button_size,
    407           variant: wc_revolut_payment_request_params.payment_request_button_theme,
    408           radius: wc_revolut_payment_request_params.payment_request_button_radius,
    409         },
    410       })
    411 
    412       paymentRequest.canMakePayment().then(result => {
    413         if (result) {
    414           paymentRequest.render()
    415         } else {
    416           paymentRequest.destroy()
    417         }
    418       })
     358        })
     359      },
     360      createOrder: () => {
     361        return {
     362          publicId: wc_revolut_payment_request_params.revolut_public_id,
     363        }
     364      },
     365      onError(error) {
     366        let errorMessage = error
     367
     368        if (error['message']) {
     369          errorMessage = error['message']
     370        }
     371
     372        if (errorMessage == 'Unknown') {
     373          errorMessage = wc_revolut_payment_request_params.error_messages.checkout_general
     374        }
     375
     376        if (wc_order_id) {
     377          return submitOrder(errorMessage)
     378        }
     379
     380        displayErrorMessage(errorMessage)
     381      },
     382      buttonStyle: {
     383        action: wc_revolut_payment_request_params.payment_request_button_type,
     384        size: wc_revolut_payment_request_params.payment_request_button_size,
     385        variant: wc_revolut_payment_request_params.payment_request_button_theme,
     386        radius: wc_revolut_payment_request_params.payment_request_button_radius,
     387      },
     388    })
     389
     390    request.canMakePayment().then(result => {
     391      if (result) {
     392        request.render()
     393      } else {
     394        request.destroy()
     395      }
    419396    })
    420397  }
     
    430407    }
    431408
    432     udpateExpressCheckoutParams(true).then(function () {
    433       instance = RevolutCheckout.payments({
    434         locale: wc_revolut_payment_request_params.locale,
    435         publicToken: wc_revolut_payment_request_params.publicToken,
    436       })
    437 
    438       instance.revolutPay.mount('#revolut-pay-express-checkout-button', {
    439         currency: wc_revolut_payment_request_params.currency,
    440         totalAmount: parseInt(wc_revolut_payment_request_params.total),
    441         requestShipping: true,
    442         validate() {
    443           return createCart(1, true).then(function (result) {
    444             if (result && result.success) {
    445               if (wc_revolut_payment_request_params.is_cart_page) {
    446                 return updatePaymentTotal()
    447               }
    448 
    449               return Promise.resolve(true)
     409    const { revolutPay } = RevolutCheckout.payments({
     410      locale: wc_revolut_payment_request_params.locale,
     411      publicToken: wc_revolut_payment_request_params.publicToken,
     412    })
     413
     414    revolutPay.mount('#revolut-pay-express-checkout-button', {
     415      currency: wc_revolut_payment_request_params.currency,
     416      totalAmount: 0,
     417      requestShipping: true,
     418      createOrder: () => {
     419        return createCart(1, true).then(result => {
     420          if (result && result.success) {
     421            if (wc_revolut_payment_request_params.is_cart_page) {
     422              updatePaymentTotal()
    450423            }
    451           })
    452         },
    453         createOrder: () => {
    454           return { publicId: wc_revolut_payment_request_params.revolut_public_id }
    455         },
    456         buttonStyle: {
    457           cashbackCurrency: wc_revolut_payment_request_params.currency,
    458           variant: wc_revolut_payment_request_params.revolut_pay_button_theme,
    459           size: wc_revolut_payment_request_params.revolut_pay_button_size,
    460           radius: wc_revolut_payment_request_params.revolut_pay_button_radius,
    461         },
    462         mobileRedirectUrls: {
    463           success: wc_revolut_payment_request_params.redirect_url,
    464           failure: wc_revolut_payment_request_params.redirect_url,
    465           cancel: wc_revolut_payment_request_params.redirect_url,
    466         },
    467         __metadata: {
    468           environment: 'woocommerce',
    469           context: wc_revolut_payment_request_params.is_cart_page ? 'cart' : 'product',
    470           origin_url: wc_revolut_payment_request_params.revolut_pay_origin_url,
    471         },
    472       })
    473 
    474       instance.revolutPay.on('payment', function (event) {
    475         switch (event.type) {
    476           case 'success':
    477             $.blockUI({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } })
    478             loadOrderData()
    479               .then(function (order_data) {
    480                 address_info = order_data.address_info
    481                 orderSelectedShippingOption = order_data.selected_shipping_option
    482                 submitWooCommerceOrder('revolut_pay')
    483                   .then(function () {
    484                     submitOrder('', 'revolut_pay')
    485                   })
    486                   .catch(error => {
    487                     displayErrorMessage([error])
    488                     $.unblockUI()
    489                     $('.blockUI.blockOverlay').hide()
    490                   })
    491               })
    492               .catch(error => {
    493                 displayErrorMessage([error])
    494                 $.unblockUI()
    495                 $('.blockUI.blockOverlay').hide()
    496               })
    497             break
    498           case 'error':
    499             displayErrorMessage(event.error.message)
    500             break
    501         }
    502       })
     424            return getRevolutOrderPublicId()
     425          }
     426          displayErrorMessage(
     427            wc_revolut_payment_request_params.error_messages.checkout_general,
     428          )
     429        })
     430      },
     431      buttonStyle: {
     432        cashbackCurrency: wc_revolut_payment_request_params.currency,
     433        variant: wc_revolut_payment_request_params.revolut_pay_button_theme,
     434        size: wc_revolut_payment_request_params.revolut_pay_button_size,
     435        radius: wc_revolut_payment_request_params.revolut_pay_button_radius,
     436      },
     437      mobileRedirectUrls: {
     438        success: wc_revolut_payment_request_params.redirect_url,
     439        failure: wc_revolut_payment_request_params.redirect_url,
     440        cancel: wc_revolut_payment_request_params.redirect_url,
     441      },
     442      __metadata: {
     443        environment: 'woocommerce',
     444        context: wc_revolut_payment_request_params.is_cart_page ? 'cart' : 'product',
     445        origin_url: wc_revolut_payment_request_params.revolut_pay_origin_url,
     446      },
     447    })
     448
     449    revolutPay.on('payment', function (event) {
     450      switch (event.type) {
     451        case 'success':
     452          $.blockUI({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } })
     453          loadOrderData()
     454            .then(function (order_data) {
     455              address_info = order_data.address_info
     456              orderSelectedShippingOption = order_data.selected_shipping_option
     457              submitWooCommerceOrder('revolut_pay')
     458                .then(function () {
     459                  submitOrder('', 'revolut_pay')
     460                })
     461                .catch(error => {
     462                  displayErrorMessage([error])
     463                  $.unblockUI()
     464                  $('.blockUI.blockOverlay').hide()
     465                })
     466            })
     467            .catch(error => {
     468              displayErrorMessage([error])
     469              $.unblockUI()
     470              $('.blockUI.blockOverlay').hide()
     471            })
     472          break
     473        case 'error':
     474          displayErrorMessage(event.error.message)
     475          break
     476      }
    503477    })
    504478  }
     
    562536      })
    563537  }
     538  function getRevolutOrderPublicId() {
     539    return new Promise((resolve, reject) => {
     540      if (wc_revolut_payment_request_params.revolut_public_id) {
     541        return resolve({ publicId: wc_revolut_payment_request_params.revolut_public_id })
     542      }
     543
     544      sendRequest(getAjaxURL('get_express_checkout_params'), {
     545        security: wc_revolut_payment_request_params.nonce.get_express_checkout_params,
     546      }).then(order => {
     547        if (order.success) {
     548          wc_revolut_payment_request_params.revolut_public_id = order.revolut_public_id
     549          return resolve({ publicId: order.revolut_public_id })
     550        }
     551
     552        displayErrorMessage(
     553          wc_revolut_payment_request_params.error_messages.checkout_general,
     554        )
     555      })
     556    })
     557  }
    564558})
  • revolut-gateway-for-woocommerce/trunk/assets/js/revolut.js

    r3047921 r3068486  
    1919  let wc_order_id = 0
    2020  let instanceUpsell = null
     21  let paymentRequestButtonResult = false
     22  let isPaymentRequestButtonActive =
     23    $('#woocommerce-revolut-payment-request-element').length > 0
    2124  let reload_checkout = 0
    2225  const revolut_pay_v2 = $('.revolut-pay-v2').length > 0
     
    358361    }
    359362
    360     if (document.getElementById('woocommerce-revolut-payment-request-element')) {
     363    if (isPaymentRequestButtonActive && !paymentRequestButtonResult) {
    361364      initPaymentRequestButton(
    362365        document.getElementById('woocommerce-revolut-payment-request-element'),
    363366        currentPaymentMethod.publicId,
     367        false,
    364368      )
    365369
     
    367371        instance.destroy()
    368372      }
     373    } else if (isPaymentRequestButtonActive) {
     374      adjustPaymentRequestButtonNameAndTitle(paymentRequestButtonResult)
    369375    }
    370376
     
    503509  }
    504510
    505   function initPaymentRequestButton(target, publicId) {
     511  function initPaymentRequestButton(target, publicId, render = true) {
    506512    $('#woocommerce-revolut-payment-request-element').empty()
    507513
     
    550556
    551557    paymentRequest.canMakePayment().then(result => {
    552       let methodName = result == 'googlePay' ? 'Google Pay' : 'Apple Pay'
    553       methodName +=
    554         ' ' + revolut_payment_request_button_style.payment_request_button_title
    555       result == 'googlePay'
    556         ? $('.revolut-google-pay-logo').show()
    557         : $('.revolut-apple-pay-logo').show()
    558       const paymentRequestText = $('.payment_method_revolut_payment_request label')
    559       paymentRequestText.html(
    560         paymentRequestText
    561           .html()
    562           .replace('Digital Wallet (ApplePay/GooglePay)', methodName),
    563       )
    564 
    565       if (result) {
     558      adjustPaymentRequestButtonNameAndTitle(result)
     559      paymentRequestButtonResult = result
     560
     561      if (result && render) {
    566562        paymentRequest.render()
    567563      } else {
     
    569565      }
    570566    })
     567  }
     568
     569  function adjustPaymentRequestButtonNameAndTitle(paymentRequestType) {
     570    let methodName = paymentRequestType == 'googlePay' ? 'Google Pay' : 'Apple Pay'
     571    methodName += ' ' + revolut_payment_request_button_style.payment_request_button_title
     572    paymentRequestType == 'googlePay'
     573      ? $('.revolut-google-pay-logo').show()
     574      : $('.revolut-apple-pay-logo').show()
     575    const paymentRequestText = $('.payment_method_revolut_payment_request label')
     576    paymentRequestText.html(
     577      paymentRequestText
     578        .html()
     579        .replace('Digital Wallet (ApplePay/GooglePay)', methodName),
     580    )
    571581  }
    572582
  • revolut-gateway-for-woocommerce/trunk/gateway-revolut.php

    r3047921 r3068486  
    77 * Author URI: https://www.revolut.com/business/online-payments
    88 * Text Domain: revolut-gateway-for-woocommerce
    9  * Version: 4.10.1
     9 * Version: 4.11.0
    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.10.1' );
     18define( 'WC_GATEWAY_REVOLUT_VERSION', '4.11.0' );
    1919define( 'WC_GATEWAY_PUBLIC_KEY_ENDPOINT', '/public-key/latest' );
    2020define( 'WC_GATEWAY_REVPAY_INDEX', 'USE_REVOLUT_PAY_2_0' );
  • revolut-gateway-for-woocommerce/trunk/includes/abstract/class-wc-payment-gateway-revolut.php

    r3047727 r3068486  
    13911391     */
    13921392    public function check_currency_support() {
    1393         if ( ! in_array( get_woocommerce_currency(), $this->available_currency_list, true ) ) {
    1394             return false;
    1395         }
    1396         return true;
     1393        return in_array( get_woocommerce_currency(), $this->available_currency_list, true );
    13971394    }
    13981395
  • revolut-gateway-for-woocommerce/trunk/includes/class-wc-revolut-apple-pay-onboarding.php

    r3033361 r3068486  
    5454     */
    5555    public $domain_onboarding_file_remote_link;
     56
     57    /**
     58     * Onboarding file local link.
     59     *
     60     * @var string
     61     */
     62    public $domain_onboarding_file_local_link;
    5663
    5764    /**
     
    128135        $this->onboarding_file_path               = $this->onboarding_file_dir . '/' . $this->domain_onboarding_file_name;
    129136        $this->domain_onboarding_file_remote_link = 'https://assets.revolut.com/api-docs/merchant-api/files/apple-developer-merchantid-domain-association';
     137        $this->domain_onboarding_file_local_link  = get_site_url() . '/.well-known/apple-developer-merchantid-domain-association';
    130138
    131139        $this->revolut_payment_request_settings = get_option( 'woocommerce_revolut_payment_request_settings', array() );
     
    277285        }
    278286
     287        if ( ! file_get_contents( $this->domain_onboarding_file_local_link ) ) { // phpcs:ignore
     288            $this->add_onboarding_error_message(
     289                __(
     290                    'Can not on-boarding Apple Pay merchant, Domain onboarding file is not accessible',
     291                    'revolut-gateway-for-woocommerce'
     292                )
     293            );
     294            return false;
     295        }
     296
    279297        if ( ! $this->register_domain() ) {
    280298            $this->add_onboarding_error_message(
     
    341359                );
    342360
     361                return false;
     362            }
     363
     364            if ( ! $this->remove_onboarding_file() ) {
    343365                return false;
    344366            }
     
    374396     */
    375397    public function remove_onboarding_file() {
    376         if ( ! unlink( $this->onboarding_file_path ) ) {
     398        if ( file_exists( $this->onboarding_file_path ) && ! unlink( $this->onboarding_file_path ) ) {
    377399            $this->add_onboarding_error_message(
    378400                __(
     
    381403                )
    382404            );
    383         }
     405
     406            return false;
     407        }
     408
     409        return true;
    384410    }
    385411
  • revolut-gateway-for-woocommerce/trunk/includes/class-wc-revolut-payment-ajax-controller.php

    r3033361 r3068486  
    2020    use WC_Gateway_Revolut_Helper_Trait;
    2121
     22    use WC_Gateway_Revolut_Express_Checkout_Helper_Trait;
    2223    /**
    2324     * API client
     
    4243        add_action( 'wc_ajax_revolut_payment_request_set_error_message', array( $this, 'revolut_payment_request_ajax_set_error_message' ) );
    4344        add_action( 'wc_ajax_revolut_payment_request_log_error', array( $this, 'revolut_payment_request_ajax_log_error' ) );
     45        add_action( 'wc_ajax_revolut_payment_request_get_express_checkout_params', array( $this, 'revolut_payment_request_ajax_get_express_checkout_params' ) );
    4446
    4547        if ( is_admin() && current_user_can( 'manage_options' ) ) {
     
    407409
    408410    /**
     411     * Get express checkout params
     412     */
     413    public function revolut_payment_request_ajax_get_express_checkout_params() {
     414        check_ajax_referer( 'wc-revolut-get-express-checkout-params', 'security' );
     415
     416        try {
     417            wp_send_json(
     418                array(
     419                    'success'           => true,
     420                    'revolut_public_id' => $this->create_express_checkout_public_id(),
     421                    'checkout_nonce'    => wp_create_nonce( 'woocommerce-process_checkout' ),
     422                )
     423            );
     424        } catch ( Exception $e ) {
     425            wp_send_json( array( 'success' => false ) );
     426            $this->log_error( $e );
     427        }
     428    }
     429
     430    /**
    409431     * Set error message
    410432     */
  • revolut-gateway-for-woocommerce/trunk/includes/gateways/class-wc-gateway-revolut-cc.php

    r3033361 r3068486  
    599599     */
    600600    public function is_available() {
     601        if ( ! $this->check_currency_support() || ! $this->is_payment_method_available( 'card' ) ) {
     602            return false;
     603        }
     604
    601605        if ( is_add_payment_method_page() && ! $this->revolut_saved_cards ) {
    602606            return false;
     
    610614     */
    611615    public function check_currency_support() {
    612         if ( ! in_array( get_woocommerce_currency(), $this->card_payments_currency_list, true ) ) {
    613             return false;
    614         }
    615         return true;
     616        return in_array( get_woocommerce_currency(), $this->card_payments_currency_list, true );
    616617    }
    617618
  • revolut-gateway-for-woocommerce/trunk/includes/gateways/class-wc-gateway-revolut-pay.php

    r3034762 r3068486  
    5050        add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 );
    5151        add_action( 'wc_ajax_revolut_payment_request_load_order_data', array( $this, 'revolut_payment_request_ajax_load_order_data' ) );
    52         add_action( 'wc_ajax_revolut_payment_request_get_express_checkout_params', array( $this, 'revolut_payment_request_ajax_get_express_checkout_params' ) );
    5352    }
    5453
     
    156155        } catch ( Exception $e ) {
    157156            wc_add_notice( $e->getMessage(), 'error' );
    158         }
    159     }
    160 
    161     /**
    162      * Get express checkout params
    163      */
    164     public function revolut_payment_request_ajax_get_express_checkout_params() {
    165         check_ajax_referer( 'wc-revolut-get-express-checkout-params', 'security' );
    166 
    167         try {
    168             wp_send_json(
    169                 array(
    170                     'success'           => true,
    171                     'revolut_public_id' => $this->create_express_checkout_public_id(),
    172                     'checkout_nonce'    => wp_create_nonce( 'woocommerce-process_checkout' ),
    173                 )
    174             );
    175         } catch ( Exception $e ) {
    176             wp_send_json( array( 'success' => false ) );
    177             $this->log_error( $e );
    178157        }
    179158    }
     
    415394    }
    416395
     396
     397    /**
     398     * Check is payment method available.
     399     */
     400    public function is_available() {
     401        if ( ! $this->check_currency_support() || ! $this->is_payment_method_available( 'pay_with_revolut' ) ) {
     402            return false;
     403        }
     404
     405        return 'yes' === $this->enabled;
     406    }
     407
    417408    /**
    418409     * Display Revolut Pay icon
  • revolut-gateway-for-woocommerce/trunk/includes/gateways/class-wc-gateway-revolut-payment-request.php

    r3047727 r3068486  
    4444        add_action( 'wc_ajax_revolut_payment_request_update_payment_total', array( $this, 'revolut_payment_request_update_revolut_order_with_cart_total' ) );
    4545        add_action( 'wc_ajax_revolut_payment_request_create_order', array( $this, 'revolut_payment_request_ajax_create_order' ) );
    46         add_action( 'wc_ajax_revolut_payment_request_get_payment_request_params', array( $this, 'revolut_payment_request_ajax_get_payment_request_params' ) );
    4746
    4847        if ( 'yes' !== $this->enabled || $this->api_settings->get_option( 'mode' ) === 'sandbox' ) {
     
    5352        add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 2 );
    5453        add_action( 'wp_enqueue_scripts', array( $this, 'revolut_enqueue_payment_request_scripts' ) );
    55     }
    56 
    57     /**
    58      * Get express checkout params
    59      */
    60     public function revolut_payment_request_ajax_get_payment_request_params() {
    61         check_ajax_referer( 'wc-revolut-get-payment-request-params', 'security' );
    62 
    63         try {
    64             wp_send_json(
    65                 array(
    66                     'success'           => true,
    67                     'revolut_public_id' => $this->create_express_checkout_public_id(),
    68                     'checkout_nonce'    => wp_create_nonce( 'woocommerce-process_checkout' ),
    69                 )
    70             );
    71         } catch ( Exception $e ) {
    72             wp_send_json( array( 'success' => false ) );
    73             $this->log_error( $e );
    74         }
    7554    }
    7655
     
    171150        $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( wp_unslash( $_POST['payment_method'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
    172151
    173         if ( ( 'yes' === $this->enabled && is_product() ) || $payment_method === $this->id ) {
     152        if ( $payment_method === $this->id ) {
     153            return true;
     154        }
     155
     156        if ( ! $this->check_currency_support() || ! $this->is_payment_method_available( array( 'apple_pay', 'google_pay' ) ) ) {
     157            return false;
     158        }
     159
     160        $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( wp_unslash( $_POST['payment_method'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
     161
     162        if ( ( 'yes' === $this->enabled && is_product() ) ) {
    174163            return true;
    175164        }
     
    419408            check_ajax_referer( 'wc-revolut-pr-add-to-cart', 'security' );
    420409
    421             $revolut_public_id = isset( $_POST['revolut_public_id'] ) ? wc_clean( wp_unslash( $_POST['revolut_public_id'] ) ) : '';
    422 
    423             if ( empty( $revolut_public_id ) ) {
    424                 throw new Exception( 'Can not get required parameter' );
    425             }
    426 
    427410            if ( ! defined( 'WOOCOMMERCE_CART' ) ) {
    428411                define( 'WOOCOMMERCE_CART', true );
     
    432415
    433416            $product_id            = isset( $_POST['product_id'] ) ? wc_clean( wp_unslash( $_POST['product_id'] ) ) : 0;
    434             $is_revolut_pay        = isset( $_POST['is_revolut_pay'] ) ? wc_clean( wp_unslash( $_POST['is_revolut_pay'] ) ) : 0;
    435417            $qty                   = isset( $_POST['qty'] ) ? wc_clean( wp_unslash( $_POST['qty'] ) ) : 0;
    436418            $is_add_to_cart_action = isset( $_POST['add_to_cart'] ) ? wc_clean( wp_unslash( $_POST['add_to_cart'] ) ) : 0;
     
    457439            WC()->cart->calculate_totals();
    458440
    459             $total_amount  = $this->update_revolut_order_with_cart_total( $revolut_public_id, $is_revolut_pay );
    460441            $is_cart_empty = ! WC()->cart->is_empty();
    461442
     
    464445            }
    465446
    466             $data['total']['amount'] = $total_amount;
     447            $data['total']['amount'] = $this->get_revolut_order_total( WC()->cart->get_total( '' ), get_woocommerce_currency() );
    467448            $data['checkout_nonce']  = wp_create_nonce( 'woocommerce-process_checkout' );
    468449            $data['status']          = 'success';
     
    486467
    487468        try {
    488 
    489             $revolut_public_id = isset( $_POST['revolut_public_id'] ) ? wc_clean( wp_unslash( $_POST['revolut_public_id'] ) ) : '';
    490 
    491             if ( empty( $revolut_public_id ) ) {
    492                 throw new Exception( 'Can not get required parameter' );
    493             }
    494469
    495470            $shipping_address = filter_input_array(
     
    511486            }
    512487
    513             $total_amount = $this->update_revolut_order_with_cart_total( $revolut_public_id );
    514 
    515488            $data['success']         = true;
    516489            $data['status']          = 'success';
    517             $data['total']['amount'] = $total_amount;
     490            $data['total']['amount'] = $this->get_revolut_order_total( WC()->cart->get_total( '' ), get_woocommerce_currency() );
    518491            $data['shippingOptions'] = $shipping_options;
    519492
     
    542515            }
    543516
    544             $revolut_public_id = isset( $_POST['revolut_public_id'] ) ? wc_clean( wp_unslash( $_POST['revolut_public_id'] ) ) : '';
    545 
    546             if ( empty( $revolut_public_id ) ) {
    547                 throw new Exception( 'Can not get required parameter' );
    548             }
    549 
    550517            $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
    551518            $this->update_shipping_method( $shipping_method );
     
    553520            WC()->cart->calculate_totals();
    554521
    555             $total_amount = $this->update_revolut_order_with_cart_total( $revolut_public_id );
    556 
    557522            $data['success']         = true;
    558523            $data['status']          = 'success';
    559             $data['total']['amount'] = $total_amount;
     524            $data['total']['amount'] = $this->get_revolut_order_total( WC()->cart->get_total( '' ), get_woocommerce_currency() );
    560525            wp_send_json( $data );
    561526        } catch ( Exception $e ) {
  • revolut-gateway-for-woocommerce/trunk/includes/traits/wc-revolut-express-checkout-helper-trait.php

    r3025245 r3068486  
    306306    public function get_wc_revolut_payment_request_params() {
    307307        try {
    308             $revolut_public_id = $this->create_express_checkout_public_id();
    309             $total             = WC()->cart->get_total( '' );
    310             $currency          = get_woocommerce_currency();
    311             $total             = $this->get_revolut_order_total( $total, $currency );
    312 
     308            $currency                         = get_woocommerce_currency();
    313309            $revolut_payment_request_settings = get_option( 'woocommerce_revolut_payment_request_settings', array() );
    314310            $revolut_pay_settings             = get_option( 'woocommerce_revolut_pay_settings', array() );
    315311
    316312            return array(
    317                 'total'                         => $total,
    318313                'currency'                      => $currency,
    319314                'locale'                        => $this->get_lang_iso_code(),
    320315                'publicToken'                   => $this->get_merchant_public_api_key(),
    321316                'ajax_url'                      => WC_AJAX::get_endpoint( '%%wc_revolut_gateway_ajax_endpoint%%' ),
    322                 'revolut_public_id'             => $revolut_public_id,
    323317                'revolut_pay_origin_url'        => str_replace( array( 'https://', 'http://' ), '', get_site_url() ),
    324318                'revolut_pay_button_theme'      => ! empty( $revolut_pay_settings['revolut_pay_button_theme'] ) ? $revolut_pay_settings['revolut_pay_button_theme'] : '',
  • revolut-gateway-for-woocommerce/trunk/includes/traits/wc-revolut-helper-trait.php

    r3034762 r3068486  
    861861
    862862    /**
    863      * Check order status
     863     * Get available card brands
    864864     *
    865865     * @param string $amount order amount.
     
    882882
    883883    /**
     884     * Get available payment methods
     885     *
     886     * @param string $amount order amount.
     887     * @param string $currency order currency.
     888     */
     889    public function get_available_payment_methods( $amount, $currency ) {
     890        try {
     891            $this->api_client->set_public_key( $this->get_merchant_public_api_key() );
     892            $order_details = $this->api_client->get( "/available-payment-methods?amount=$amount&currency=$currency", true );
     893            if ( ! isset( $order_details['available_payment_methods'] ) || empty( $order_details['available_payment_methods'] ) ) {
     894                return array();
     895            }
     896
     897            return array_map( 'strtolower', $order_details['available_payment_methods'] );
     898        } catch ( Exception $e ) {
     899            $this->log_error( 'get_available_payment_methods: ' . $e->getMessage() );
     900            return array();
     901        }
     902    }
     903
     904    /**
    884905     * Check the current page
    885906     */
     
    892913        }
    893914    }
     915
     916    /**
     917     * Check the current page
     918     *
     919     * @param string|array $payment_method Payment method name.
     920     */
     921    public function is_payment_method_available( $payment_method ) {
     922        try {
     923            if ( WC()->cart ) {
     924                $total                     = WC()->cart->get_total( '' );
     925                $currency                  = get_woocommerce_currency();
     926                $total                     = $this->get_revolut_order_total( $total, $currency );
     927                $available_payment_methods = $this->get_available_payment_methods( $total, $currency );
     928
     929                if ( is_array( $payment_method ) ) {
     930                    return count( array_intersect( $payment_method, $available_payment_methods ) );
     931                }
     932
     933                return in_array( $payment_method, $available_payment_methods, true );
     934            }
     935        } catch ( Exception $e ) {
     936            $this->log_error( 'is_payment_method_available: ' . $e->getMessage() );
     937            return false;
     938        }
     939
     940        return false;
     941    }
    894942}
  • revolut-gateway-for-woocommerce/trunk/readme.txt

    r3047921 r3068486  
    33Tags: revolut, revolut business, revolut pay, payments, gateway, payment gateway, credit card, card
    44Requires at least: 4.4
    5 Tested up to: 6.3
    6 Stable tag: 4.10.1
     5Tested up to: 6.5
     6Stable tag: 4.11.0
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    9898
    9999== Changelog ==
     100= 4.11.0 =
     101* Improved Fast Checkout order creation process
     102* Improved Apple Pay domain registration process
     103* Improved supported payment gateway and currency checks
     104
    100105= 4.10.1 =
    101106* Fixed card gateway issue
Note: See TracChangeset for help on using the changeset viewer.