Show funding source as payment method

This commit is contained in:
Alex P 2023-03-01 10:20:04 +02:00
parent 43a5b759f2
commit f7323210f0
No known key found for this signature in database
GPG key ID: 54487A734A204D71
4 changed files with 61 additions and 11 deletions

View file

@ -644,7 +644,7 @@ return array(
>', >',
'</a>' '</a>'
), ),
'options' => $container->get( 'wcgateway.all-funding-sources' ), 'options' => $container->get( 'wcgateway.settings.funding-sources' ),
'screens' => array( 'screens' => array(
State::STATE_START, State::STATE_START,
State::STATE_ONBOARDED, State::STATE_ONBOARDED,
@ -881,6 +881,17 @@ return array(
'sofort' => _x( 'Sofort', 'Name of payment method', 'woocommerce-paypal-payments' ), 'sofort' => _x( 'Sofort', 'Name of payment method', 'woocommerce-paypal-payments' ),
'venmo' => _x( 'Venmo', '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' ), '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 { 'wcgateway.funding-source.renderer' => function ( ContainerInterface $container ) : FundingSourceRenderer {
return new 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 { 'wcgateway.checkout-helper' => static function ( ContainerInterface $container ): CheckoutHelper {
return new CheckoutHelper(); return new CheckoutHelper();
}, },

View file

@ -22,13 +22,32 @@ class FundingSourceRenderer {
*/ */
protected $settings; protected $settings;
/**
* Map funding source ID -> human-readable name.
*
* @var array<string, string>
*/
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. * FundingSourceRenderer constructor.
* *
* @param ContainerInterface $settings The settings. * @param ContainerInterface $settings The settings.
* @param array<string, string> $funding_sources Map funding source ID -> human-readable name.
*/ */
public function __construct( ContainerInterface $settings ) { public function __construct(
ContainerInterface $settings,
array $funding_sources
) {
$this->settings = $settings; $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'. * @param string $id The ID of the funding source, such as 'venmo'.
*/ */
public function render_name( string $id ): string { public function render_name( string $id ): string {
if ( 'venmo' === $id ) { if ( array_key_exists( $id, $this->funding_sources ) ) {
return __( 'Venmo', 'woocommerce-paypal-payments' ); 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' ) ? return $this->settings->has( 'title' ) ?
$this->settings->get( 'title' ) $this->settings->get( 'title' )
: __( 'PayPal', 'woocommerce-paypal-payments' ); : __( 'PayPal', 'woocommerce-paypal-payments' );
@ -51,9 +78,14 @@ class FundingSourceRenderer {
* @param string $id The ID of the funding source, such as 'venmo'. * @param string $id The ID of the funding source, such as 'venmo'.
*/ */
public function render_description( string $id ): string { public function render_description( string $id ): string {
if ( 'venmo' === $id ) { if ( array_key_exists( $id, $this->funding_sources ) ) {
return __( 'Pay via Venmo.', 'woocommerce-paypal-payments' ); 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' ) ? return $this->settings->has( 'description' ) ?
$this->settings->get( 'description' ) $this->settings->get( 'description' )
: __( 'Pay via PayPal.', 'woocommerce-paypal-payments' ); : __( 'Pay via PayPal.', 'woocommerce-paypal-payments' );

View file

@ -179,7 +179,7 @@ class WCGatewayModule implements ModuleInterface {
$c->get( 'onboarding.environment' ), $c->get( 'onboarding.environment' ),
$settings_status->is_pay_later_button_enabled(), $settings_status->is_pay_later_button_enabled(),
$settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(), $settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(),
$c->get( 'wcgateway.all-funding-sources' ) $c->get( 'wcgateway.settings.funding-sources' )
); );
$assets->register_assets(); $assets->register_assets();
} }

View file

@ -59,7 +59,10 @@ class WcGatewayTest extends TestCase
$this->environment = Mockery::mock(Environment::class); $this->environment = Mockery::mock(Environment::class);
$this->paymentTokenRepository = Mockery::mock(PaymentTokenRepository::class); $this->paymentTokenRepository = Mockery::mock(PaymentTokenRepository::class);
$this->logger = Mockery::mock(LoggerInterface::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->apiShopCountry = 'DE';
$this->onboardingState->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED); $this->onboardingState->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED);
@ -271,6 +274,8 @@ class WcGatewayTest extends TestCase
return [ return [
[null, 'PayPal', 'Pay via PayPal.'], [null, 'PayPal', 'Pay via PayPal.'],
['venmo', 'Venmo', 'Pay via Venmo.'], ['venmo', 'Venmo', 'Pay via Venmo.'],
['paylater', 'Pay Later', 'Pay via Pay Later.'],
['blik', 'BLIK (via PayPal)', 'Pay via BLIK.'],
['qwerty', 'PayPal', 'Pay via PayPal.'], ['qwerty', 'PayPal', 'Pay via PayPal.'],
]; ];
} }