diff --git a/modules/ppcp-api-client/services.php b/modules/ppcp-api-client/services.php index ce363dabc..71c9a25f8 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 494fa4594..8b06d17f5 100644 --- a/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php +++ b/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php @@ -70,6 +70,13 @@ class PurchaseUnitFactory { */ private $prefix; + /** + * The Soft Descriptor. + * + * @var string + */ + private $soft_descriptor; + /** * PurchaseUnitFactory constructor. * @@ -80,6 +87,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, @@ -88,7 +96,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; @@ -98,6 +107,7 @@ class PurchaseUnitFactory { $this->shipping_factory = $shipping_factory; $this->payments_factory = $payments_factory; $this->prefix = $prefix; + $this->soft_descriptor = $soft_descriptor; } /** @@ -128,7 +138,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, @@ -198,7 +208,7 @@ class PurchaseUnitFactory { } } $invoice_id = ''; - $soft_descriptor = ''; + $soft_descriptor = $this->soft_descriptor; $purchase_unit = new PurchaseUnit( $amount, $items, @@ -233,7 +243,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 13714d910..26d866066 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -971,6 +971,15 @@ return array( return 'https://www.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%s'; }, + 'wcgateway.soft-descriptor' => static function ( ContainerInterface $container ): string { + $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 { $sandbox_url_base = $container->get( 'wcgateway.transaction-url-sandbox' ); $live_url_base = $container->get( 'wcgateway.transaction-url-live' ); 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..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 @@ -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. Text field, max value of 22 characters.', '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',