Merge branch 'trunk' into PCP-2786-do-not-save-payment-token-for-guest-users

This commit is contained in:
Emili Castells Guasch 2024-03-22 10:49:49 +01:00
commit 16a8c9a313
11 changed files with 71 additions and 35 deletions

View file

@ -1,6 +1,6 @@
*** Changelog ***
= 2.6.0 - xxxx-xx-xx =
= 2.6.0 - 2024-03-20 =
* Fix - invoice_id not included in API call when creating payment with saved card #2086
* Fix - Typo in SCA indicators for ACDC Vault transactions #2083
* Fix - Payments with saved card tokens use Capture intent when Authorize is configured #2069

View file

@ -61,10 +61,10 @@ class ItemFactory {
$price = (float) $item['line_subtotal'] / (float) $item['quantity'];
return new Item(
mb_substr( $product->get_name(), 0, 127 ),
$this->prepare_item_string( $product->get_name() ),
new Money( $price, $this->currency ),
$quantity,
$this->prepare_description( $product->get_description() ),
$this->prepare_item_string( $product->get_description() ),
null,
$this->prepare_sku( $product->get_sku() ),
( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
@ -138,10 +138,10 @@ class ItemFactory {
$image = $product instanceof WC_Product ? wp_get_attachment_image_src( (int) $product->get_image_id(), 'full' ) : '';
return new Item(
mb_substr( $item->get_name(), 0, 127 ),
$this->prepare_item_string( $item->get_name() ),
new Money( $price_without_tax_rounded, $currency ),
$quantity,
$product instanceof WC_Product ? $this->prepare_description( $product->get_description() ) : '',
$product instanceof WC_Product ? $this->prepare_item_string( $product->get_description() ) : '',
null,
$product instanceof WC_Product ? $this->prepare_sku( $product->get_sku() ) : '',
( $product instanceof WC_Product && $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
@ -160,7 +160,7 @@ class ItemFactory {
*/
private function from_wc_order_fee( \WC_Order_Item_Fee $item, \WC_Order $order ): Item {
return new Item(
$item->get_name(),
$this->prepare_item_string( $item->get_name() ),
new Money( (float) $item->get_amount(), $order->get_currency() ),
$item->get_quantity(),
'',

View file

@ -12,14 +12,14 @@ namespace WooCommerce\PayPalCommerce\ApiClient\Helper;
trait ItemTrait {
/**
* Cleanups the description and prepares it for sending to PayPal.
* Cleans up item strings (title and description for example) and prepares them for sending to PayPal.
*
* @param string $description Item description.
* @param string $string Item string.
* @return string
*/
protected function prepare_description( string $description ): string {
$description = strip_shortcodes( wp_strip_all_tags( $description ) );
return substr( $description, 0, 127 ) ?: '';
protected function prepare_item_string( string $string ): string {
$string = strip_shortcodes( wp_strip_all_tags( $string ) );
return substr( $string, 0, 127 ) ?: '';
}
/**

View file

@ -169,10 +169,10 @@ class Shipment implements ShipmentInterface {
$image = wp_get_attachment_image_src( (int) $product->get_image_id(), 'full' );
$ppcp_order_item = new Item(
mb_substr( $item->get_name(), 0, 127 ),
$this->prepare_item_string( $item->get_name() ),
new Money( $price_without_tax_rounded, $currency ),
$quantity,
$this->prepare_description( $product->get_description() ),
$this->prepare_item_string( $product->get_description() ),
null,
$this->prepare_sku( $product->get_sku() ),
$product->is_virtual() ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,

View file

@ -114,7 +114,7 @@ class SubscriptionsApiHandler {
*/
public function create_product( WC_Product $product ) {
try {
$subscription_product = $this->products_endpoint->create( $product->get_title(), $this->prepare_description( $product->get_description() ) );
$subscription_product = $this->products_endpoint->create( $this->prepare_item_string( $product->get_title() ), $this->prepare_item_string( $product->get_description() ) );
$product->update_meta_data( 'ppcp_subscription_product', $subscription_product->to_array() );
$product->save();
} catch ( RuntimeException $exception ) {
@ -169,7 +169,7 @@ class SubscriptionsApiHandler {
$catalog_product_name = $catalog_product->name() ?: '';
$catalog_product_description = $catalog_product->description() ?: '';
$wc_product_description = $this->prepare_description( $product->get_description() ) ?: $product->get_title();
$wc_product_description = $this->prepare_item_string( $product->get_description() ) ?: $this->prepare_item_string( $product->get_title() );
if ( $catalog_product_name !== $product->get_title() || $catalog_product_description !== $wc_product_description ) {
$data = array();

View file

@ -313,8 +313,10 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
*/
public function form() {
add_action( 'gettext', array( $this, 'replace_credit_card_cvv_label' ), 10, 3 );
add_action( 'gettext', array( $this, 'replace_credit_card_cvv_placeholder' ), 10, 3 );
parent::form();
remove_action( 'gettext', 'replace_credit_card_cvv_label' );
remove_action( 'gettext', 'replace_credit_card_cvv_placeholder' );
}
/**
@ -334,6 +336,23 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
return __( 'CVV', 'woocommerce-paypal-payments' );
}
/**
* Replace WooCommerce credit card CVV field placeholder.
*
* @param string $translation Translated text.
* @param string $text Original text to translate.
* @param string $domain Text domain.
*
* @return string Translated field.
*/
public function replace_credit_card_cvv_placeholder( string $translation, string $text, string $domain ): string {
if ( 'woocommerce' !== $domain || 'CVC' !== $text || ! apply_filters( 'woocommerce_paypal_payments_card_fields_translate_card_cvv', true ) ) {
return $translation;
}
return __( 'CVV', 'woocommerce-paypal-payments' );
}
/**
* Returns the icons of the gateway.
*

View file

@ -202,7 +202,13 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
'type' => 'text',
'default' => get_bloginfo( 'name' ) ?? '',
'desc_tip' => true,
'description' => __( 'Merchant name displayed in Ratepay\'s payment instructions.', 'woocommerce-paypal-payments' ),
'description' => __( 'Merchant name displayed in Ratepay\'s payment instructions. Should not exceed 127 characters.', 'woocommerce-paypal-payments' ),
'maxlength' => 127,
'custom_attributes' => array(
'pattern' => '.{1,127}',
'autocomplete' => 'off',
'required' => '',
),
),
'logo_url' => array(
'title' => __( 'Logo URL', 'woocommerce-paypal-payments' ),
@ -210,6 +216,11 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
'default' => '',
'desc_tip' => true,
'description' => __( 'Logo to be presented on Ratepay\'s payment instructions.', 'woocommerce-paypal-payments' ),
'custom_attributes' => array(
'pattern' => '.+',
'autocomplete' => 'off',
'required' => '',
),
),
'customer_service_instructions' => array(
'title' => __( 'Customer service instructions', 'woocommerce-paypal-payments' ),
@ -217,6 +228,11 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
'default' => '',
'desc_tip' => true,
'description' => __( 'Customer service instructions to be presented on Ratepay\'s payment instructions.', 'woocommerce-paypal-payments' ),
'custom_attributes' => array(
'pattern' => '.+',
'autocomplete' => 'off',
'required' => '',
),
),
);
}

View file

@ -179,7 +179,7 @@ If you encounter issues with the PayPal buttons not appearing after an update, p
== Changelog ==
= 2.6.0 - xxxx-xx-xx =
= 2.6.0 - 2024-03-20 =
* Fix - invoice_id not included in API call when creating payment with saved card #2086
* Fix - Typo in SCA indicators for ACDC Vault transactions #2083
* Fix - Payments with saved card tokens use Capture intent when Authorize is configured #2069

View file

@ -65,7 +65,7 @@ class FilePathPluginFactory implements FilePathPluginFactoryInterface {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugin_data = get_plugin_data( $filePath );
$plugin_data = get_plugin_data( $filePath, false );
if ( empty( $plugin_data ) ) {
throw new UnexpectedValueException(
sprintf(

View file

@ -312,11 +312,12 @@ class ItemFactoryTest extends TestCase
$result = $testee->from_wc_order($order);
$item = current($result);
/**
* @var Item $item
*/
$this->assertEquals(mb_substr($name, 0, 127), $item->name());
$this->assertEquals(substr($description, 0, 127), $item->description());
$this->assertEquals(substr( strip_shortcodes( wp_strip_all_tags( $name ) ), 0, 127 ), $item->name());
$this->assertEquals(substr( strip_shortcodes( wp_strip_all_tags( $description ) ), 0, 127 ), $item->description());
}
public function testFromPayPalResponse()

View file

@ -97,7 +97,7 @@ define( 'PAYPAL_INTEGRATION_DATE', '2024-03-12' );
*/
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugin_data = get_plugin_data( __DIR__ . '/woocommerce-paypal-payments.php' );
$plugin_data = get_plugin_data( __DIR__ . '/woocommerce-paypal-payments.php', false );
$plugin_version = $plugin_data['Version'] ?? null;
$installed_plugin_version = get_option( 'woocommerce-ppcp-version' );
if ( $installed_plugin_version !== $plugin_version ) {