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' );