From f812d043af40da570edcbdd21b4629a7ec4d6d66 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Tue, 30 May 2023 15:11:13 +0200 Subject: [PATCH 1/4] Add soft descriptor to PurchaseUnitFactory PCP-1709 --- modules/ppcp-api-client/services.php | 4 +++- .../src/Factory/PurchaseUnitFactory.php | 18 ++++++++++++++---- modules/ppcp-wc-gateway/services.php | 4 ++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-api-client/services.php b/modules/ppcp-api-client/services.php index e7347b3bd..0deb058f8 100644 --- a/modules/ppcp-api-client/services.php +++ b/modules/ppcp-api-client/services.php @@ -298,6 +298,7 @@ return array( $shipping_factory = $container->get( 'api.factory.shipping' ); $payments_factory = $container->get( 'api.factory.payments' ); $prefix = $container->get( 'api.prefix' ); + $soft_descriptor = $container->get( 'wcgateway.soft-descriptor' ); return new PurchaseUnitFactory( $amount_factory, @@ -306,7 +307,8 @@ return array( $item_factory, $shipping_factory, $payments_factory, - $prefix + $prefix, + $soft_descriptor ); }, 'api.factory.patch-collection-factory' => static function ( ContainerInterface $container ): PatchCollectionFactory { diff --git a/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php b/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php index 9f8f12c5e..d5b0a801e 100644 --- a/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php +++ b/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php @@ -68,6 +68,13 @@ class PurchaseUnitFactory { */ private $prefix; + /** + * The Soft Descriptor. + * + * @var string + */ + private $soft_descriptor; + /** * PurchaseUnitFactory constructor. * @@ -78,6 +85,7 @@ class PurchaseUnitFactory { * @param ShippingFactory $shipping_factory The shipping factory. * @param PaymentsFactory $payments_factory The payments factory. * @param string $prefix The prefix. + * @param string $soft_descriptor The soft descriptor. */ public function __construct( AmountFactory $amount_factory, @@ -86,7 +94,8 @@ class PurchaseUnitFactory { ItemFactory $item_factory, ShippingFactory $shipping_factory, PaymentsFactory $payments_factory, - string $prefix = 'WC-' + string $prefix = 'WC-', + string $soft_descriptor = '' ) { $this->amount_factory = $amount_factory; @@ -96,6 +105,7 @@ class PurchaseUnitFactory { $this->shipping_factory = $shipping_factory; $this->payments_factory = $payments_factory; $this->prefix = $prefix; + $this->soft_descriptor = $soft_descriptor; } /** @@ -126,7 +136,7 @@ class PurchaseUnitFactory { $payee = $this->payee_repository->payee(); $custom_id = (string) $order->get_id(); $invoice_id = $this->prefix . $order->get_order_number(); - $soft_descriptor = ''; + $soft_descriptor = $this->soft_descriptor; $purchase_unit = new PurchaseUnit( $amount, @@ -189,7 +199,7 @@ class PurchaseUnitFactory { $custom_id = ''; $invoice_id = ''; - $soft_descriptor = ''; + $soft_descriptor = $this->soft_descriptor; $purchase_unit = new PurchaseUnit( $amount, $items, @@ -224,7 +234,7 @@ class PurchaseUnitFactory { $description = ( isset( $data->description ) ) ? $data->description : ''; $custom_id = ( isset( $data->custom_id ) ) ? $data->custom_id : ''; $invoice_id = ( isset( $data->invoice_id ) ) ? $data->invoice_id : ''; - $soft_descriptor = ( isset( $data->soft_descriptor ) ) ? $data->soft_descriptor : ''; + $soft_descriptor = ( isset( $data->soft_descriptor ) ) ? $data->soft_descriptor : $this->soft_descriptor; $items = array(); if ( isset( $data->items ) && is_array( $data->items ) ) { $items = array_map( diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 9577f027d..255de3e76 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -955,6 +955,10 @@ return array( return 'https://www.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%s'; }, + 'wcgateway.soft-descriptor' => static function ( ContainerInterface $container ): string { + return 'soft descriptor test'; + }, + 'wcgateway.transaction-url-provider' => static function ( ContainerInterface $container ): TransactionUrlProvider { $sandbox_url_base = $container->get( 'wcgateway.transaction-url-sandbox' ); $live_url_base = $container->get( 'wcgateway.transaction-url-live' ); From 220da3cfea343de68d9943122039a0ab3ff40241 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Fri, 2 Jun 2023 10:48:47 +0200 Subject: [PATCH 2/4] Add soft descriptor setting PCP-1709 --- modules/ppcp-wc-gateway/services.php | 7 ++++++- .../src/Settings/Fields/connection-tab-fields.php | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 255de3e76..f7141684d 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -956,7 +956,12 @@ return array( }, 'wcgateway.soft-descriptor' => static function ( ContainerInterface $container ): string { - return 'soft descriptor test'; + $settings = $container->get( 'wcgateway.settings' ); + assert( $settings instanceof Settings); + if ( $settings->has( 'soft_descriptor' ) ) { + return $settings->get( 'soft_descriptor' ); + } + return ''; }, 'wcgateway.transaction-url-provider' => static function ( ContainerInterface $container ): TransactionUrlProvider { diff --git a/modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php b/modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php index 6ac84583a..dd3d95f37 100644 --- a/modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php +++ b/modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php @@ -423,6 +423,20 @@ return function ( ContainerInterface $container, array $fields ): array { '' ), ), + 'soft_descriptor' => array( + 'title' => __( 'Soft Descriptor', 'woocommerce-paypal-payments' ), + 'type' => 'text', + 'desc_tip' => true, + 'description' => __( 'The soft descriptor is the dynamic text used to construct the statement descriptor that appears on a payer\'s card statement.', 'woocommerce-paypal-payments' ), + 'maxlength' => 22, + 'default' => '', + 'screens' => array( + State::STATE_START, + State::STATE_ONBOARDED, + ), + 'requirements' => array(), + 'gateway' => Settings::CONNECTION_TAB_ID, + ), 'prefix' => array( 'title' => __( 'Invoice prefix', 'woocommerce-paypal-payments' ), 'type' => 'text', From b7c4055610413f98c0dabc3c7e5103606ed0526e Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Mon, 12 Jun 2023 09:00:08 +0200 Subject: [PATCH 3/4] Fix CS --- modules/ppcp-wc-gateway/services.php | 2 +- .../Settings/Fields/connection-tab-fields.php | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 8a82c0ea5..da2baa718 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -956,7 +956,7 @@ return array( 'wcgateway.soft-descriptor' => static function ( ContainerInterface $container ): string { $settings = $container->get( 'wcgateway.settings' ); - assert( $settings instanceof Settings); + assert( $settings instanceof Settings ); if ( $settings->has( 'soft_descriptor' ) ) { return $settings->get( 'soft_descriptor' ); } diff --git a/modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php b/modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php index dd3d95f37..e5f006cfb 100644 --- a/modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php +++ b/modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php @@ -423,19 +423,19 @@ return function ( ContainerInterface $container, array $fields ): array { '' ), ), - 'soft_descriptor' => array( - 'title' => __( 'Soft Descriptor', 'woocommerce-paypal-payments' ), - 'type' => 'text', - 'desc_tip' => true, - 'description' => __( 'The soft descriptor is the dynamic text used to construct the statement descriptor that appears on a payer\'s card statement.', 'woocommerce-paypal-payments' ), - 'maxlength' => 22, - 'default' => '', - 'screens' => array( + 'soft_descriptor' => array( + 'title' => __( 'Soft Descriptor', 'woocommerce-paypal-payments' ), + 'type' => 'text', + 'desc_tip' => true, + 'description' => __( 'The soft descriptor is the dynamic text used to construct the statement descriptor that appears on a payer\'s card statement.', 'woocommerce-paypal-payments' ), + 'maxlength' => 22, + 'default' => '', + 'screens' => array( State::STATE_START, State::STATE_ONBOARDED, ), - 'requirements' => array(), - 'gateway' => Settings::CONNECTION_TAB_ID, + 'requirements' => array(), + 'gateway' => Settings::CONNECTION_TAB_ID, ), 'prefix' => array( 'title' => __( 'Invoice prefix', 'woocommerce-paypal-payments' ), From 5f550ae976fe87d71c8dabbae7006885ec031cf4 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Wed, 14 Jun 2023 12:19:41 +0200 Subject: [PATCH 4/4] Add max value to tooltip --- .../src/Settings/Fields/connection-tab-fields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php b/modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php index e5f006cfb..d0d25bc61 100644 --- a/modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php +++ b/modules/ppcp-wc-gateway/src/Settings/Fields/connection-tab-fields.php @@ -427,7 +427,7 @@ return function ( ContainerInterface $container, array $fields ): array { 'title' => __( 'Soft Descriptor', 'woocommerce-paypal-payments' ), 'type' => 'text', 'desc_tip' => true, - 'description' => __( 'The soft descriptor is the dynamic text used to construct the statement descriptor that appears on a payer\'s card statement.', 'woocommerce-paypal-payments' ), + 'description' => __( 'The soft descriptor is the dynamic text used to construct the statement descriptor that appears on a payer\'s card statement. Text field, max value of 22 characters.', 'woocommerce-paypal-payments' ), 'maxlength' => 22, 'default' => '', 'screens' => array(