Merge pull request #1220 from woocommerce/PCP-259-log-payment-method

Show funding source as payment method
This commit is contained in:
Emili Castells 2023-03-16 15:12:27 +01:00 committed by GitHub
commit cbf64f5cb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 13 deletions

View file

@ -644,7 +644,7 @@ return array(
>',
'</a>'
),
'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',
)
)
);
},
@ -952,9 +963,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();
},

View file

@ -22,13 +22,32 @@ class FundingSourceRenderer {
*/
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.
*
* @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 ) {
$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' );

View file

@ -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();
}