Skip to content

Commit

Permalink
Merge branch 'develop' into cobranded-cards
Browse files Browse the repository at this point in the history
  • Loading branch information
gpressutto5 authored Apr 4, 2024
2 parents 5f0f8c4 + fc53894 commit 2a630ca
Show file tree
Hide file tree
Showing 22 changed files with 243 additions and 63 deletions.
2 changes: 1 addition & 1 deletion assets/images/payment-methods/afterpay-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions changelog/2024-03-30-01-19-36-005298
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Add an instructive error message when customer tries to use 2 different currencies for Stripe Billing subscriptions.
4 changes: 4 additions & 0 deletions changelog/fix-7866-tos-decline-busy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix Decline button state for Accept loading on ToS modal
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Change IP country rule after country settings are changed in WC settings page
4 changes: 4 additions & 0 deletions changelog/fix-8567-connect-page-payment-methods
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix payment icons on connect page (Klarna, Afterpay)
4 changes: 4 additions & 0 deletions changelog/fix-filesystem-phpcs-reports
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Ignore alternative function WordPress PHPCS sniffs in the GH workflows and tests
5 changes: 5 additions & 0 deletions changelog/fix-migrate-woopay-skipped-tracks-event
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: Complete WooPay Tracks event migration and cleanup migration related code


2 changes: 1 addition & 1 deletion client/checkout/woopay/email-input-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ export const handleWooPayEmailInput = async (
dispatchUserExistEvent( true );
}, 2000 );

recordUserEvent( 'woopay_skipped', {}, true );
recordUserEvent( 'woopay_skipped', {} );

searchParams.delete( 'skip_woopay' );

Expand Down
6 changes: 3 additions & 3 deletions client/connect-account-page/payment-methods.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import {
DiscoverIcon,
GooglePayIcon,
MastercardIcon,
SofortIcon,
VisaIcon,
WooIcon,
KlarnaIcon,
} from 'wcpay/payment-methods-icons';

