diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 1f3393337..e1b50d883 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -644,7 +644,7 @@ return array( >', '' ), - 'options' => $container->get( 'wcgateway.all-funding-sources' ), + 'options' => $container->get( 'wcgateway.settings.funding-sources' ), 'screens' => array( State::STATE_START, State::STATE_ONBOARDED, @@ -881,6 +881,17 @@ return array( 'sofort' => _x( 'Sofort', 'Name of payment method', 'woocommerce-paypal-payments' ), 'venmo' => _x( 'Venmo', 'Name of payment method', 'woocommerce-paypal-payments' ), 'trustly' => _x( 'Trustly', 'Name of payment method', 'woocommerce-paypal-payments' ), + 'paylater' => _x( 'Pay Later', 'Name of payment method', 'woocommerce-paypal-payments' ), + ); + }, + 'wcgateway.settings.funding-sources' => static function( ContainerInterface $container ): array { + return array_diff_key( + $container->get( 'wcgateway.all-funding-sources' ), + array_flip( + array( + 'paylater', + ) + ) ); }, @@ -951,9 +962,11 @@ return array( 'wcgateway.funding-source.renderer' => function ( ContainerInterface $container ) : FundingSourceRenderer { return new FundingSourceRenderer( - $container->get( 'wcgateway.settings' ) + $container->get( 'wcgateway.settings' ), + $container->get( 'wcgateway.all-funding-sources' ) ); }, + 'wcgateway.checkout-helper' => static function ( ContainerInterface $container ): CheckoutHelper { return new CheckoutHelper(); }, diff --git a/modules/ppcp-wc-gateway/src/FundingSource/FundingSourceRenderer.php b/modules/ppcp-wc-gateway/src/FundingSource/FundingSourceRenderer.php index e91d87574..a465db721 100644 --- a/modules/ppcp-wc-gateway/src/FundingSource/FundingSourceRenderer.php +++ b/modules/ppcp-wc-gateway/src/FundingSource/FundingSourceRenderer.php @@ -22,13 +22,32 @@ class FundingSourceRenderer { */ protected $settings; + /** + * Map funding source ID -> human-readable name. + * + * @var array + */ + protected $funding_sources; + + /** + * The IDs of the sources belonging to PayPal that do not need to mention "via PayPal". + * + * @var string[] + */ + protected $own_funding_sources = array( 'venmo', 'paylater' ); + /** * FundingSourceRenderer constructor. * - * @param ContainerInterface $settings The settings. + * @param ContainerInterface $settings The settings. + * @param array $funding_sources Map funding source ID -> human-readable name. */ - public function __construct( ContainerInterface $settings ) { - $this->settings = $settings; + public function __construct( + ContainerInterface $settings, + array $funding_sources + ) { + $this->settings = $settings; + $this->funding_sources = $funding_sources; } /** @@ -37,9 +56,17 @@ class FundingSourceRenderer { * @param string $id The ID of the funding source, such as 'venmo'. */ public function render_name( string $id ): string { - if ( 'venmo' === $id ) { - return __( 'Venmo', 'woocommerce-paypal-payments' ); + if ( array_key_exists( $id, $this->funding_sources ) ) { + if ( in_array( $id, $this->own_funding_sources, true ) ) { + return $this->funding_sources[ $id ]; + } + return sprintf( + /* translators: %s - Sofort, BLIK, iDeal, Mercado Pago, etc. */ + __( '%s (via PayPal)', 'woocommerce-paypal-payments' ), + $this->funding_sources[ $id ] + ); } + return $this->settings->has( 'title' ) ? $this->settings->get( 'title' ) : __( 'PayPal', 'woocommerce-paypal-payments' ); @@ -51,9 +78,14 @@ class FundingSourceRenderer { * @param string $id The ID of the funding source, such as 'venmo'. */ public function render_description( string $id ): string { - if ( 'venmo' === $id ) { - return __( 'Pay via Venmo.', 'woocommerce-paypal-payments' ); + if ( array_key_exists( $id, $this->funding_sources ) ) { + return sprintf( + /* translators: %s - Sofort, BLIK, iDeal, Mercado Pago, etc. */ + __( 'Pay via %s.', 'woocommerce-paypal-payments' ), + $this->funding_sources[ $id ] + ); } + return $this->settings->has( 'description' ) ? $this->settings->get( 'description' ) : __( 'Pay via PayPal.', 'woocommerce-paypal-payments' ); diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index 289eb178c..a8ae5eb60 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -179,7 +179,7 @@ class WCGatewayModule implements ModuleInterface { $c->get( 'onboarding.environment' ), $settings_status->is_pay_later_button_enabled(), $settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(), - $c->get( 'wcgateway.all-funding-sources' ) + $c->get( 'wcgateway.settings.funding-sources' ) ); $assets->register_assets(); } diff --git a/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php b/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php index b62f013d7..26107abd0 100644 --- a/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php +++ b/tests/PHPUnit/WcGateway/Gateway/WcGatewayTest.php @@ -59,7 +59,10 @@ class WcGatewayTest extends TestCase $this->environment = Mockery::mock(Environment::class); $this->paymentTokenRepository = Mockery::mock(PaymentTokenRepository::class); $this->logger = Mockery::mock(LoggerInterface::class); - $this->funding_source_renderer = new FundingSourceRenderer($this->settings); + $this->funding_source_renderer = new FundingSourceRenderer( + $this->settings, + ['venmo' => 'Venmo', 'paylater' => 'Pay Later', 'blik' => 'BLIK'] + ); $this->apiShopCountry = 'DE'; $this->onboardingState->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED); @@ -271,6 +274,8 @@ class WcGatewayTest extends TestCase return [ [null, 'PayPal', 'Pay via PayPal.'], ['venmo', 'Venmo', 'Pay via Venmo.'], + ['paylater', 'Pay Later', 'Pay via Pay Later.'], + ['blik', 'BLIK (via PayPal)', 'Pay via BLIK.'], ['qwerty', 'PayPal', 'Pay via PayPal.'], ]; }