Changeset 3068486
- Timestamp:
- 04/10/2024 12:17:17 PM (22 months ago)
- Location:
- revolut-gateway-for-woocommerce/trunk
- Files:
-
- 12 edited
-
assets/js/revolut-payment-request.js (modified) (7 diffs)
-
assets/js/revolut.js (modified) (6 diffs)
-
gateway-revolut.php (modified) (2 diffs)
-
includes/abstract/class-wc-payment-gateway-revolut.php (modified) (1 diff)
-
includes/class-wc-revolut-apple-pay-onboarding.php (modified) (6 diffs)
-
includes/class-wc-revolut-payment-ajax-controller.php (modified) (3 diffs)
-
includes/gateways/class-wc-gateway-revolut-cc.php (modified) (2 diffs)
-
includes/gateways/class-wc-gateway-revolut-pay.php (modified) (3 diffs)
-
includes/gateways/class-wc-gateway-revolut-payment-request.php (modified) (11 diffs)
-
includes/traits/wc-revolut-express-checkout-helper-trait.php (modified) (1 diff)
-
includes/traits/wc-revolut-helper-trait.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
revolut-gateway-for-woocommerce/trunk/assets/js/revolut-payment-request.js
r3025245 r3068486 92 92 product_data['is_revolut_pay'] = revpay ? 1 : 0 93 93 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_id96 94 product_data['product_id'] = $('.single_add_to_cart_button').val() 97 95 product_data['qty'] = $('.quantity .qty').val() … … 130 128 let address_data = { 131 129 security: wc_revolut_payment_request_params.nonce.shipping, 132 revolut_public_id: wc_revolut_payment_request_params.revolut_public_id,133 130 country: address.country, 134 131 state: address.region, … … 158 155 function updateShippingOptions(shippingOption) { 159 156 let shipping_option_data = { 160 revolut_public_id: wc_revolut_payment_request_params.revolut_public_id,161 157 security: wc_revolut_payment_request_params.nonce.update_shipping, 162 158 shipping_method: [shippingOption.id], … … 185 181 .then(response => { 186 182 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: revpay200 ? wc_revolut_payment_request_params.nonce.get_express_checkout_params201 : 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_id208 wc_revolut_payment_request_params.nonce.checkout = response.checkout_nonce209 return resolve()210 }211 reject('')212 183 }) 213 184 .catch(error => { … … 353 324 } 354 325 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(() => { 384 357 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 } 419 396 }) 420 397 } … … 430 407 } 431 408 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() 450 423 } 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 } 503 477 }) 504 478 } … … 562 536 }) 563 537 } 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 } 564 558 }) -
revolut-gateway-for-woocommerce/trunk/assets/js/revolut.js
r3047921 r3068486 19 19 let wc_order_id = 0 20 20 let instanceUpsell = null 21 let paymentRequestButtonResult = false 22 let isPaymentRequestButtonActive = 23 $('#woocommerce-revolut-payment-request-element').length > 0 21 24 let reload_checkout = 0 22 25 const revolut_pay_v2 = $('.revolut-pay-v2').length > 0 … … 358 361 } 359 362 360 if ( document.getElementById('woocommerce-revolut-payment-request-element')) {363 if (isPaymentRequestButtonActive && !paymentRequestButtonResult) { 361 364 initPaymentRequestButton( 362 365 document.getElementById('woocommerce-revolut-payment-request-element'), 363 366 currentPaymentMethod.publicId, 367 false, 364 368 ) 365 369 … … 367 371 instance.destroy() 368 372 } 373 } else if (isPaymentRequestButtonActive) { 374 adjustPaymentRequestButtonNameAndTitle(paymentRequestButtonResult) 369 375 } 370 376 … … 503 509 } 504 510 505 function initPaymentRequestButton(target, publicId ) {511 function initPaymentRequestButton(target, publicId, render = true) { 506 512 $('#woocommerce-revolut-payment-request-element').empty() 507 513 … … 550 556 551 557 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) { 566 562 paymentRequest.render() 567 563 } else { … … 569 565 } 570 566 }) 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 ) 571 581 } 572 582 -
revolut-gateway-for-woocommerce/trunk/gateway-revolut.php
r3047921 r3068486 7 7 * Author URI: https://www.revolut.com/business/online-payments 8 8 * Text Domain: revolut-gateway-for-woocommerce 9 * Version: 4.1 0.19 * Version: 4.11.0 10 10 * Requires at least: 4.4 11 11 * Tested up to: 6.1 … … 16 16 defined( 'ABSPATH' ) || exit; 17 17 define( 'REVOLUT_PATH', plugin_dir_path( __FILE__ ) ); 18 define( 'WC_GATEWAY_REVOLUT_VERSION', '4.1 0.1' );18 define( 'WC_GATEWAY_REVOLUT_VERSION', '4.11.0' ); 19 19 define( 'WC_GATEWAY_PUBLIC_KEY_ENDPOINT', '/public-key/latest' ); 20 20 define( 'WC_GATEWAY_REVPAY_INDEX', 'USE_REVOLUT_PAY_2_0' ); -
revolut-gateway-for-woocommerce/trunk/includes/abstract/class-wc-payment-gateway-revolut.php
r3047727 r3068486 1391 1391 */ 1392 1392 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 ); 1397 1394 } 1398 1395 -
revolut-gateway-for-woocommerce/trunk/includes/class-wc-revolut-apple-pay-onboarding.php
r3033361 r3068486 54 54 */ 55 55 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; 56 63 57 64 /** … … 128 135 $this->onboarding_file_path = $this->onboarding_file_dir . '/' . $this->domain_onboarding_file_name; 129 136 $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'; 130 138 131 139 $this->revolut_payment_request_settings = get_option( 'woocommerce_revolut_payment_request_settings', array() ); … … 277 285 } 278 286 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 279 297 if ( ! $this->register_domain() ) { 280 298 $this->add_onboarding_error_message( … … 341 359 ); 342 360 361 return false; 362 } 363 364 if ( ! $this->remove_onboarding_file() ) { 343 365 return false; 344 366 } … … 374 396 */ 375 397 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 ) ) { 377 399 $this->add_onboarding_error_message( 378 400 __( … … 381 403 ) 382 404 ); 383 } 405 406 return false; 407 } 408 409 return true; 384 410 } 385 411 -
revolut-gateway-for-woocommerce/trunk/includes/class-wc-revolut-payment-ajax-controller.php
r3033361 r3068486 20 20 use WC_Gateway_Revolut_Helper_Trait; 21 21 22 use WC_Gateway_Revolut_Express_Checkout_Helper_Trait; 22 23 /** 23 24 * API client … … 42 43 add_action( 'wc_ajax_revolut_payment_request_set_error_message', array( $this, 'revolut_payment_request_ajax_set_error_message' ) ); 43 44 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' ) ); 44 46 45 47 if ( is_admin() && current_user_can( 'manage_options' ) ) { … … 407 409 408 410 /** 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 /** 409 431 * Set error message 410 432 */ -
revolut-gateway-for-woocommerce/trunk/includes/gateways/class-wc-gateway-revolut-cc.php
r3033361 r3068486 599 599 */ 600 600 public function is_available() { 601 if ( ! $this->check_currency_support() || ! $this->is_payment_method_available( 'card' ) ) { 602 return false; 603 } 604 601 605 if ( is_add_payment_method_page() && ! $this->revolut_saved_cards ) { 602 606 return false; … … 610 614 */ 611 615 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 ); 616 617 } 617 618 -
revolut-gateway-for-woocommerce/trunk/includes/gateways/class-wc-gateway-revolut-pay.php
r3034762 r3068486 50 50 add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); 51 51 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' ) );53 52 } 54 53 … … 156 155 } catch ( Exception $e ) { 157 156 wc_add_notice( $e->getMessage(), 'error' ); 158 }159 }160 161 /**162 * Get express checkout params163 */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 );178 157 } 179 158 } … … 415 394 } 416 395 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 417 408 /** 418 409 * Display Revolut Pay icon -
revolut-gateway-for-woocommerce/trunk/includes/gateways/class-wc-gateway-revolut-payment-request.php
r3047727 r3068486 44 44 add_action( 'wc_ajax_revolut_payment_request_update_payment_total', array( $this, 'revolut_payment_request_update_revolut_order_with_cart_total' ) ); 45 45 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' ) );47 46 48 47 if ( 'yes' !== $this->enabled || $this->api_settings->get_option( 'mode' ) === 'sandbox' ) { … … 53 52 add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 2 ); 54 53 add_action( 'wp_enqueue_scripts', array( $this, 'revolut_enqueue_payment_request_scripts' ) ); 55 }56 57 /**58 * Get express checkout params59 */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 }75 54 } 76 55 … … 171 150 $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( wp_unslash( $_POST['payment_method'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing 172 151 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() ) ) { 174 163 return true; 175 164 } … … 419 408 check_ajax_referer( 'wc-revolut-pr-add-to-cart', 'security' ); 420 409 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 427 410 if ( ! defined( 'WOOCOMMERCE_CART' ) ) { 428 411 define( 'WOOCOMMERCE_CART', true ); … … 432 415 433 416 $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;435 417 $qty = isset( $_POST['qty'] ) ? wc_clean( wp_unslash( $_POST['qty'] ) ) : 0; 436 418 $is_add_to_cart_action = isset( $_POST['add_to_cart'] ) ? wc_clean( wp_unslash( $_POST['add_to_cart'] ) ) : 0; … … 457 439 WC()->cart->calculate_totals(); 458 440 459 $total_amount = $this->update_revolut_order_with_cart_total( $revolut_public_id, $is_revolut_pay );460 441 $is_cart_empty = ! WC()->cart->is_empty(); 461 442 … … 464 445 } 465 446 466 $data['total']['amount'] = $t otal_amount;447 $data['total']['amount'] = $this->get_revolut_order_total( WC()->cart->get_total( '' ), get_woocommerce_currency() ); 467 448 $data['checkout_nonce'] = wp_create_nonce( 'woocommerce-process_checkout' ); 468 449 $data['status'] = 'success'; … … 486 467 487 468 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 }494 469 495 470 $shipping_address = filter_input_array( … … 511 486 } 512 487 513 $total_amount = $this->update_revolut_order_with_cart_total( $revolut_public_id );514 515 488 $data['success'] = true; 516 489 $data['status'] = 'success'; 517 $data['total']['amount'] = $t otal_amount;490 $data['total']['amount'] = $this->get_revolut_order_total( WC()->cart->get_total( '' ), get_woocommerce_currency() ); 518 491 $data['shippingOptions'] = $shipping_options; 519 492 … … 542 515 } 543 516 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 550 517 $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); 551 518 $this->update_shipping_method( $shipping_method ); … … 553 520 WC()->cart->calculate_totals(); 554 521 555 $total_amount = $this->update_revolut_order_with_cart_total( $revolut_public_id );556 557 522 $data['success'] = true; 558 523 $data['status'] = 'success'; 559 $data['total']['amount'] = $t otal_amount;524 $data['total']['amount'] = $this->get_revolut_order_total( WC()->cart->get_total( '' ), get_woocommerce_currency() ); 560 525 wp_send_json( $data ); 561 526 } catch ( Exception $e ) { -
revolut-gateway-for-woocommerce/trunk/includes/traits/wc-revolut-express-checkout-helper-trait.php
r3025245 r3068486 306 306 public function get_wc_revolut_payment_request_params() { 307 307 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(); 313 309 $revolut_payment_request_settings = get_option( 'woocommerce_revolut_payment_request_settings', array() ); 314 310 $revolut_pay_settings = get_option( 'woocommerce_revolut_pay_settings', array() ); 315 311 316 312 return array( 317 'total' => $total,318 313 'currency' => $currency, 319 314 'locale' => $this->get_lang_iso_code(), 320 315 'publicToken' => $this->get_merchant_public_api_key(), 321 316 'ajax_url' => WC_AJAX::get_endpoint( '%%wc_revolut_gateway_ajax_endpoint%%' ), 322 'revolut_public_id' => $revolut_public_id,323 317 'revolut_pay_origin_url' => str_replace( array( 'https://', 'http://' ), '', get_site_url() ), 324 318 '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 861 861 862 862 /** 863 * Check order status863 * Get available card brands 864 864 * 865 865 * @param string $amount order amount. … … 882 882 883 883 /** 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¤cy=$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 /** 884 905 * Check the current page 885 906 */ … … 892 913 } 893 914 } 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 } 894 942 } -
revolut-gateway-for-woocommerce/trunk/readme.txt
r3047921 r3068486 3 3 Tags: revolut, revolut business, revolut pay, payments, gateway, payment gateway, credit card, card 4 4 Requires at least: 4.4 5 Tested up to: 6. 36 Stable tag: 4.1 0.15 Tested up to: 6.5 6 Stable tag: 4.11.0 7 7 Requires PHP: 7.0 8 8 License: GPLv2 or later … … 98 98 99 99 == 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 100 105 = 4.10.1 = 101 106 * Fixed card gateway issue
Note: See TracChangeset
for help on using the changeset viewer.