mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Merge branch 'trunk' into PCP-4853-fix-vaulting
This commit is contained in:
commit
47773ab705
9 changed files with 66 additions and 16 deletions
|
@ -682,6 +682,11 @@ return array(
|
|||
'GB' => $default_currencies,
|
||||
'US' => $default_currencies,
|
||||
'NO' => $default_currencies,
|
||||
'YT' => $default_currencies,
|
||||
'RE' => $default_currencies,
|
||||
'GP' => $default_currencies,
|
||||
'GF' => $default_currencies,
|
||||
'MQ' => $default_currencies,
|
||||
)
|
||||
);
|
||||
},
|
||||
|
|
|
@ -78,7 +78,7 @@ return array(
|
|||
'RE',
|
||||
'GP',
|
||||
'GF',
|
||||
'MQ'
|
||||
'MQ',
|
||||
)
|
||||
);
|
||||
},
|
||||
|
|
|
@ -78,6 +78,11 @@ return array(
|
|||
'SE',
|
||||
'GB',
|
||||
'US',
|
||||
'YT',
|
||||
'RE',
|
||||
'GP',
|
||||
'GF',
|
||||
'MQ',
|
||||
)
|
||||
);
|
||||
},
|
||||
|
|
|
@ -120,8 +120,12 @@ return array(
|
|||
return new PaymentSettings();
|
||||
},
|
||||
'settings.data.settings' => static function ( ContainerInterface $container ) : SettingsModel {
|
||||
$environment = $container->get( 'settings.environment' );
|
||||
assert( $environment instanceof Environment );
|
||||
|
||||
return new SettingsModel(
|
||||
$container->get( 'settings.service.sanitizer' )
|
||||
$container->get( 'settings.service.sanitizer' ),
|
||||
$environment->is_sandbox() ? $container->get( 'wcgateway.settings.invoice-prefix-random' ) : $container->get( 'wcgateway.settings.invoice-prefix' )
|
||||
);
|
||||
},
|
||||
'settings.data.paylater-messaging' => static function ( ContainerInterface $container ) : array {
|
||||
|
|
|
@ -47,14 +47,24 @@ class SettingsModel extends AbstractDataModel {
|
|||
*/
|
||||
protected DataSanitizer $sanitizer;
|
||||
|
||||
/**
|
||||
* Invoice prefix.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $invoice_prefix;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param DataSanitizer $sanitizer Data sanitizer service.
|
||||
* @param string $invoice_prefix Invoice prefix.
|
||||
* @throws RuntimeException If the OPTION_KEY is not defined in the child class.
|
||||
*/
|
||||
public function __construct( DataSanitizer $sanitizer ) {
|
||||
$this->sanitizer = $sanitizer;
|
||||
public function __construct( DataSanitizer $sanitizer, string $invoice_prefix ) {
|
||||
$this->sanitizer = $sanitizer;
|
||||
$this->invoice_prefix = $invoice_prefix;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -66,7 +76,7 @@ class SettingsModel extends AbstractDataModel {
|
|||
protected function get_defaults() : array {
|
||||
return array(
|
||||
// Free-form string values.
|
||||
'invoice_prefix' => '',
|
||||
'invoice_prefix' => $this->invoice_prefix,
|
||||
'brand_name' => '',
|
||||
'soft_descriptor' => '',
|
||||
|
||||
|
|
|
@ -269,7 +269,6 @@ class SettingsDataManager {
|
|||
// Enable BCDC for business sellers without ACDC.
|
||||
$this->payment_methods->toggle_method_state( CardButtonGateway::ID, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow plugins to modify apm payment gateway states before saving.
|
||||
*
|
||||
|
|
|
@ -576,7 +576,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
|||
// Enable APMs after onboarding if the country is compatible.
|
||||
add_action(
|
||||
'woocommerce_paypal_payments_toggle_payment_gateways_apms',
|
||||
function ( PaymentSettings $payment_methods, array $methods_apm ) use ( $container ) {
|
||||
function ( PaymentSettings $payment_methods, array $methods_apm, ConfigurationFlagsDTO $flags ) use ( $container ) {
|
||||
|
||||
$general_settings = $container->get( 'settings.data.general' );
|
||||
assert( $general_settings instanceof GeneralSettings );
|
||||
|
@ -586,6 +586,11 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
|||
|
||||
// Enable all APM methods.
|
||||
foreach ( $methods_apm as $method ) {
|
||||
if ( $flags->use_card_payments === false ) {
|
||||
$payment_methods->toggle_method_state( $method['id'], $flags->use_card_payments );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip PayUponInvoice if merchant is not in Germany.
|
||||
if ( PayUponInvoiceGateway::ID === $method['id'] && 'DE' !== $merchant_country ) {
|
||||
continue;
|
||||
|
@ -606,7 +611,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
|||
}
|
||||
},
|
||||
10,
|
||||
2
|
||||
3
|
||||
);
|
||||
|
||||
// Toggle payment gateways after onboarding based on flags.
|
||||
|
|
|
@ -2092,4 +2092,29 @@ return array(
|
|||
'wcgateway.settings.admin-settings-enabled' => static function( ContainerInterface $container ): bool {
|
||||
return $container->has( 'settings.url' ) && ! SettingsModule::should_use_the_old_ui();
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a prefix for the site, ensuring the same site always gets the same prefix (unless the URL changes).
|
||||
*/
|
||||
'wcgateway.settings.invoice-prefix' => static function( ContainerInterface $container ): string {
|
||||
$site_url = get_site_url( get_current_blog_id() );
|
||||
$hash = md5( $site_url );
|
||||
$letters = preg_replace( '~\d~', '', $hash ) ?? '';
|
||||
$prefix = substr( $letters, 0, 6 );
|
||||
|
||||
return $prefix ? $prefix . '-' : '';
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns random 6 characters length alphabetic prefix, followed by a hyphen.
|
||||
*/
|
||||
'wcgateway.settings.invoice-prefix-random' => static function( ContainerInterface $container ): string {
|
||||
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$prefix = '';
|
||||
for ( $i = 0; $i < 6; $i++ ) {
|
||||
$prefix .= $characters[ wp_rand( 0, strlen( $characters ) - 1 ) ];
|
||||
}
|
||||
|
||||
return $prefix . '-';
|
||||
},
|
||||
);
|
||||
|
|
|
@ -49,6 +49,9 @@ return function ( ContainerInterface $container, array $fields ): array {
|
|||
$onboarding_send_only_notice_renderer = $container->get( 'onboarding.render-send-only-notice' );
|
||||
assert( $onboarding_send_only_notice_renderer instanceof OnboardingSendOnlyNoticeRenderer );
|
||||
|
||||
$environment = $container->get( 'settings.environment' );
|
||||
assert( $environment instanceof Environment );
|
||||
|
||||
$is_send_only_country = $container->get( 'wcgateway.is-send-only-country' );
|
||||
$onboarding_elements_class = $is_send_only_country ? 'hide' : 'ppcp-onboarding-element';
|
||||
$send_only_country_notice_class = $is_send_only_country ? 'ppcp-onboarding-element' : 'hide';
|
||||
|
@ -510,13 +513,7 @@ return function ( ContainerInterface $container, array $fields ): array {
|
|||
'custom_attributes' => array(
|
||||
'pattern' => '[a-zA-Z_\\-]+',
|
||||
),
|
||||
'default' => ( static function (): string {
|
||||
$site_url = get_site_url( get_current_blog_id() );
|
||||
$hash = md5( $site_url );
|
||||
$letters = preg_replace( '~\d~', '', $hash ) ?? '';
|
||||
$prefix = substr( $letters, 0, 6 );
|
||||
return $prefix ? $prefix . '-' : '';
|
||||
} )(),
|
||||
'default' => $environment->is_sandbox() ? $container->get( 'wcgateway.settings.invoice-prefix-random' ) : $container->get( 'wcgateway.settings.invoice-prefix' ),
|
||||
'screens' => array(
|
||||
State::STATE_START,
|
||||
State::STATE_ONBOARDED,
|
||||
|
@ -539,7 +536,7 @@ return function ( ContainerInterface $container, array $fields ): array {
|
|||
'requirements' => array(),
|
||||
'gateway' => Settings::CONNECTION_TAB_ID,
|
||||
),
|
||||
'stay_updated' => array(
|
||||
'stay_updated' => array(
|
||||
'title' => __( 'Stay Updated', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue