Skip to content

Commit

Permalink
Merge branch 'develop' into fix/phpstan-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
timur27 authored May 23, 2024
2 parents a31fcc4 + 100575d commit 4986fb9
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 78 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-blocks-checkout-ece-error-when-prb-disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix ECE error in the blocks checkout when PRBs are disabled.
5 changes: 5 additions & 0 deletions changelog/fix-blocks-page-detection-for-woopay
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fix
Comment: Fixes an unreleased bug


4 changes: 4 additions & 0 deletions changelog/fix-settings-notices-consistency
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

fix: settings notices consistency
4 changes: 4 additions & 0 deletions changelog/update-pass-previous-exception-with-exception
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: update

Pass previous exception with exception
5 changes: 5 additions & 0 deletions changelog/update-sandbox-mode-notice-tooltip-copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: update
Comment: Just updating the copy of the tooltip.


Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const expressCheckoutIframe = async ( api, context, emailSelector ) => {
userEmail = email;
urlParams.append( 'email', email );
}
urlParams.append( 'is_blocks', !! wcSettings.wcBlocksConfig );
urlParams.append( 'is_blocks', !! window.wcSettings?.wcBlocksConfig );
urlParams.append( 'is_express', 'true' );
urlParams.append( 'express_context', context );
urlParams.append( 'source_url', window.location.href );
Expand Down
14 changes: 12 additions & 2 deletions client/express-checkout/blocks/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global wcpayConfig */
/* global wcpayConfig, wcpayExpressCheckoutParams */

