mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
phpcs
This commit is contained in:
parent
0ce7c248fe
commit
d96f4593a6
8 changed files with 72 additions and 51 deletions
|
@ -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');
|
||||||
|
@ -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()
|
||||||
{
|
{
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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',
|
||||||
|
|
|
@ -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])) {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -193,18 +194,19 @@ class SettingsRenderer
|
||||||
<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 href="#">',
|
|
||||||
'</a>'
|
'</a>'
|
||||||
)
|
)
|
||||||
); ?>
|
); ?>
|
||||||
|
@ -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) . '"
|
||||||
>';
|
> ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue