mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
Merge pull request #398 from woocommerce/pcp-400-show-funding-source
Show "Venmo" instead of "PayPal" when using its' button
This commit is contained in:
commit
d5823c1254
13 changed files with 293 additions and 169 deletions
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/**
|
||||
* Renders info about funding sources like Venmo.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\WcGateway\FundingSource
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\FundingSource;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class FundingSourceRenderer
|
||||
*/
|
||||
class FundingSourceRenderer {
|
||||
/**
|
||||
* The settings.
|
||||
*
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* FundingSourceRenderer constructor.
|
||||
*
|
||||
* @param ContainerInterface $settings The settings.
|
||||
*/
|
||||
public function __construct( ContainerInterface $settings ) {
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of the funding source (suitable for displaying to user).
|
||||
*
|
||||
* @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' );
|
||||
}
|
||||
return $this->settings->has( 'title' ) ?
|
||||
$this->settings->get( 'title' )
|
||||
: __( 'PayPal', 'woocommerce-paypal-payments' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of the funding source (for checkout).
|
||||
*
|
||||
* @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' );
|
||||
}
|
||||
return $this->settings->has( 'description' ) ?
|
||||
$this->settings->get( 'description' )
|
||||
: __( 'Pay via PayPal.', 'woocommerce-paypal-payments' );
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ use WooCommerce\PayPalCommerce\Onboarding\State;
|
|||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
|
||||
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\FundingSource\FundingSourceRenderer;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
|
||||
|
@ -44,6 +45,13 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
*/
|
||||
protected $settings_renderer;
|
||||
|
||||
/**
|
||||
* The funding source renderer.
|
||||
*
|
||||
* @var FundingSourceRenderer
|
||||
*/
|
||||
protected $funding_source_renderer;
|
||||
|
||||
/**
|
||||
* The processor for orders.
|
||||
*
|
||||
|
@ -153,6 +161,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
* PayPalGateway constructor.
|
||||
*
|
||||
* @param SettingsRenderer $settings_renderer The Settings Renderer.
|
||||
* @param FundingSourceRenderer $funding_source_renderer The funding source renderer.
|
||||
* @param OrderProcessor $order_processor The Order Processor.
|
||||
* @param AuthorizedPaymentsProcessor $authorized_payments_processor The Authorized Payments Processor.
|
||||
* @param ContainerInterface $config The settings.
|
||||
|
@ -170,6 +179,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
*/
|
||||
public function __construct(
|
||||
SettingsRenderer $settings_renderer,
|
||||
FundingSourceRenderer $funding_source_renderer,
|
||||
OrderProcessor $order_processor,
|
||||
AuthorizedPaymentsProcessor $authorized_payments_processor,
|
||||
ContainerInterface $config,
|
||||
|
@ -190,6 +200,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
$this->order_processor = $order_processor;
|
||||
$this->authorized_payments_processor = $authorized_payments_processor;
|
||||
$this->settings_renderer = $settings_renderer;
|
||||
$this->funding_source_renderer = $funding_source_renderer;
|
||||
$this->config = $config;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->refund_processor = $refund_processor;
|
||||
|
@ -241,6 +252,12 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
$this->description = $this->config->has( 'description' ) ?
|
||||
$this->config->get( 'description' ) : $this->method_description;
|
||||
|
||||
$funding_source = $this->session_handler->funding_source();
|
||||
if ( $funding_source ) {
|
||||
$this->title = $this->funding_source_renderer->render_name( $funding_source );
|
||||
$this->description = $this->funding_source_renderer->render_description( $funding_source );
|
||||
}
|
||||
|
||||
$this->init_form_fields();
|
||||
$this->init_settings();
|
||||
|
||||
|
@ -344,8 +361,15 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
);
|
||||
}
|
||||
|
||||
if ( is_admin() ) {
|
||||
return __(
|
||||
'Accept PayPal, Pay Later and alternative payment types.',
|
||||
'woocommerce-paypal-payments'
|
||||
);
|
||||
}
|
||||
|
||||
return __(
|
||||
'Accept PayPal, Pay Later and alternative payment types.',
|
||||
'Pay via PayPal.',
|
||||
'woocommerce-paypal-payments'
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue