Merge trunk and fix conflicts

This commit is contained in:
Emili Castells Guasch 2025-01-02 13:50:48 +01:00
commit 1c0b49cbbe
165 changed files with 7146 additions and 4771 deletions

View file

@ -454,7 +454,7 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
$tokens = WC_Payment_Tokens::get_customer_tokens( get_current_user_id() );
foreach ( $tokens as $token ) {
if ( $token->get_id() === (int) $card_payment_token_id ) {
$custom_id = $wc_order->get_order_number();
$custom_id = (string) $wc_order->get_id();
$invoice_id = $this->prefix . $wc_order->get_order_number();
$create_order = $this->capture_card_payment->create_order( $token->get_token(), $custom_id, $invoice_id, $wc_order );

View file

@ -96,52 +96,35 @@ trait CreditCardOrderInfoHandlingTrait {
return;
}
$fraud_responses = $fraud->to_array();
$card_brand = $payment_source->properties()->brand ?? __( 'N/A', 'woocommerce-paypal-payments' );
$card_last_digits = $payment_source->properties()->last_digits ?? __( 'N/A', 'woocommerce-paypal-payments' );
$avs_response_order_note_title = __( 'Address Verification Result', 'woocommerce-paypal-payments' );
$response_order_note_title = __( 'PayPal Advanced Card Processing Verification:', 'woocommerce-paypal-payments' );
/* translators: %1$s is AVS order note title, %2$s is AVS order note result markup */
$avs_response_order_note_format = __( '%1$s %2$s', 'woocommerce-paypal-payments' );
$avs_response_order_note_result_format = '<ul class="ppcp_avs_result">
<li>%1$s</li>
<ul class="ppcp_avs_result_inner">
<li>%2$s</li>
<li>%3$s</li>
</ul>
<li>%4$s</li>
<li>%5$s</li>
</ul>';
$avs_response_order_note_result = sprintf(
$avs_response_order_note_result_format,
/* translators: %s is fraud AVS code */
sprintf( __( 'AVS: %s', 'woocommerce-paypal-payments' ), esc_html( $fraud_responses['avs_code'] ) ),
/* translators: %s is fraud AVS address match */
sprintf( __( 'Address Match: %s', 'woocommerce-paypal-payments' ), esc_html( $fraud_responses['address_match'] ) ),
/* translators: %s is fraud AVS postal match */
sprintf( __( 'Postal Match: %s', 'woocommerce-paypal-payments' ), esc_html( $fraud_responses['postal_match'] ) ),
/* translators: %s is card brand */
sprintf( __( 'Card Brand: %s', 'woocommerce-paypal-payments' ), esc_html( $card_brand ) ),
/* translators: %s card last digits */
sprintf( __( 'Card Last Digits: %s', 'woocommerce-paypal-payments' ), esc_html( $card_last_digits ) )
$response_order_note_format = __( '%1$s %2$s', 'woocommerce-paypal-payments' );
$response_order_note_result_format = '<ul class="ppcp_avs_cvv_result">
<li>%1$s</li>
<li>%2$s</li>
<li>%3$s</li>
</ul>';
$response_order_note_result = sprintf(
$response_order_note_result_format,
/* translators: %1$s is card brand and %2$s card last 4 digits */
sprintf( __( 'Card: %1$s (%2$s)', 'woocommerce-paypal-payments' ), $card_brand, $card_last_digits ),
/* translators: %s is fraud AVS message */
sprintf( __( 'AVS: %s', 'woocommerce-paypal-payments' ), $fraud->get_avs_code_message() ),
/* translators: %s is fraud CVV message */
sprintf( __( 'CVV: %s', 'woocommerce-paypal-payments' ), $fraud->get_cvv2_code_message() ),
);
$avs_response_order_note = sprintf(
$avs_response_order_note_format,
esc_html( $avs_response_order_note_title ),
wp_kses_post( $avs_response_order_note_result )
$response_order_note = sprintf(
$response_order_note_format,
esc_html( $response_order_note_title ),
wp_kses_post( $response_order_note_result )
);
$wc_order->add_order_note( $avs_response_order_note );
$cvv_response_order_note_format = '<ul class="ppcp_cvv_result"><li>%1$s</li></ul>';
$cvv_response_order_note = sprintf(
$cvv_response_order_note_format,
/* translators: %s is fraud CVV match */
sprintf( __( 'CVV2 Match: %s', 'woocommerce-paypal-payments' ), esc_html( $fraud_responses['cvv_match'] ) )
);
$wc_order->add_order_note( $cvv_response_order_note );
$wc_order->add_order_note( $response_order_note );
$meta_details = array_merge(
$fraud_responses,
$fraud->to_array(),
array(
'card_brand' => $card_brand,
'card_last_digits' => $card_last_digits,

View file

@ -5,7 +5,7 @@
* @package WooCommerce\PayPalCommerce\WcGateway\Settings
*/
declare(strict_types=1);
declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\WcGateway\Settings;
@ -18,44 +18,46 @@ use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
*/
class Settings implements ContainerInterface {
const KEY = 'woocommerce-ppcp-settings';
const KEY = 'woocommerce-ppcp-settings';
const CONNECTION_TAB_ID = 'ppcp-connection';
const PAY_LATER_TAB_ID = 'ppcp-pay-later';
const PAY_LATER_TAB_ID = 'ppcp-pay-later';
/**
* The settings.
*
* @var array
*/
private $settings = array();
private array $settings = array();
/**
* The list of selected default button locations.
*
* @var string[]
*/
protected $default_button_locations;
protected array $default_button_locations;
/**
* The list of selected default pay later button locations.
*
* @var string[]
*/
protected $default_pay_later_button_locations;
protected array $default_pay_later_button_locations;
/**
* The list of selected default pay later messaging locations.
*
* @var string[]
*/
protected $default_pay_later_messaging_locations;
protected array $default_pay_later_messaging_locations;
/**
* The default ACDC gateway title.
*
* @var string
*/
protected $default_dcc_gateway_title;
protected string $default_dcc_gateway_title;
/**
* A helper for mapping the new/old settings.
@ -67,11 +69,17 @@ class Settings implements ContainerInterface {
/**
* Settings constructor.
*
* @param string[] $default_button_locations The list of selected default button locations.
* @param string $default_dcc_gateway_title The default ACDC gateway title.
* @param string[] $default_pay_later_button_locations The list of selected default pay later button locations.
* @param string[] $default_pay_later_messaging_locations The list of selected default pay later messaging locations.
* @param SettingsMapHelper $settings_map_helper A helper for mapping the new/old settings.
* @param string[] $default_button_locations The list of selected default
* button locations.
* @param string $default_dcc_gateway_title The default ACDC gateway
* title.
* @param string[] $default_pay_later_button_locations The list of selected default
* pay later button locations.
* @param string[] $default_pay_later_messaging_locations The list of selected default
* pay later messaging
* locations.
* @param SettingsMapHelper $settings_map_helper A helper for mapping the
* new/old settings.
*/
public function __construct(
array $default_button_locations,
@ -90,10 +98,11 @@ class Settings implements ContainerInterface {
/**
* Returns the value for an id.
*
* @param string $id The value identificator.
* @throws NotFoundException When nothing was found.
*
* @param string $id The value identifier.
*
* @return mixed
* @throws NotFoundException When nothing was found.
*/
public function get( $id ) {
if ( ! $this->has( $id ) ) {
@ -106,23 +115,24 @@ class Settings implements ContainerInterface {
/**
* Whether a value exists.
*
* @param string $id The value identificator.
* @param string $id The value identifier.
*
* @return bool
*/
public function has( $id ) {
public function has( string $id ) {
if ( $this->settings_map_helper->has_mapped_key( $id ) ) {
return true;
}
$this->load();
return array_key_exists( $id, $this->settings );
}
/**
* Sets a value.
*
* @param string $id The value identificator.
* @param string $id The value identifier.
* @param mixed $value The value.
*/
public function set( $id, $value ) {
@ -142,7 +152,7 @@ class Settings implements ContainerInterface {
*
* @return bool
*/
private function load(): bool {
private function load() : bool {
if ( $this->settings ) {
return false;
}
@ -175,6 +185,7 @@ class Settings implements ContainerInterface {
}
$this->settings[ $key ] = $value;
}
return true;
}
}

View file

@ -21,9 +21,14 @@ class TaskRegistrar implements TaskRegistrarInterface {
*
* @throws RuntimeException If problem registering.
*/
public function register( array $tasks ): void {
public function register( string $list_id, array $tasks ): void {
$task_lists = TaskLists::get_lists();
if ( ! isset( $task_lists[ $list_id ] ) ) {
return;
}
foreach ( $tasks as $task ) {
$added_task = TaskLists::add_task( 'extended', $task );
$added_task = TaskLists::add_task( $list_id, $task );
if ( $added_task instanceof WP_Error ) {
throw new RuntimeException( $added_task->get_error_message() );
}

View file

@ -15,11 +15,12 @@ use RuntimeException;
interface TaskRegistrarInterface {
/**
* Registers the tasks inside "Things to do next" WC section.
* Registers the tasks inside the section with given list ID.
*
* @param string $list_id The list ID.
* @param Task[] $tasks The list of tasks.
* @return void
* @throws RuntimeException If problem registering.
*/
public function register( array $tasks ): void;
public function register( string $list_id, array $tasks ): void;
}

View file

@ -13,6 +13,7 @@ use Exception;
use Psr\Log\LoggerInterface;
use Throwable;
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
@ -547,6 +548,33 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul
}
);
add_filter(
'woocommerce_paypal_payments_rest_common_merchant_data',
function( array $merchant_data ) use ( $c ): array {
if ( ! isset( $merchant_data['features'] ) ) {
$merchant_data['features'] = array();
}
$billing_agreements_endpoint = $c->get( 'api.endpoint.billing-agreements' );
assert( $billing_agreements_endpoint instanceof BillingAgreementsEndpoint );
$reference_transactions_enabled = $billing_agreements_endpoint->reference_transaction_enabled();
$merchant_data['features']['save_paypal_and_venmo'] = array(
'enabled' => $reference_transactions_enabled,
);
$dcc_product_status = $c->get( 'wcgateway.helper.dcc-product-status' );
assert( $dcc_product_status instanceof DCCProductStatus );
$dcc_enabled = $dcc_product_status->dcc_is_active();
$merchant_data['features']['advanced_credit_and_debit_cards'] = array(
'enabled' => $dcc_enabled,
);
return $merchant_data;
}
);
return true;
}
@ -653,7 +681,10 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul
$listener = $container->get( 'wcgateway.settings.listener' );
assert( $listener instanceof SettingsListener );
$listener->listen_for_merchant_id();
$use_new_ui = $container->get( 'wcgateway.settings.admin-settings-enabled' );
if ( ! $use_new_ui ) {
$listener->listen_for_merchant_id();
}
try {
$listener->listen_for_vaulting_enabled();
@ -880,10 +911,11 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul
if ( empty( $simple_redirect_tasks ) ) {
return;
}
$task_registrar = $container->get( 'wcgateway.settings.wc-tasks.task-registrar' );
assert( $task_registrar instanceof TaskRegistrarInterface );
$task_registrar->register( $simple_redirect_tasks );
$task_registrar->register( 'extended', $simple_redirect_tasks );
} catch ( Exception $exception ) {
$logger->error( "Failed to create a task in the 'Things to do next' section of WC. " . $exception->getMessage() );
}