🔀 Merge branch 'trunk'

This commit is contained in:
Philipp Stracker 2024-07-15 11:56:45 +02:00
commit c780b025a3
No known key found for this signature in database
15 changed files with 134 additions and 35 deletions

View file

@ -25,6 +25,10 @@ if (!defined('ABSPATH')) {
define('ABSPATH', ''); define('ABSPATH', '');
} }
if (!defined('PPCP_PAYPAL_BN_CODE')) {
define('PPCP_PAYPAL_BN_CODE', 'Woo_PPCP');
}
/** /**
* Cancel the next occurrence of a scheduled action. * Cancel the next occurrence of a scheduled action.
* *

View file

@ -723,6 +723,30 @@ return array(
'TWD', 'TWD',
'USD', 'USD',
), ),
'CN' => array(
'AUD',
'BRL',
'CAD',
'CHF',
'CZK',
'DKK',
'EUR',
'GBP',
'HKD',
'HUF',
'ILS',
'JPY',
'MXN',
'NOK',
'NZD',
'PHP',
'PLN',
'SEK',
'SGD',
'THB',
'TWD',
'USD',
),
'CY' => array( 'CY' => array(
'AUD', 'AUD',
'BRL', 'BRL',
@ -1416,6 +1440,10 @@ return array(
'visa' => array(), 'visa' => array(),
'amex' => array(), 'amex' => array(),
), ),
'CN' => array(
'mastercard' => array(),
'visa' => array(),
),
'CY' => array( 'CY' => array(
'mastercard' => array(), 'mastercard' => array(),
'visa' => array(), 'visa' => array(),

View file

@ -42,7 +42,7 @@ trait RequestTrait {
*/ */
$args = apply_filters( 'ppcp_request_args', $args, $url ); $args = apply_filters( 'ppcp_request_args', $args, $url );
if ( ! isset( $args['headers']['PayPal-Partner-Attribution-Id'] ) ) { if ( ! isset( $args['headers']['PayPal-Partner-Attribution-Id'] ) ) {
$args['headers']['PayPal-Partner-Attribution-Id'] = 'Woo_PPCP'; $args['headers']['PayPal-Partner-Attribution-Id'] = PPCP_PAYPAL_BN_CODE;
} }
$response = wp_remote_get( $url, $args ); $response = wp_remote_get( $url, $args );

View file

