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

View file

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

View file

@ -1,22 +1,20 @@
<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\Button\Helper;
use Inpsyde\PayPalCommerce\ApiClient\Helper\DccApplies;
class MessagesApply
{
private $countries = [
'US',
];
public function forCountry() : bool
{
public function forCountry(): bool
{
$region = wc_get_base_location();
$country = $region['country'];
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 Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
//phpcs:disable Inpsyde.CodeQuality.NoAccessors.NoGetter
//phpcs:disable Inpsyde.CodeQuality.ReturnTypeDeclaration.NoReturnType
class CreditCardGateway extends PayPalGateway
{
public const ID = 'ppcp-credit-card-gateway';
@ -32,7 +34,12 @@ class CreditCardGateway extends PayPalGateway
$this->notice = $notice;
$this->settingsRenderer = $settingsRenderer;
$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 = [
'products',
'subscriptions',
@ -97,7 +104,9 @@ class CreditCardGateway extends PayPalGateway
return $content;
}
public function get_title() {
public function get_title()
{
if (is_admin()) {
return parent::get_title();
}
@ -117,7 +126,7 @@ class CreditCardGateway extends PayPalGateway
'hiper' => _x('Hiper', 'Name of credit card', 'woocommerce-paypal-commerce-gateway'),
];
$images = array_map(
function(string $type) use ($titleOptions) : string {
function (string $type) use ($titleOptions): string {
return '<img
title="' . esc_attr($titleOptions[$type]) . '"
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->settingsRenderer = $settingsRenderer;
$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 = [
'products',
'subscriptions',

View file

@ -82,7 +82,10 @@ class Settings implements ContainerInterface
'button_cart_enabled' => true,
'brand_name' => get_bloginfo('name'),
'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) {
if (isset($this->settings[$key])) {

View file

@ -93,7 +93,8 @@ class SettingsListener
$this->webhookRegistrar->register();
}
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 (
$settings['client_id'] !== $this->settings->get('client_id')
|| $settings['client_secret'] !== $currentSecret

View file

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