/**
* Internal dependencies
Expand All @@ -16,7 +16,17 @@ const expressCheckoutElementPaymentMethod = ( api ) => ( {
supports: {
features: getConfig( 'features' ),
},
canMakePayment: () => wcpayConfig.isExpressCheckoutElementEnabled,
canMakePayment: () => {
if ( typeof wcpayExpressCheckoutParams === 'undefined' ) {
return false;
}

if ( typeof wcpayConfig !== 'undefined' ) {
return wcpayConfig.isExpressCheckoutElementEnabled;
}

return false;
},
} );

export default expressCheckoutElementPaymentMethod;
7 changes: 3 additions & 4 deletions client/overview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const OverviewSandboxModeNotice = ( { ctaAction = () => {} } ) => {
/* translators: %1$s: WooPayments */
__(
// eslint-disable-next-line max-len
'{{strong}}%1$s is in sandbox mode.{{/strong}} To accept real transactions, {{switchToLiveLink}}set up a live %1$s account{{/switchToLiveLink}}.{{learnMoreIcon/}}',
'{{strong}}%1$s is in sandbox mode.{{/strong}} To accept real transactions, {{switchToLiveLink}}set up a live %1$s account.{{/switchToLiveLink}} {{learnMoreIcon/}}',
'woocommerce-payments'
),
'WooPayments'
Expand All @@ -80,21 +80,20 @@ const OverviewSandboxModeNotice = ( { ctaAction = () => {} } ) => {
'Learn more about sandbox mode',
'woocommerce-payments'
) }
maxWidth={ '315px' }
maxWidth={ '250px' }
content={
<>
{ interpolateComponents( {
mixedString: sprintf(
/* translators: %1$s: WooPayments */
__(
// eslint-disable-next-line max-len
'In sandbox mode, personal/business verifications and checkout payments are simulated. Find out what works best for you by {{strong}}testing all the %1$s options and flows.{{/strong}} {{learnMoreLink}}Learn more{{/learnMoreLink}}',
'Sandbox mode gives you access to all %1$s features while checkout transactions are simulated. {{learnMoreLink}}Learn more{{/learnMoreLink}}',
'woocommerce-payments'
),
'WooPayments'
),
components: {
strong: <strong />,
learnMoreLink: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
<Link
Expand Down
7 changes: 5 additions & 2 deletions client/payment-request/blocks/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global wcpayConfig */
/* global wcpayConfig, wcpayPaymentRequestParams */

/**
* Internal dependencies
Expand Down Expand Up @@ -28,7 +28,10 @@ const paymentRequestPaymentMethod = ( api ) => ( {
return false;
}

if ( wcpayConfig.isExpressCheckoutElementEnabled ) {
if (
typeof wcpayConfig !== 'undefined' &&
wcpayConfig.isExpressCheckoutElementEnabled
) {
return false;
}

Expand Down
6 changes: 0 additions & 6 deletions client/settings/express-checkout-settings/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,6 @@
}
}

.express-checkout__notice {
margin-left: 0;
margin-right: 0;
border: 0;
}

.payment-method-settings {
&__option-help-text {
color: #757575;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe( 'PaymentRequestSettings', () => {

expect(
screen.queryByText(
'One or more of your extensions alters checkout fields. This might cause issues with this payment method.'
'Your custom checkout fields may not be compatible with these payment methods.'
)
).toBeInTheDocument();
} );
Expand All @@ -276,7 +276,7 @@ describe( 'PaymentRequestSettings', () => {

expect(
screen.queryByText(
'One or more of your extensions alters checkout fields. This might cause issues with this payment method.'
'Your custom checkout fields may not be compatible with these payment methods.'
)
).not.toBeInTheDocument();
} );
Expand Down
6 changes: 0 additions & 6 deletions client/settings/express-checkout/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
padding: 24px;
background: #fff;

.gridicons-notice-outline {
fill: #f0b849;
margin-bottom: -5px;
margin-right: 16px;
}

&__label-container {
display: flex;
flex-wrap: wrap;
Expand Down
2 changes: 1 addition & 1 deletion client/settings/express-checkout/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ describe( 'ExpressCheckout', () => {

expect(
screen.queryByText(
'One or more of your extensions alters checkout fields. This might cause issues with this payment method.'
'Your custom checkout fields may not be compatible with these payment methods.'
)
).toBeInTheDocument();
} );
Expand Down
60 changes: 21 additions & 39 deletions client/settings/settings-warnings/incompatibility-notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,30 @@ import interpolateComponents from '@automattic/interpolate-components';
/**
* Internal dependencies
*/
import { Notice } from '@wordpress/components';
import NoticeOutlineIcon from 'gridicons/dist/notice-outline';
import './style.scss';
import InlineNotice from 'wcpay/components/inline-notice';

const IncompatibilityNotice = ( { message, learnMoreLinkHref } ) => (
<Notice
status="warning"
isDismissible={ false }
className="express-checkout__notice express-checkout__incompatibility-warning"
>
<span>
<NoticeOutlineIcon
style={ {
color: '#F0B849',
fill: 'currentColor',
marginBottom: '-5px',
marginRight: '10px',
} }
size={ 20 }
/>
</span>
<span>
{ message }
<br />
{ interpolateComponents( {
mixedString: __(
'{{learnMoreLink}}Learn More{{/learnMoreLink}}',
'woocommerce-payments'
<InlineNotice status="warning" icon={ true } isDismissible={ false }>
{ message }
<br />
{ interpolateComponents( {
mixedString: __(
'{{learnMoreLink}}Learn More{{/learnMoreLink}}',
'woocommerce-payments'
),
components: {
learnMoreLink: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
<a
target="_blank"
rel="noreferrer"
href={ learnMoreLinkHref }
/>
),
components: {
learnMoreLink: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
<a
target="_blank"
rel="noreferrer"
href={ learnMoreLinkHref }
/>
),
},
} ) }
</span>
</Notice>
},
} ) }
</InlineNotice>
);

export const WooPayIncompatibilityNotice = () => (
Expand All @@ -64,7 +46,7 @@ export const WooPayIncompatibilityNotice = () => (
export const ExpressCheckoutIncompatibilityNotice = () => (
<IncompatibilityNotice
message={ __(
'One or more of your extensions alters checkout fields. This might cause issues with this payment method.',
'Your custom checkout fields may not be compatible with these payment methods.',
'woocommerce-payments'
) }
// eslint-disable-next-line max-len
Expand Down
11 changes: 5 additions & 6 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use WCPay\Constants\Intent_Status;
use WCPay\Constants\Payment_Type;
use WCPay\Constants\Payment_Method;
use WCPay\Exceptions\{ Add_Payment_Method_Exception, Amount_Too_Small_Exception, Process_Payment_Exception, Intent_Authentication_Exception, API_Exception, Invalid_Address_Exception};
use WCPay\Exceptions\{ Add_Payment_Method_Exception, Amount_Too_Small_Exception, Process_Payment_Exception, Intent_Authentication_Exception, API_Exception, Invalid_Address_Exception, Fraud_Prevention_Enabled_Exception, Invalid_Phone_Number_Exception, Rate_Limiter_Enabled_Exception };
use WCPay\Core\Server\Request\Cancel_Intention;
use WCPay\Core\Server\Request\Capture_Intention;
use WCPay\Core\Server\Request\Create_And_Confirm_Intention;
Expand Down Expand Up @@ -1128,7 +1128,6 @@ public function new_process_payment( WC_Order $order ) {
* @param int $order_id Order ID to process the payment for.
*
* @return array|null An array with result of payment and redirect URL, or nothing.
* @throws Process_Payment_Exception Error processing the payment.
* @throws Exception Error processing the payment.
*/
public function process_payment( $order_id ) {
Expand All @@ -1141,7 +1140,7 @@ public function process_payment( $order_id ) {

try {
if ( 20 < strlen( $order->get_billing_phone() ) ) {
throw new Process_Payment_Exception(
throw new Invalid_Phone_Number_Exception(
__( 'Invalid phone number.', 'woocommerce-payments' ),
'invalid_phone_number'
);
Expand All @@ -1151,15 +1150,15 @@ public function process_payment( $order_id ) {
$fraud_prevention_service = Fraud_Prevention_Service::get_instance();
// phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( $fraud_prevention_service->is_enabled() && ! $fraud_prevention_service->verify_token( $_POST['wcpay-fraud-prevention-token'] ?? null ) ) {
throw new Process_Payment_Exception(
throw new Fraud_Prevention_Enabled_Exception(
__( "We're not able to process this payment. Please refresh the page and try again.", 'woocommerce-payments' ),
'fraud_prevention_enabled'
);
}
}

if ( $this->failed_transaction_rate_limiter->is_limited() ) {
throw new Process_Payment_Exception(
throw new Rate_Limiter_Enabled_Exception(
__( 'Your payment was not processed.', 'woocommerce-payments' ),
'rate_limiter_enabled'
);
Expand Down Expand Up @@ -1281,7 +1280,7 @@ public function process_payment( $order_id ) {

// Re-throw the exception after setting everything up.
// This makes the error notice show up both in the regular and block checkout.
throw new Exception( WC_Payments_Utils::get_filtered_error_message( $e, $blocked_by_fraud_rules ) );
throw new Exception( WC_Payments_Utils::get_filtered_error_message( $e, $blocked_by_fraud_rules ), 0, $e );
}
}

Expand Down
3 changes: 3 additions & 0 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,13 @@ public static function init() {
include_once __DIR__ . '/exceptions/class-intent-authentication-exception.php';
include_once __DIR__ . '/exceptions/class-invalid-payment-method-exception.php';
include_once __DIR__ . '/exceptions/class-process-payment-exception.php';
include_once __DIR__ . '/exceptions/class-invalid-phone-number-exception.php';
include_once __DIR__ . '/exceptions/class-invalid-webhook-data-exception.php';
include_once __DIR__ . '/exceptions/class-invalid-price-exception.php';
include_once __DIR__ . '/exceptions/class-fraud-ruleset-exception.php';
include_once __DIR__ . '/exceptions/class-fraud-prevention-enabled-exception.php';
include_once __DIR__ . '/exceptions/class-order-not-found-exception.php';
include_once __DIR__ . '/exceptions/class-rate-limiter-enabled-exception.php';
include_once __DIR__ . '/constants/class-base-constant.php';
include_once __DIR__ . '/constants/class-country-code.php';
include_once __DIR__ . '/constants/class-currency-code.php';
Expand Down
16 changes: 16 additions & 0 deletions includes/exceptions/class-fraud-prevention-enabled-exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Class Fraud_Prevention_Enabled_Exception
*
* @package WooCommerce\Payments
*/

namespace WCPay\Exceptions;

defined( 'ABSPATH' ) || exit;

/**
* Exception for throwing an error when fraud prevension service is enabled.
*/
class Fraud_Prevention_Enabled_Exception extends Process_Payment_Exception {
}
16 changes: 16 additions & 0 deletions includes/exceptions/class-invalid-phone-number-exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Class Invalid_Phone_Number_Exception
*
* @package WooCommerce\Payments
*/

namespace WCPay\Exceptions;

defined( 'ABSPATH' ) || exit;

/**
* Exception for throwing an error when phone number is invalid.
*/
class Invalid_Phone_Number_Exception extends Process_Payment_Exception {
}
16 changes: 16 additions & 0 deletions includes/exceptions/class-rate-limiter-enabled-exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Class Rate_Limiter_Enabled_Exception
*
* @package WooCommerce\Payments
*/

namespace WCPay\Exceptions;

defined( 'ABSPATH' ) || exit;

/**
* Exception for throwing an error when rate limiter is enabled.
*/
class Rate_Limiter_Enabled_Exception extends Process_Payment_Exception {
}
Loading

0 comments on commit 4986fb9

Please sign in to comment.