@ -140,12 +140,17 @@ class AxoModule implements ModuleInterface {
); );
add_action( add_action(
'init', 'wp_loaded',
function () use ( $c ) { function () use ( $c ) {
$module = $this; $module = $this;
$subscription_helper = $c->get( 'wc-subscriptions.helper' );
assert( $subscription_helper instanceof SubscriptionHelper );
// Check if the module is applicable, correct country, currency, ... etc. // Check if the module is applicable, correct country, currency, ... etc.
if ( ! $c->get( 'axo.eligible' ) || 'continuation' === $c->get( 'button.context' ) ) { if ( ! $c->get( 'axo.eligible' )
|| 'continuation' === $c->get( 'button.context' )
|| $subscription_helper->cart_contains_subscription() ) {
return; return;
} }
@ -334,15 +339,11 @@ class AxoModule implements ModuleInterface {
$is_axo_enabled = $settings->has( 'axo_enabled' ) && $settings->get( 'axo_enabled' ) ?? false; $is_axo_enabled = $settings->has( 'axo_enabled' ) && $settings->get( 'axo_enabled' ) ?? false;
$is_dcc_enabled = $settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' ) ?? false; $is_dcc_enabled = $settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' ) ?? false;
$subscription_helper = $c->get( 'wc-subscriptions.helper' );
assert( $subscription_helper instanceof SubscriptionHelper );
return ! is_user_logged_in() return ! is_user_logged_in()
&& CartCheckoutDetector::has_classic_checkout() && CartCheckoutDetector::has_classic_checkout()
&& $is_axo_enabled && $is_axo_enabled
&& $is_dcc_enabled && $is_dcc_enabled
&& ! $this->is_excluded_endpoint() && ! $this->is_excluded_endpoint();
&& ! $subscription_helper->cart_contains_subscription();
} }
/** /**

View file

@ -829,7 +829,9 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
*/ */
do_action( "ppcp_before_{$location_hook}_message_wrapper" ); do_action( "ppcp_before_{$location_hook}_message_wrapper" );
$messages_placeholder = '<div class="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>'; $bn_code = PPCP_PAYPAL_BN_CODE;
$messages_placeholder = '<div class="ppcp-messages" data-partner-attribution-id="' . esc_attr( $bn_code ) . '"></div>';
if ( is_array( $block_params ) && ( $block_params['blockName'] ?? false ) ) { if ( is_array( $block_params ) && ( $block_params['blockName'] ?? false ) ) {
$this->render_after_block( $this->render_after_block(
@ -1511,7 +1513,10 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
private function bn_code_for_context( string $context ): string { private function bn_code_for_context( string $context ): string {
$codes = $this->bn_codes(); $codes = $this->bn_codes();
return ( isset( $codes[ $context ] ) ) ? $codes[ $context ] : 'Woo_PPCP';
$bn_code = PPCP_PAYPAL_BN_CODE;
return ( isset( $codes[ $context ] ) ) ? $codes[ $context ] : $bn_code;
} }
/** /**
@ -1519,13 +1524,15 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
* *
* @return array * @return array
*/ */
private function bn_codes(): array { private function bn_codes() : array {
$bn_code = PPCP_PAYPAL_BN_CODE;
return array( return array(
'checkout' => 'Woo_PPCP', 'checkout' => $bn_code,
'cart' => 'Woo_PPCP', 'cart' => $bn_code,
'mini-cart' => 'Woo_PPCP', 'mini-cart' => $bn_code,
'product' => 'Woo_PPCP', 'product' => $bn_code,
); );
} }

View file

@ -150,6 +150,30 @@ return array(
'TWD', 'TWD',
'USD', 'USD',
), ),
'CN' => array(
'AUD',
'BRL',
'CAD',
'CHF',
'CZK',
'DKK',
'EUR',
'GBP',
'HKD',
'HUF',
'ILS',
'JPY',
'MXN',
'NOK',
'NZD',
'PHP',
'PLN',
'SEK',
'SGD',
'THB',
'TWD',
'USD',
),
'CY' => array( 'CY' => array(
'AUD', 'AUD',
'BRL', 'BRL',

View file

@ -28,7 +28,9 @@ class PayLaterBlockRenderer {
public function render( array $attributes, ContainerInterface $c ): string { public function render( array $attributes, ContainerInterface $c ): string {
if ( PayLaterBlockModule::is_block_enabled( $c->get( 'wcgateway.settings.status' ) ) ) { if ( PayLaterBlockModule::is_block_enabled( $c->get( 'wcgateway.settings.status' ) ) ) {
$html = '<div id="' . esc_attr( $attributes['id'] ?? '' ) . '" class="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>'; $bn_code = PPCP_PAYPAL_BN_CODE;
$html = '<div id="' . esc_attr( $attributes['id'] ?? '' ) . '" class="ppcp-messages" data-partner-attribution-id="' . esc_attr( $bn_code ) . '"></div>';
$processor = new \WP_HTML_Tag_Processor( $html ); $processor = new \WP_HTML_Tag_Processor( $html );

View file

@ -57,7 +57,7 @@ document.addEventListener( 'DOMContentLoaded', () => {
merchantClientId: PcpPayLaterConfigurator.merchantClientId, merchantClientId: PcpPayLaterConfigurator.merchantClientId,
partnerClientId: PcpPayLaterConfigurator.partnerClientId, partnerClientId: PcpPayLaterConfigurator.partnerClientId,
partnerName: 'WooCommerce', partnerName: 'WooCommerce',
bnCode: 'Woo_PPCP', bnCode: PcpPayLaterConfigurator.bnCode,
placements: [ placements: [
'cart', 'cart',
'checkout', 'checkout',

View file

@ -113,6 +113,8 @@ class PayLaterConfiguratorModule implements ModuleInterface {
$config_factory = $c->get( 'paylater-configurator.factory.config' ); $config_factory = $c->get( 'paylater-configurator.factory.config' );
assert( $config_factory instanceof ConfigFactory ); assert( $config_factory instanceof ConfigFactory );
$bn_code = PPCP_PAYPAL_BN_CODE;
wp_localize_script( wp_localize_script(
'ppcp-paylater-configurator', 'ppcp-paylater-configurator',
'PcpPayLaterConfigurator', 'PcpPayLaterConfigurator',
@ -130,6 +132,7 @@ class PayLaterConfiguratorModule implements ModuleInterface {
'config' => $config_factory->from_settings( $settings ), 'config' => $config_factory->from_settings( $settings ),
'merchantClientId' => $settings->get( 'client_id' ), 'merchantClientId' => $settings->get( 'client_id' ),
'partnerClientId' => $c->get( 'api.partner_merchant_id' ), 'partnerClientId' => $c->get( 'api.partner_merchant_id' ),
'bnCode' => $bn_code,
'publishButtonClassName' => 'ppcp-paylater-configurator-publishButton', 'publishButtonClassName' => 'ppcp-paylater-configurator-publishButton',
'headerClassName' => 'ppcp-paylater-configurator-header', 'headerClassName' => 'ppcp-paylater-configurator-header',
'subheaderClassName' => 'ppcp-paylater-configurator-subheader', 'subheaderClassName' => 'ppcp-paylater-configurator-subheader',

View file

@ -95,14 +95,16 @@ class PayLaterWCBlocksRenderer {
) { ) {
if ( PayLaterWCBlocksModule::is_placement_enabled( $c->get( 'wcgateway.settings.status' ), $location ) ) { if ( PayLaterWCBlocksModule::is_placement_enabled( $c->get( 'wcgateway.settings.status' ), $location ) ) {
$html = '<div id="' . esc_attr( $attributes['ppcpId'] ?? '' ) . '" class="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>'; $bn_code = PPCP_PAYPAL_BN_CODE;
$html = '<div id="' . esc_attr( $attributes['ppcpId'] ?? '' ) . '" class="ppcp-messages" data-partner-attribution-id="' . esc_attr( $bn_code ) . '"></div>';
$processor = new \WP_HTML_Tag_Processor( $html ); $processor = new \WP_HTML_Tag_Processor( $html );
if ( $processor->next_tag( 'div' ) ) { if ( $processor->next_tag( 'div' ) ) {
$processor->set_attribute( 'data-block-name', esc_attr( $attributes['blockId'] ?? '' ) ); $processor->set_attribute( 'data-block-name', esc_attr( $attributes['blockId'] ?? '' ) );
$processor->set_attribute( 'class', 'ppcp-messages' ); $processor->set_attribute( 'class', 'ppcp-messages' );
$processor->set_attribute( 'data-partner-attribution-id', 'Woo_PPCP' ); $processor->set_attribute( 'data-partner-attribution-id', $bn_code );
if ( $this->layout === 'flex' ) { if ( $this->layout === 'flex' ) {
$processor->set_attribute( 'data-pp-style-layout', 'flex' ); $processor->set_attribute( 'data-pp-style-layout', 'flex' );

View file

@ -109,34 +109,36 @@ class PayPalSubscriptionsModule implements ModuleInterface {
$product = wc_get_product( $product_id ); $product = wc_get_product( $product_id );
if ( ! ( is_a( $product, WC_Product::class ) ) ) {
wc_add_notice( __( 'Cannot add this product to cart (invalid product).', 'woocommerce-paypal-payments' ), 'error' );
return false;
}
$settings = $c->get( 'wcgateway.settings' ); $settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings ); assert( $settings instanceof Settings );
$subscriptions_mode = $settings->has( 'subscriptions_mode' ) ? $settings->get( 'subscriptions_mode' ) : ''; $subscriptions_mode = $settings->has( 'subscriptions_mode' ) ? $settings->get( 'subscriptions_mode' ) : '';
$is_paypal_subscription = static function ( $product ) use ( $subscriptions_mode ): bool {
return $product &&
in_array( $product->get_type(), array( 'subscription', 'variable-subscription' ), true ) &&
'subscriptions_api' === $subscriptions_mode &&
$product->get_meta( '_ppcp_enable_subscription_product', true ) === 'yes';
};
if ( 'subscriptions_api' !== $subscriptions_mode ) { if ( $is_paypal_subscription( $product ) ) {
if ( $product && $product->get_sold_individually() ) {
$product->set_sold_individually( false );
$product->save();
}
return $passed_validation;
}
if ( $product && $product->get_meta( '_ppcp_enable_subscription_product', true ) === 'yes' ) {
if ( ! $product->get_sold_individually() ) { if ( ! $product->get_sold_individually() ) {
$product->set_sold_individually( true ); $product->set_sold_individually( true );
$product->save(); $product->save();
} }
wc_add_notice( __( 'You cannot add a subscription product to a cart with other items.', 'woocommerce-paypal-payments' ), 'error' ); wc_add_notice( __( 'You cannot add a PayPal Subscription product to a cart with other items.', 'woocommerce-paypal-payments' ), 'error' );
return false; return false;
} }
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { foreach ( WC()->cart->get_cart() as $cart_item ) {
$cart_product = wc_get_product( $cart_item['product_id'] ); $cart_product = wc_get_product( $cart_item['product_id'] );
if ( $cart_product && $cart_product->get_meta( '_ppcp_enable_subscription_product', true ) === 'yes' ) { if ( $is_paypal_subscription( $cart_product ) ) {
wc_add_notice( __( 'You can only have one subscription product in your cart.', 'woocommerce-paypal-payments' ), 'error' ); wc_add_notice( __( 'You can only have one PayPal Subscription product in your cart.', 'woocommerce-paypal-payments' ), 'error' );
return false; return false;
} }
} }

View file

@ -153,6 +153,30 @@ return array(
'TWD', 'TWD',
'USD', 'USD',
), ),
'CN' => array(
'AUD',
'BRL',
'CAD',
'CHF',
'CZK',
'DKK',
'EUR',
'GBP',
'HKD',
'HUF',
'ILS',
'JPY',
'MXN',
'NOK',
'NZD',
'PHP',
'PLN',
'SEK',
'SGD',
'THB',
'TWD',
'USD',
),
'CY' => array( 'CY' => array(
'AUD', 'AUD',
'BRL', 'BRL',

View file

@ -28,7 +28,7 @@ return function ( ContainerInterface $container, array $fields ): array {
$has_enabled_separate_button_gateways = $container->get( 'wcgateway.settings.has_enabled_separate_button_gateways' ); $has_enabled_separate_button_gateways = $container->get( 'wcgateway.settings.has_enabled_separate_button_gateways' );
$preview_message = __( 'Standard Card Button Styling Preview', 'woocommerce-paypal-payments' ); $preview_message = __( 'Button Styling Preview', 'woocommerce-paypal-payments' );
$axo_smart_button_location_notice = $container->has( 'axo.smart-button-location-notice' ) ? $container->get( 'axo.smart-button-location-notice' ) : ''; $axo_smart_button_location_notice = $container->has( 'axo.smart-button-location-notice' ) ? $container->get( 'axo.smart-button-location-notice' ) : '';

View file

@ -54,6 +54,7 @@ class ModularTestCase extends TestCase
!defined('CONNECT_WOO_SANDBOX_MERCHANT_ID') && define('CONNECT_WOO_SANDBOX_MERCHANT_ID', 'merchant-id2'); !defined('CONNECT_WOO_SANDBOX_MERCHANT_ID') && define('CONNECT_WOO_SANDBOX_MERCHANT_ID', 'merchant-id2');
!defined('CONNECT_WOO_URL') && define('CONNECT_WOO_URL', 'https://connect.woocommerce.com/ppc'); !defined('CONNECT_WOO_URL') && define('CONNECT_WOO_URL', 'https://connect.woocommerce.com/ppc');
!defined('CONNECT_WOO_SANDBOX_URL') && define('CONNECT_WOO_SANDBOX_URL', 'https://connect.woocommerce.com/ppcsandbox'); !defined('CONNECT_WOO_SANDBOX_URL') && define('CONNECT_WOO_SANDBOX_URL', 'https://connect.woocommerce.com/ppcsandbox');
!defined('PPCP_PAYPAL_BN_CODE') && define('PPCP_PAYPAL_BN_CODE', 'Woo_PPCP');
} }
/** /**

View file

@ -27,6 +27,7 @@ define( 'PAYPAL_URL', 'https://www.paypal.com' );
define( 'PAYPAL_SANDBOX_API_URL', 'https://api-m.sandbox.paypal.com' ); define( 'PAYPAL_SANDBOX_API_URL', 'https://api-m.sandbox.paypal.com' );
define( 'PAYPAL_SANDBOX_URL', 'https://www.sandbox.paypal.com' ); define( 'PAYPAL_SANDBOX_URL', 'https://www.sandbox.paypal.com' );
define( 'PAYPAL_INTEGRATION_DATE', '2024-06-25' ); define( 'PAYPAL_INTEGRATION_DATE', '2024-06-25' );
define( 'PPCP_PAYPAL_BN_CODE', 'Woo_PPCP' );
! defined( 'CONNECT_WOO_CLIENT_ID' ) && define( 'CONNECT_WOO_CLIENT_ID', 'AcCAsWta_JTL__OfpjspNyH7c1GGHH332fLwonA5CwX4Y10mhybRZmHLA0GdRbwKwjQIhpDQy0pluX_P' ); ! defined( 'CONNECT_WOO_CLIENT_ID' ) && define( 'CONNECT_WOO_CLIENT_ID', 'AcCAsWta_JTL__OfpjspNyH7c1GGHH332fLwonA5CwX4Y10mhybRZmHLA0GdRbwKwjQIhpDQy0pluX_P' );
! defined( 'CONNECT_WOO_SANDBOX_CLIENT_ID' ) && define( 'CONNECT_WOO_SANDBOX_CLIENT_ID', 'AYmOHbt1VHg-OZ_oihPdzKEVbU3qg0qXonBcAztuzniQRaKE0w1Hr762cSFwd4n8wxOl-TCWohEa0XM_' ); ! defined( 'CONNECT_WOO_SANDBOX_CLIENT_ID' ) && define( 'CONNECT_WOO_SANDBOX_CLIENT_ID', 'AYmOHbt1VHg-OZ_oihPdzKEVbU3qg0qXonBcAztuzniQRaKE0w1Hr762cSFwd4n8wxOl-TCWohEa0XM_' );