This commit is contained in:
David Remer 2020-08-21 09:41:12 +03:00
parent 0ce7c248fe
commit d96f4593a6
8 changed files with 72 additions and 51 deletions

View file

@ -19,6 +19,7 @@ use Inpsyde\PayPalCommerce\Session\SessionHandler;
use Inpsyde\PayPalCommerce\Subscription\Helper\SubscriptionHelper; use Inpsyde\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings; use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
//phpcs:disable Inpsyde.CodeQuality.PropertyPerClassLimit.TooMuchProperties
class SmartButton implements SmartButtonInterface class SmartButton implements SmartButtonInterface
{ {
private $moduleUrl; private $moduleUrl;
@ -92,7 +93,8 @@ class SmartButton implements SmartButtonInterface
return true; return true;
} }
private function renderMessageWrapperRegistrar() : bool { private function renderMessageWrapperRegistrar(): bool
{
$notEnabledOnCart = $this->settings->has('message_cart_enabled') && $notEnabledOnCart = $this->settings->has('message_cart_enabled') &&
!$this->settings->get('message_cart_enabled'); !$this->settings->get('message_cart_enabled');
@ -126,7 +128,6 @@ class SmartButton implements SmartButtonInterface
); );
} }
$notEnabledOnCheckout = $this->settings->has('message_enabled') && $notEnabledOnCheckout = $this->settings->has('message_enabled') &&
!$this->settings->get('message_enabled'); !$this->settings->get('message_enabled');
if (! $notEnabledOnCheckout) { if (! $notEnabledOnCheckout) {
@ -141,7 +142,9 @@ class SmartButton implements SmartButtonInterface
} }
return true; return true;
} }
private function renderButtonWrapperRegistrar() : bool {
private function renderButtonWrapperRegistrar(): bool
{
$notEnabledOnCart = $this->settings->has('button_cart_enabled') && $notEnabledOnCart = $this->settings->has('button_cart_enabled') &&
!$this->settings->get('button_cart_enabled'); !$this->settings->get('button_cart_enabled');
@ -178,7 +181,7 @@ class SmartButton implements SmartButtonInterface
$notEnabledOnMiniCart = $this->settings->has('button_mini_cart_enabled') && $notEnabledOnMiniCart = $this->settings->has('button_mini_cart_enabled') &&
!$this->settings->get('button_mini_cart_enabled'); !$this->settings->get('button_mini_cart_enabled');
if ( if (
! $notEnabledOnMiniCart ! $notEnabledOnMiniCart
) { ) {
add_action( add_action(
'woocommerce_widget_shopping_cart_after_buttons', 'woocommerce_widget_shopping_cart_after_buttons',
@ -189,14 +192,7 @@ class SmartButton implements SmartButtonInterface
); );
} }
add_action( add_action('woocommerce_review_order_after_submit', [$this, 'buttonRenderer'], 10);
'woocommerce_review_order_after_submit',
[
$this,
'buttonRenderer',
],
10
);
return true; return true;
} }
@ -248,11 +244,15 @@ class SmartButton implements SmartButtonInterface
echo '<div id="ppc-button"></div>'; echo '<div id="ppc-button"></div>';
} }
public function messageRenderer() { public function messageRenderer()
{
echo '<div id="ppcp-messages"></div>'; echo '<div id="ppcp-messages"></div>';
} }
private function messageValues() : array { //phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong
private function messageValues(): array
{
if ( if (
$this->settings->has('disable_funding') $this->settings->has('disable_funding')
@ -338,6 +338,7 @@ class SmartButton implements SmartButtonInterface
return $values; return $values;
} }
//phpcs:enable Inpsyde.CodeQuality.FunctionLength.TooLong
public function dccRenderer() public function dccRenderer()
{ {

View file

@ -66,8 +66,10 @@ class CreateOrderEndpoint implements EndpointInterface
$this->sessionHandler->replaceBnCode($bnCode); $this->sessionHandler->replaceBnCode($bnCode);
$this->apiEndpoint->withBnCode($bnCode); $this->apiEndpoint->withBnCode($bnCode);
} }
$payeePreferred = $this->settings->has('payee_preferred') && $this->settings->get('payee_preferred') ? $payeePreferred = $this->settings->has('payee_preferred')
PaymentMethod::PAYEE_PREFERRED_IMMEDIATE_PAYMENT_REQUIRED :PaymentMethod::PAYEE_PREFERRED_UNRESTRICTED; && $this->settings->get('payee_preferred') ?
PaymentMethod::PAYEE_PREFERRED_IMMEDIATE_PAYMENT_REQUIRED
: PaymentMethod::PAYEE_PREFERRED_UNRESTRICTED;
$paymentMethod = new PaymentMethod($payeePreferred); $paymentMethod = new PaymentMethod($payeePreferred);
$order = $this->apiEndpoint->createForPurchaseUnits( $order = $this->apiEndpoint->createForPurchaseUnits(
$purchaseUnits, $purchaseUnits,

View file

@ -1,20 +1,18 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\Button\Helper; namespace Inpsyde\PayPalCommerce\Button\Helper;
use Inpsyde\PayPalCommerce\ApiClient\Helper\DccApplies;
class MessagesApply class MessagesApply
{ {
private $countries = [ private $countries = [
'US', 'US',
]; ];
public function forCountry() : bool
{
public function forCountry(): bool
{
$region = wc_get_base_location(); $region = wc_get_base_location();
$country = $region['country']; $country = $region['country'];
return in_array($country, $this->countries, true); return in_array($country, $this->countries, true);

View file

@ -12,6 +12,8 @@ use Psr\Container\ContainerInterface;
//phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps //phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
//phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType //phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
//phpcs:disable Inpsyde.CodeQuality.NoAccessors.NoGetter
//phpcs:disable Inpsyde.CodeQuality.ReturnTypeDeclaration.NoReturnType
class CreditCardGateway extends PayPalGateway class CreditCardGateway extends PayPalGateway
{ {
public const ID = 'ppcp-credit-card-gateway'; public const ID = 'ppcp-credit-card-gateway';
@ -32,7 +34,12 @@ class CreditCardGateway extends PayPalGateway
$this->notice = $notice; $this->notice = $notice;
$this->settingsRenderer = $settingsRenderer; $this->settingsRenderer = $settingsRenderer;
$this->config = $config; $this->config = $config;
if (defined('PPCP_FLAG_SUBSCRIPTION') && PPCP_FLAG_SUBSCRIPTION && $this->config->has('vault_enabled') && $this->config->get('vault_enabled')) { if (
defined('PPCP_FLAG_SUBSCRIPTION')
&& PPCP_FLAG_SUBSCRIPTION
&& $this->config->has('vault_enabled')
&& $this->config->get('vault_enabled')
) {
$this->supports = [ $this->supports = [
'products', 'products',
'subscriptions', 'subscriptions',
@ -97,7 +104,9 @@ class CreditCardGateway extends PayPalGateway
return $content; return $content;
} }
public function get_title() { public function get_title()
{
if (is_admin()) { if (is_admin()) {
return parent::get_title(); return parent::get_title();
} }
@ -117,7 +126,7 @@ class CreditCardGateway extends PayPalGateway
'hiper' => _x('Hiper', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'), 'hiper' => _x('Hiper', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'),
]; ];
$images = array_map( $images = array_map(
function(string $type) use ($titleOptions) : string { function (string $type) use ($titleOptions): string {
return '<img return '<img
title="' . esc_attr($titleOptions[$type]) . '" title="' . esc_attr($titleOptions[$type]) . '"
src="' . esc_url($this->moduleUrl) . '/assets/images/' . esc_attr($type) . '.svg" src="' . esc_url($this->moduleUrl) . '/assets/images/' . esc_attr($type) . '.svg"

View file

@ -50,7 +50,12 @@ class PayPalGateway extends \WC_Payment_Gateway
$this->notice = $notice; $this->notice = $notice;
$this->settingsRenderer = $settingsRenderer; $this->settingsRenderer = $settingsRenderer;
$this->config = $config; $this->config = $config;
if (defined('PPCP_FLAG_SUBSCRIPTION') && PPCP_FLAG_SUBSCRIPTION && $this->config->has('vault_enabled') && $this->config->get('vault_enabled')) { if (
defined('PPCP_FLAG_SUBSCRIPTION')
&& PPCP_FLAG_SUBSCRIPTION
&& $this->config->has('vault_enabled')
&& $this->config->get('vault_enabled')
) {
$this->supports = [ $this->supports = [
'products', 'products',
'subscriptions', 'subscriptions',

View file

@ -82,7 +82,10 @@ class Settings implements ContainerInterface
'button_cart_enabled' => true, 'button_cart_enabled' => true,
'brand_name' => get_bloginfo('name'), 'brand_name' => get_bloginfo('name'),
'dcc_gateway_title' => __('Credit Cards', 'woocommerce-paypal-commerce-gateway'), 'dcc_gateway_title' => __('Credit Cards', 'woocommerce-paypal-commerce-gateway'),
'dcc_gateway_description' => __('Pay with your credit card.', 'woocommerce-paypal-commerce-gateway'), 'dcc_gateway_description' => __(
'Pay with your credit card.',
'woocommerce-paypal-commerce-gateway'
),
]; ];
foreach ($defaults as $key => $value) { foreach ($defaults as $key => $value) {
if (isset($this->settings[$key])) { if (isset($this->settings[$key])) {

View file

@ -93,7 +93,8 @@ class SettingsListener
$this->webhookRegistrar->register(); $this->webhookRegistrar->register();
} }
if ($this->settings->has('client_id')) { if ($this->settings->has('client_id')) {
$currentSecret = $this->settings->has('client_secret') ? $this->settings->get('client_secret') : ''; $currentSecret = $this->settings->has('client_secret') ?
$this->settings->get('client_secret') : '';
if ( if (
$settings['client_id'] !== $this->settings->get('client_id') $settings['client_id'] !== $this->settings->get('client_id')
|| $settings['client_secret'] !== $currentSecret || $settings['client_secret'] !== $currentSecret

View file

@ -45,8 +45,8 @@ class SettingsRenderer
$selected = (in_array($optionKey, $value, true)) ? 'selected="selected"' : ''; $selected = (in_array($optionKey, $value, true)) ? 'selected="selected"' : '';
$options[] = '<option value="' . esc_attr($optionKey) . '" ' . $selected . '>' . $options[] = '<option value="' . esc_attr($optionKey) . '" ' . $selected . '>' .
esc_html($optionValue) . esc_html($optionValue) .
'</option>'; '</option>';
} }
$html = sprintf( $html = sprintf(
@ -127,6 +127,7 @@ class SettingsRenderer
//phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType //phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
//phpcs:disable Inpsyde.CodeQuality.NestingLevel.High //phpcs:disable Inpsyde.CodeQuality.NestingLevel.High
//phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong
public function render(bool $isDcc) public function render(bool $isDcc)
{ {
@ -187,31 +188,32 @@ class SettingsRenderer
<?php endforeach; <?php endforeach;
if ($isDcc) : if ($isDcc) :
?> ?>
<tr> <tr>
<th><?php esc_html_e('3D Secure', 'woocommerce-paypal-commerce-gateway'); ?></th> <th><?php esc_html_e('3D Secure', 'woocommerce-paypal-commerce-gateway'); ?></th>
<td> <td>
<p> <p>
<?php <?php
/**
* @todo: Provide link to documentation.
*/
echo wp_kses_post( echo wp_kses_post(
sprintf( sprintf(
//translators: %s is a link tag. // translators: %1$s and %2$s is a link tag.
__( __(
'3D Secure benefits cardholders and merchants by providing an additional '3D Secure benefits cardholders and merchants by providing an additional
layer of verification using Verified by Visa, MasterCard SecureCode and layer of verification using Verified by Visa, MasterCard SecureCode and
American Express SafeKey. %sLearn more about 3D Secure.%s', American Express SafeKey. %1$sLearn more about 3D Secure.%2$s',
'woocommerce-paypal-commerce-gateway' 'woocommerce - paypal - commerce - gateway'
), ),
'<a href = "#">',
//ToDo: Provide link to documentation. '</a>'
'<a href="#">', )
'</a>' ); ?>
)
); ?>
</p> </p>
</td> </td>
</tr> </tr>
<?php <?php
endif; endif;
} }
//phpcs:enable Inpsyde.CodeQuality.NestingLevel.High //phpcs:enable Inpsyde.CodeQuality.NestingLevel.High
@ -223,11 +225,11 @@ class SettingsRenderer
$value = $this->settings->has($config['hidden']) ? $value = $this->settings->has($config['hidden']) ?
(string) $this->settings->get($config['hidden']) (string) $this->settings->get($config['hidden'])
: ''; : '';
echo '<input echo ' < input
type="hidden" type = "hidden"
name="ppcp[' . esc_attr($config['hidden']) . ']" name = "ppcp[' . esc_attr($config['hidden']) . ']"
value="' . esc_attr($value) . '" value = "' . esc_attr($value) . '"
>'; > ';
} }
} }
} }