const PaymentMethods: React.FC = () => {
Expand All @@ -38,14 +38,14 @@ const PaymentMethods: React.FC = () => {
<GooglePayIcon />
{ wcpaySettings.isWooPayStoreCountryAvailable && <WooIcon /> }
<WooIcon />
<SofortIcon />
<KlarnaIcon />
<AffirmIcon />
{ 'GB' === wcpaySettings?.connect?.country ? (
<ClearpayIcon />
) : (
<AfterpayIcon />
) }
<span>& more.</span>
<span>& more</span>
</div>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ exports[`ConnectAccountPage should render correctly 1`] = `
src="assets/images/payment-methods/woo.svg"
/>
<img
alt="Sofort"
alt="Klarna"
class="payment-method__icon"
src="assets/images/payment-methods/sofort.svg"
src="assets/images/payment-methods/klarna.svg"
/>
<img
alt="Affirm"
Expand All @@ -122,7 +122,7 @@ exports[`ConnectAccountPage should render correctly 1`] = `
src="assets/images/payment-methods/afterpay-logo.svg"
/>
<span>
& more.
& more
</span>
</div>
<div
Expand Down Expand Up @@ -374,9 +374,9 @@ exports[`ConnectAccountPage should render correctly with WooPay eligible 1`] = `
src="assets/images/payment-methods/woo.svg"
/>
<img
alt="Sofort"
alt="Klarna"
class="payment-method__icon"
src="assets/images/payment-methods/sofort.svg"
src="assets/images/payment-methods/klarna.svg"
/>
<img
alt="Affirm"
Expand All @@ -389,7 +389,7 @@ exports[`ConnectAccountPage should render correctly with WooPay eligible 1`] = `
src="assets/images/payment-methods/afterpay-logo.svg"
/>
<span>
& more.
& more
</span>
</div>
<div
Expand Down Expand Up @@ -598,9 +598,9 @@ exports[`ConnectAccountPage should render correctly with an incentive 1`] = `
src="assets/images/payment-methods/woo.svg"
/>
<img
alt="Sofort"
alt="Klarna"
class="payment-method__icon"
src="assets/images/payment-methods/sofort.svg"
src="assets/images/payment-methods/klarna.svg"
/>
<img
alt="Affirm"
Expand All @@ -613,7 +613,7 @@ exports[`ConnectAccountPage should render correctly with an incentive 1`] = `
src="assets/images/payment-methods/afterpay-logo.svg"
/>
<span>
& more.
& more
</span>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const StripeBillingToggle: React.FC< Props > = ( { onChange } ) => {
),
},
} ) }
data-testid={ 'stripe-billing-toggle' }
/>
);
};
Expand Down
6 changes: 5 additions & 1 deletion client/tos/modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ const TosModalUI = ( { onAccept, onDecline, isBusy, hasError } ) => {
{ message }
</div>
<div className="woocommerce-payments__tos-footer">
<Button isSecondary onClick={ onDecline } isBusy={ isBusy }>
<Button
isSecondary
onClick={ onDecline }
disabled={ isBusy }
>
{ __( 'Decline', 'woocommerce-payments' ) }
</Button>

Expand Down
5 changes: 1 addition & 4 deletions client/tracks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ export const recordEvent = (
*
* @param {string} eventName Name of the event.
* @param {Object} [eventProperties] Event properties (optional).
* @param {boolean} isLegacy Event properties (optional).
*/
export const recordUserEvent = (
eventName: string,
eventProperties: Record< string, unknown > = {},
isLegacy = false
eventProperties: Record< string, unknown > = {}
): void => {
const nonce =
getConfig( 'platformTrackerNonce' ) ??
Expand All @@ -80,7 +78,6 @@ export const recordUserEvent = (
body.append( 'action', 'platform_tracks' );
body.append( 'tracksEventName', eventName );
body.append( 'tracksEventProp', JSON.stringify( eventProperties ) );
body.append( 'isLegacy', JSON.stringify( isLegacy ) ); // formData does not allow appending booleans, so we stringify it - it is parsed back to a boolean on the PHP side.
fetch( ajaxUrl, {
method: 'post',
body,
Expand Down
44 changes: 44 additions & 0 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ public function init_hooks() {
add_action( 'woocommerce_update_order', [ $this, 'schedule_order_tracking' ], 10, 2 );

add_filter( 'rest_request_before_callbacks', [ $this, 'remove_all_actions_on_preflight_check' ], 10, 3 );

add_action( 'woocommerce_settings_save_general', [ $this, 'update_fraud_rules_based_on_general_options' ], 20 );
}

$this->maybe_init_subscriptions_hooks();
Expand Down Expand Up @@ -2976,6 +2978,48 @@ protected function maybe_refresh_fraud_protection_settings() {
}
}

/**
* Updates the fraud rules depending on some settings when those settings have changed.
*
* @return void This is a readonly action.
*/
public function update_fraud_rules_based_on_general_options() {
// If the protection level is not "advanced", no need to run this, because it won't contain the IP country filter.
if ( 'advanced' !== $this->get_current_protection_level() ) {
return;
}

// If the ruleset can't be parsed, skip updating.
$ruleset = $this->get_advanced_fraud_protection_settings();
if (
'error' === $ruleset
|| ! is_array( $ruleset )
|| ! Fraud_Risk_Tools::is_valid_ruleset_array( $ruleset )
) {
return;
}

$needs_update = false;
foreach ( $ruleset as &$rule_array ) {
if ( isset( $rule_array['key'] ) && Fraud_Risk_Tools::RULE_INTERNATIONAL_IP_ADDRESS === $rule_array['key'] ) {
$new_rule_array = Fraud_Risk_Tools::get_international_ip_address_rule()->to_array();
if ( isset( $rule_array['check'] )
&& isset( $new_rule_array['check'] )
&& wp_json_encode( $rule_array['check'] ) !== wp_json_encode( $new_rule_array['check'] )
) {
$rule_array = $new_rule_array;
$needs_update = true;
}
}
}

// Update the possibly changed values on the server, and the transient.
if ( $needs_update ) {
$this->payments_api_client->save_fraud_ruleset( $ruleset );
set_transient( 'wcpay_fraud_protection_settings', $ruleset, DAY_IN_SECONDS );
}
}

/**
* The get_icon() method from the WC_Payment_Gateway class wraps the icon URL into a prepared HTML element, but there are situations when this
* element needs to be rendered differently on the UI (e.g. additional styles or `display` property).
Expand Down
1 change: 1 addition & 0 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ public static function init() {
include_once __DIR__ . '/exceptions/class-add-payment-method-exception.php';
include_once __DIR__ . '/exceptions/class-amount-too-large-exception.php';
include_once __DIR__ . '/exceptions/class-amount-too-small-exception.php';
include_once __DIR__ . '/exceptions/class-cannot-combine-currencies-exception.php';
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';
Expand Down
18 changes: 3 additions & 15 deletions includes/class-woopay-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@
*/
class WooPay_Tracker extends Jetpack_Tracks_Client {

/**
* Legacy prefix used for WooPay user events
*
* @var string
*/
private static $legacy_user_prefix = 'woocommerceanalytics';

/**
* WCPay user event prefix
*
Expand Down Expand Up @@ -107,10 +100,7 @@ public function ajax_tracks() {
$tracks_data = $event_prop;
}
}
// Legacy events are shopper events that still use the woocommerceanalytics prefix.
// These need to be migrated to the wcpay prefix.
$is_legacy_event = isset( $_REQUEST['isLegacy'] ) ? rest_sanitize_boolean( wc_clean( wp_unslash( $_REQUEST['isLegacy'] ) ) ) : false;
$this->maybe_record_event( sanitize_text_field( wp_unslash( $_REQUEST['tracksEventName'] ) ), $tracks_data, $is_legacy_event );
$this->maybe_record_event( sanitize_text_field( wp_unslash( $_REQUEST['tracksEventName'] ) ), $tracks_data );

wp_send_json_success();
}
Expand All @@ -132,13 +122,11 @@ public function ajax_tracks_id() {
*
* @param string $event name of the event.
* @param array $data array of event properties.
* @param boolean $is_legacy indicate whether this is a legacy event.
*/
public function maybe_record_event( $event, $data = [], $is_legacy = true ) {
public function maybe_record_event( $event, $data = [] ) {
// Top level events should not be namespaced.
if ( '_aliasUser' !== $event ) {
$prefix = $is_legacy ? self::$legacy_user_prefix : self::$user_prefix;
$event = $prefix . '_' . $event;
$event = self::$user_prefix . '_' . $event;
}

return $this->tracks_record_event( $event, $data );
Expand Down
46 changes: 46 additions & 0 deletions includes/exceptions/class-cannot-combine-currencies-exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Class Cannot_Combine_Currencies_Exception
*
* @package WooCommerce\Payments
*/

namespace WCPay\Exceptions;

defined( 'ABSPATH' ) || exit;

/**
* Class representing Amount_Too_Small_Exception
*/
class Cannot_Combine_Currencies_Exception extends API_Exception {
/**
* Holds the attempted currency, extracted from the error message returned by the API.
*
* @var string
*/
private $currency;

/**
* Constructor
*
* @param string $message The Exception message to throw.
* @param string $currency The currency for which this is the minimum amount.
* @param int $http_code HTTP response code.
* @param int $code The Exception code.
* @param \Throwable $previous The previous exception used for the exception chaining.
*/
public function __construct( $message, $currency, $http_code, $code = 0, $previous = null ) {
$this->currency = $currency;

parent::__construct( $message, 'cannot_combine_currencies', $http_code, null, null, $code, $previous );
}

/**
* Returns the currency of the minumum required amount.
*
* @return string
*/
public function get_currency() {
return $this->currency;
}
}
Loading

0 comments on commit 2a630ca

Please sign in to comment.