Merge pull request #3405 from woocommerce/PCP-4254-inbox-classic-ux-mexico-installments-new-ux-updates

Add Mexico installments notice in Classic UX and WooCommerce Inbox notifications
This commit is contained in:
Emili Castells 2025-05-22 17:16:35 +02:00 committed by GitHub
commit 2e710bbed6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 201 additions and 28 deletions

View file

@ -7,6 +7,8 @@
* Enhancement - Enhance the accessibility of the new Settings UI #3294
* Enhancement - Add capture pre-conditions for card payment source #3300
* Enhancement - Enable all/Disable all toggle next to Alternative Payment methods on Payment Methods tab #3321
* Enhancement - Add installment notifications for Mexico store locations #3404, #3405
* Fix - Various issues for Mexico store locations during onboarding & plugin configuration #3403
* Fix - APFS plugin triggers incorrect renewal date for simple products as subscriptions #3272
* Fix - PayPal Smart Button incompatible with WooCommerce Subscription Switching #3291
* Fix - Fastlane gateway visible on Pay for Order page #3293

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\AdminNotices;
use WooCommerce\PayPalCommerce\AdminNotices\Notes\MexicoInstallmentsNote;
use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
@ -110,6 +111,16 @@ class AdminNotices implements ServiceModule, ExtendingModule, ExecutableModule {
}
);
add_action(
'woocommerce_init',
function() {
if ( is_admin() && is_callable( array( WC(), 'is_wc_admin_active' ) ) && WC()->is_wc_admin_active() && class_exists( 'Automattic\WooCommerce\Admin\Notes\Notes' ) ) {
MexicoInstallmentsNote::init();
}
}
);
return true;
}
}

View file

@ -0,0 +1,122 @@
<?php
/**
* Inbox Note for Mexico Installments feature.
*
* @package WooCommerce\PayPalCommerce\AdminNotices\Notes
*/
declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\AdminNotices\Notes;
use Automattic\WooCommerce\Admin\Notes\Note;
use Automattic\WooCommerce\Admin\Notes\NotesUnavailableException;
use Automattic\WooCommerce\Admin\Notes\NoteTraits;
use Exception;
/**
* Class MexicoInstallmentsNote
*/
class MexicoInstallmentsNote {
use NoteTraits;
/**
* Name of the note for use in the database.
*/
const NOTE_NAME = 'ppcp-mexico-installments-note';
/**
* Note initialization.
*/
public static function init(): void {
try {
/**
* The method exists in the NoteTraits trait.
*
* @psalm-suppress UndefinedMethod
*/
self::possibly_add_note();
} catch ( Exception $e ) {
return;
}
}
/**
* Add the note if it passes predefined conditions.
*
* @throws NotesUnavailableException Throws exception when notes are unavailable.
*/
public static function possibly_add_note(): void {
$note = self::get_note();
if ( ! self::can_be_added() ) {
return;
}
$note->save();
}
/**
* Returns a new Note.
*
* @return Note
*/
public static function get_note(): Note {
$note = new Note();
$note->set_name( self::NOTE_NAME );
$note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
$note->set_source( 'woocommerce-paypal-payments' );
$note->set_title(
__( 'Enable Installments with PayPal', 'woocommerce-paypal-payments' )
);
$note->set_content(
sprintf(
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag. %3$s and %4$s are the opening and closing of HTML <p> tag.
__(
'Allow your customers to pay in installments without interest while you receive the full payment in a single transaction.*
%3$sActivate your Installments without interest with PayPal.%4$s
%3$sYou will receive the full payment minus the applicable PayPal fee. See %1$sterms and conditions%2$s.%4$s',
'woocommerce-paypal-payments'
),
'<a href="https://www.paypal.com/mx/webapps/mpp/merchant-fees" target="_blank">',
'</a>',
'<p>',
'</p>'
)
);
$note->add_action(
'enable-installments-action-link',
__( 'Enable Installments', 'woocommerce-paypal-payments' ),
esc_url( 'https://www.paypal.com/businessmanage/preferences/installmentplan' ),
Note::E_WC_ADMIN_NOTE_UNACTIONED,
true
);
return $note;
}
/**
* Checks if a note can and should be added.
*
* @return bool
* @throws NotesUnavailableException Throws exception when notes are unavailable.
*/
public static function can_be_added(): bool {
$country = wc_get_base_location()['country'] ?? '';
if ( $country !== 'MX' ) {
return false;
}
/**
* The method exists in the NoteTraits trait.
*
* @psalm-suppress UndefinedMethod
*/
if ( self::note_exists() ) {
return false;
}
return true;
}
}

View file

@ -1162,6 +1162,37 @@ return array(
'gateway' => 'dcc',
'input_class' => $container->get( 'wcgateway.helper.vaulting-scope' ) ? array() : array( 'ppcp-disabled-checkbox' ),
),
'mexico_installments' => array(
'heading' => __( 'Installments', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-heading',
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'paypal',
'description' => sprintf(
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag. %3$s and %4$s are the opening and closing of HTML <p> tag.
__(
'Allow your customers to pay in installments without interest while you receive the full payment in a single transaction.*
%3$sTerms and conditions: *You will receive the full payment minus the applicable PayPal fee. See %1$sterms and conditions%2$s.%4$s',
'woocommerce-paypal-payments'
),
'<a href="https://www.paypal.com/mx/webapps/mpp/merchant-fees" target="_blank">',
'</a>',
'<p class="description">',
'</p>'
),
),
'mexico_installments_action_link' => array(
'title' => __( 'Activate your Installments', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-text',
'text' => '<a href="https://www.paypal.com/businessmanage/preferences/installmentplan" target="_blank" class="button ppcp-refresh-feature-status">' . esc_html__( 'Enable Installments', 'woocommerce-paypal-payments' ) . '</a>',
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'paypal',
),
'paypal_saved_payments' => array(
'heading' => __( 'Saved payments', 'woocommerce-paypal-payments' ),
'description' => sprintf(
@ -1255,6 +1286,11 @@ return array(
$fields['disable_cards']['options'] = $card_options;
$fields['card_icons']['options'] = array_merge( $dark_versions, $card_options );
if ( $container->get( 'api.shop.country' ) !== 'MX' ) {
unset( $fields['mexico_installments'] );
unset( $fields['mexico_installments_action_link'] );
}
return $fields;
},

View file

@ -163,6 +163,8 @@ If you encounter issues with the PayPal buttons not appearing after an update, p
* Enhancement - Enhance the accessibility of the new Settings UI #3294
* Enhancement - Add capture pre-conditions for card payment source #3300
* Enhancement - Enable all/Disable all toggle next to Alternative Payment methods on Payment Methods tab #3321
* Enhancement - Add installment notifications for Mexico store locations #3404, #3405
* Fix - Various issues for Mexico store locations during onboarding & plugin configuration #3403
* Fix - APFS plugin triggers incorrect renewal date for simple products as subscriptions #3272
* Fix - PayPal Smart Button incompatible with WooCommerce Subscription Switching #3291
* Fix - Fastlane gateway visible on Pay for Order page #3293