Merge branch 'trunk' into PCP-155-tracking-api

This commit is contained in:
dinamiko 2022-08-18 15:50:16 +02:00
commit 8a052166ff
11 changed files with 275 additions and 27 deletions

View file

@ -1,5 +1,16 @@
*** Changelog ***
= 1.9.3 - TBD =
* Fix - Transaction ID in order not updated when manually capturing authorized payment from WC #766
* Fix - Failed form validation on Checkout page causing page to be sticky #781
* Fix - Do not include full path in exception #779
* Enhancement - Add links to docs & support in plugin #782
* Enhancement - Put gateway sub-options into tabs #772
* Enhancement - Show tabs only after onboarding #789
* Enhancement - Add header on settings page #790
* Enhancement - PUI add option for a phone number field next to the Birth Date field #742
* Enhancement - PUI gateway availability on pay for order page with unsupported currency #744
= 1.9.2 - 2022-08-09 =
* Fix - Do not allow birth date older than 100 years for PUI. #743
* Fix - Store the customer id for vaulted payment method in usermeta to not lose vaulted methods after the invoice prefix change. #698

View file

@ -66,7 +66,7 @@ const bootstrap = () => {
errorHandler.clear();
if (messages.length) {
messages.forEach(s => errorHandler.message(s));
errorHandler.messages(messages);
} else {
errorHandler.message(PayPalCommerceGateway.labels.error.required.generic);
}

View file

@ -17,21 +17,48 @@ class ErrorHandler {
appendPreparedErrorMessageElement(errorMessageElement)
{
if(this.messagesList === null) {
this.prepareMessagesList();
if (this.messagesList === null) {
this._prepareMessagesList();
}
this.messagesList.replaceWith(errorMessageElement);
}
/**
* @param {String} text
* @param {Boolean} persist
*/
message(text, persist = false)
{
if(! typeof String || text.length === 0){
this._addMessage(text, persist);
this._scrollToMessages();
}
/**
* @param {Array} texts
* @param {Boolean} persist
*/
messages(texts, persist = false)
{
texts.forEach(t => this._addMessage(t, persist));
this._scrollToMessages();
}
/**
* @private
* @param {String} text
* @param {Boolean} persist
*/
_addMessage(text, persist = false)
{
if(! typeof String || text.length === 0) {
throw new Error('A new message text must be a non-empty string.');
}
if(this.messagesList === null){
this.prepareMessagesList();
if (this.messagesList === null){
this._prepareMessagesList();
}
if (persist) {
@ -40,15 +67,24 @@ class ErrorHandler {
this.wrapper.classList.remove('ppcp-persist');
}
let messageNode = this.prepareMessagesListItem(text);
let messageNode = this._prepareMessagesListItem(text);
this.messagesList.appendChild(messageNode);
jQuery.scroll_to_notices(jQuery('.woocommerce-notices-wrapper'))
}
prepareMessagesList()
/**
* @private
*/
_scrollToMessages()
{
if(this.messagesList === null){
jQuery.scroll_to_notices(jQuery('.woocommerce-notices-wrapper'));
}
/**
* @private
*/
_prepareMessagesList()
{
if (this.messagesList === null) {
this.messagesList = document.createElement('ul');
this.messagesList.setAttribute('class', 'woocommerce-error');
this.messagesList.setAttribute('role', 'alert');
@ -56,7 +92,10 @@ class ErrorHandler {
}
}
prepareMessagesListItem(message)
/**
* @private
*/
_prepareMessagesListItem(message)
{
const li = document.createElement('li');
li.innerHTML = message;
@ -64,13 +103,6 @@ class ErrorHandler {
return li;
}
sanitize(text)
{
const textarea = document.createElement('textarea');
textarea.innerHTML = text;
return textarea.value.replace('Error: ', '');
}
clear()
{
if (this.messagesList === null) {

View file

@ -168,3 +168,53 @@ ul.ppcp-onboarding-options-sublist {
height: 23px;
}
}
.ppcp-settings-page-header {
display: flex;
align-items: center;
max-width: 1200px;
margin-top: 10px;
}
.ppcp-settings-page-header img {
height: 30px;
}
.ppcp-settings-page-header h4 {
margin: 0 15px 0 5px;
}
.ppcp-settings-page-header .button, .ppcp-settings-page-header a {
margin: 0 5px;
}
.ppcp-right-align {
margin-left: auto;
}
.ppcp-settings-page-header a {
text-decoration: none;
}
@media (max-width: 1200px) {
.ppcp-settings-page-header {
display: block;
}
.ppcp-settings-page-header .ppcp-right-align {
display: block;
margin-left: 0;
}
.ppcp-settings-page-header .button, .ppcp-settings-page-header a {
margin: 5px 10px 5px 0;
}
.ppcp-settings-page-header .ppcp-inline-only {
display: none;
}
.ppcp-settings-page-header h4 {
margin-left: 0;
}
}

View file

@ -54,6 +54,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Notice\GatewayWithoutPayPalAdminNotice;
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Settings\HeaderRenderer;
use WooCommerce\PayPalCommerce\WcGateway\Settings\SectionsRenderer;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener;
@ -201,7 +202,14 @@ return array(
'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer {
return new SectionsRenderer(
$container->get( 'wcgateway.current-ppcp-settings-page-id' ),
$container->get( 'wcgateway.settings.sections' )
$container->get( 'wcgateway.settings.sections' ),
$container->get( 'onboarding.state' )
);
},
'wcgateway.settings.header-renderer' => static function ( ContainerInterface $container ): HeaderRenderer {
return new HeaderRenderer(
$container->get( 'wcgateway.current-ppcp-settings-page-id' ),
$container->get( 'wcgateway.url' )
);
},
'wcgateway.settings.sections' => static function ( ContainerInterface $container ): array {

View file

@ -0,0 +1,82 @@
<?php
/**
* Renders the settings page header.
*
* @package WooCommerce\PayPalCommerce\WcGateway\Settings
*/
declare( strict_types=1 );
namespace WooCommerce\PayPalCommerce\WcGateway\Settings;
/**
* Class HeaderRenderer
*/
class HeaderRenderer {
const KEY = 'ppcp-tab';
/**
* ID of the current PPCP gateway settings page, or empty if it is not such page.
*
* @var string
*/
private $page_id;
/**
* The URL to the module.
*
* @var string
*/
private $module_url;
/**
* HeaderRenderer constructor.
*
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
* @param string $module_url The URL to the module.
*/
public function __construct( string $page_id, string $module_url ) {
$this->page_id = $page_id;
$this->module_url = $module_url;
}
/**
* Whether the sections tab should be rendered.
*
* @return bool
*/
public function should_render() : bool {
return ! empty( $this->page_id );
}
/**
* Renders the Sections tab.
*/
public function render(): string {
if ( ! $this->should_render() ) {
return '';
}
return '
<div class="ppcp-settings-page-header">
<img alt="PayPal" src="' . esc_url( $this->module_url ) . 'assets/images/paypal.png"/>
<h4> <span class="ppcp-inline-only">-</span> ' . __( 'The all-in-one checkout solution for WooCommerce', 'woocommerce-paypal-payments' ) . '</h4>
<a class="button" href="https://woocommerce.com/document/woocommerce-paypal-payments/">'
. __( 'Documentation', 'woocommerce-paypal-payments' ) .
'</a>
<a class="button" href="https://woocommerce.com/my-account/create-a-ticket/">'
. __( 'Get Help', 'woocommerce-paypal-payments' ) .
'</a>
<span class="ppcp-right-align">
<a href="https://woocommerce.com/feature-requests/woocommerce-paypal-payments/">'
. __( 'Request a feature', 'woocommerce-paypal-payments' ) .
'</a>
<a href="https://github.com/woocommerce/woocommerce-paypal-payments/issues/new?assignees=&labels=type%3A+bug&template=bug_report.md">'
. __( 'Submit a bug', 'woocommerce-paypal-payments' ) .
'</a>
</span>
</div>
';
}
}

View file

@ -9,6 +9,7 @@ declare( strict_types=1 );
namespace WooCommerce\PayPalCommerce\WcGateway\Settings;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\Webhooks\Status\WebhooksStatusPage;
@ -33,15 +34,24 @@ class SectionsRenderer {
*/
protected $sections;
/**
* The onboarding state.
*
* @var State
*/
private $state;
/**
* SectionsRenderer constructor.
*
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
* @param array<string, string> $sections Key - page/gateway ID, value - displayed text.
* @param State $state The onboarding state.
*/
public function __construct( string $page_id, array $sections ) {
public function __construct( string $page_id, array $sections, State $state ) {
$this->page_id = $page_id;
$this->sections = $sections;
$this->state = $state;
}
/**
@ -50,7 +60,9 @@ class SectionsRenderer {
* @return bool
*/
public function should_render() : bool {
return ! empty( $this->page_id );
return ! empty( $this->page_id ) &&
( $this->state->production_state() === State::STATE_ONBOARDED ||
$this->state->sandbox_state() === State::STATE_ONBOARDED );
}
/**

View file

@ -31,6 +31,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
use WooCommerce\PayPalCommerce\WcGateway\Notice\GatewayWithoutPayPalAdminNotice;
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Settings\HeaderRenderer;
use WooCommerce\PayPalCommerce\WcGateway\Settings\SectionsRenderer;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener;
@ -65,11 +66,14 @@ class WCGatewayModule implements ModuleInterface {
add_action(
'woocommerce_sections_checkout',
function() use ( $c ) {
$header_renderer = $c->get( 'wcgateway.settings.header-renderer' );
assert( $header_renderer instanceof HeaderRenderer );
$section_renderer = $c->get( 'wcgateway.settings.sections-renderer' );
assert( $section_renderer instanceof SectionsRenderer );
// phpcs:ignore WordPress.Security.EscapeOutput
echo $section_renderer->render();
echo $header_renderer->render() . $section_renderer->render();
},
20
);

View file

@ -1,6 +1,6 @@
{
"name": "woocommerce-paypal-payments",
"version": "1.9.2",
"version": "1.9.3",
"description": "WooCommerce PayPal Payments",
"repository": "https://github.com/woocommerce/woocommerce-paypal-payments",
"license": "GPL-2.0",

View file

@ -4,7 +4,7 @@ Tags: woocommerce, paypal, payments, ecommerce, e-commerce, store, sales, sell,
Requires at least: 5.3
Tested up to: 6.0
Requires PHP: 7.1
Stable tag: 1.9.2
Stable tag: 1.9.3
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@ -81,6 +81,17 @@ Follow the steps below to connect the plugin to your PayPal account:
== Changelog ==
= 1.9.3 =
* Fix - Transaction ID in order not updated when manually capturing authorized payment from WC #766
* Fix - Failed form validation on Checkout page causing page to be sticky #781
* Fix - Do not include full path in exception #779
* Enhancement - Add links to docs & support in plugin #782
* Enhancement - Put gateway sub-options into tabs #772
* Enhancement - Show tabs only after onboarding #789
* Enhancement - Add header on settings page #790
* Enhancement - PUI add option for a phone number field next to the Birth Date field #742
* Enhancement - PUI gateway availability on pay for order page with unsupported currency #744
= 1.9.2 =
* Fix - Do not allow birth date older than 100 years for PUI. #743
* Fix - Store the customer id for vaulted payment method in usermeta to not lose vaulted methods after the invoice prefix change. #698

View file

@ -3,13 +3,13 @@
* Plugin Name: WooCommerce PayPal Payments
* Plugin URI: https://woocommerce.com/products/woocommerce-paypal-payments/
* Description: PayPal's latest complete payments processing solution. Accept PayPal, Pay Later, credit/debit cards, alternative digital wallets local payment types and bank accounts. Turn on only PayPal options or process a full suite of payment methods. Enable global transaction with extensive currency and country coverage.
* Version: 1.9.2
* Version: 1.9.3
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* License: GPL-2.0
* Requires PHP: 7.1
* WC requires at least: 3.9
* WC tested up to: 6.7
* WC tested up to: 6.8
* Text Domain: woocommerce-paypal-payments
*
* @package WooCommerce\PayPalCommerce
@ -143,6 +143,44 @@ define( 'PPCP_FLAG_SEPARATE_APM_BUTTONS', apply_filters( 'woocommerce_paypal_pay
}
);
// Add links below the description on the Plugins page.
add_filter(
'plugin_row_meta',
function( $links, $file ) {
if ( plugin_basename( __FILE__ ) !== $file ) {
return $links;
}
return array_merge(
$links,
array(
sprintf(
'<a href="%1$s">%2$s</a>',
'https://woocommerce.com/document/woocommerce-paypal-payments/',
__( 'Documentation', 'woocommerce-paypal-payments' )
),
sprintf(
'<a href="%1$s">%2$s</a>',
'https://woocommerce.com/my-account/create-a-ticket/',
__( 'Get help', 'woocommerce-paypal-payments' )
),
sprintf(
'<a href="%1$s">%2$s</a>',
'https://woocommerce.com/feature-requests/woocommerce-paypal-payments/',
__( 'Request a feature', 'woocommerce-paypal-payments' )
),
sprintf(
'<a href="%1$s">%2$s</a>',
'https://github.com/woocommerce/woocommerce-paypal-payments/issues/new?assignees=&labels=type%3A+bug&template=bug_report.md',
__( 'Submit a bug', 'woocommerce-paypal-payments' )
),
)
);
},
10,
2
);
/**
* Check if WooCommerce is active.
*