mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +08:00
Merge pull request #1719 from woocommerce/PCP-2006-google-pay-settings-improvements
Google Pay Settings improvements (2006)
This commit is contained in:
commit
c07e8eaa87
55 changed files with 1784 additions and 243 deletions
|
@ -16,7 +16,7 @@ document.addEventListener(
|
|||
jQuery( '*[data-ppcp-display]' ).each( (index, el) => {
|
||||
const rules = jQuery(el).data('ppcpDisplay');
|
||||
|
||||
console.log('rules', rules);
|
||||
// console.log('rules', rules);
|
||||
|
||||
for (const rule of rules) {
|
||||
displayManager.addRule(rule);
|
||||
|
|
|
@ -14,11 +14,11 @@ class DisplayManager {
|
|||
addRule(ruleConfig) {
|
||||
const updateStatus = () => {
|
||||
this.ruleStatus[ruleConfig.key] = this.rules[ruleConfig.key].status;
|
||||
console.log('ruleStatus', this.ruleStatus);
|
||||
//console.log('ruleStatus', this.ruleStatus);
|
||||
}
|
||||
|
||||
this.rules[ruleConfig.key] = new Rule(ruleConfig, updateStatus.bind(this));
|
||||
console.log('Rule', this.rules[ruleConfig.key]);
|
||||
//console.log('Rule', this.rules[ruleConfig.key]);
|
||||
}
|
||||
|
||||
register() {
|
||||
|
|
|
@ -15,14 +15,14 @@ class Rule {
|
|||
const condition = ConditionFactory.make(conditionConfig, updateStatus);
|
||||
this.conditions[condition.key] = condition;
|
||||
|
||||
console.log('Condition', condition);
|
||||
//console.log('Condition', condition);
|
||||
}
|
||||
|
||||
for (const actionConfig of this.config.actions) {
|
||||
const action = ActionFactory.make(actionConfig);
|
||||
this.actions[action.key] = action;
|
||||
|
||||
console.log('Action', action);
|
||||
//console.log('Action', action);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -87,6 +87,7 @@ document.addEventListener(
|
|||
|
||||
try {
|
||||
renderer.render({});
|
||||
jQuery(document).trigger('ppcp_paypal_render_preview', settings);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
@ -113,7 +114,7 @@ document.addEventListener(
|
|||
'client-id': PayPalCommerceGatewaySettings.client_id,
|
||||
'currency': PayPalCommerceGatewaySettings.currency,
|
||||
'integration-date': PayPalCommerceGatewaySettings.integration_date,
|
||||
'components': ['buttons', 'funding-eligibility', 'messages'],
|
||||
'components': PayPalCommerceGatewaySettings.components,
|
||||
'enable-funding': ['venmo', 'paylater'],
|
||||
};
|
||||
|
||||
|
|
|
@ -1021,7 +1021,8 @@ return array(
|
|||
$partner_endpoint,
|
||||
$container->get( 'dcc.status-cache' ),
|
||||
$container->get( 'api.helpers.dccapplies' ),
|
||||
$container->get( 'onboarding.state' )
|
||||
$container->get( 'onboarding.state' ),
|
||||
$container->get( 'api.helper.failure-registry' )
|
||||
);
|
||||
},
|
||||
|
||||
|
@ -1101,7 +1102,8 @@ return array(
|
|||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'api.endpoint.partners' ),
|
||||
$container->get( 'pui.status-cache' ),
|
||||
$container->get( 'onboarding.state' )
|
||||
$container->get( 'onboarding.state' ),
|
||||
$container->get( 'api.helper.failure-registry' )
|
||||
);
|
||||
},
|
||||
'wcgateway.pay-upon-invoice' => static function ( ContainerInterface $container ): PayUponInvoice {
|
||||
|
|
|
@ -211,16 +211,20 @@ class SettingsPageAssets {
|
|||
wp_localize_script(
|
||||
'ppcp-gateway-settings',
|
||||
'PayPalCommerceGatewaySettings',
|
||||
array(
|
||||
'is_subscriptions_plugin_active' => $this->subscription_helper->plugin_is_active(),
|
||||
'client_id' => $this->client_id,
|
||||
'currency' => $this->currency,
|
||||
'country' => $this->country,
|
||||
'environment' => $this->environment->current_environment(),
|
||||
'integration_date' => PAYPAL_INTEGRATION_DATE,
|
||||
'is_pay_later_button_enabled' => $this->is_pay_later_button_enabled,
|
||||
'disabled_sources' => $this->disabled_sources,
|
||||
'all_funding_sources' => $this->all_funding_sources,
|
||||
apply_filters(
|
||||
'woocommerce_paypal_payments_admin_gateway_settings',
|
||||
array(
|
||||
'is_subscriptions_plugin_active' => $this->subscription_helper->plugin_is_active(),
|
||||
'client_id' => $this->client_id,
|
||||
'currency' => $this->currency,
|
||||
'country' => $this->country,
|
||||
'environment' => $this->environment->current_environment(),
|
||||
'integration_date' => PAYPAL_INTEGRATION_DATE,
|
||||
'is_pay_later_button_enabled' => $this->is_pay_later_button_enabled,
|
||||
'disabled_sources' => $this->disabled_sources,
|
||||
'all_funding_sources' => $this->all_funding_sources,
|
||||
'components' => array( 'buttons', 'funding-eligibility', 'messages' ),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -142,6 +142,20 @@ class PayUponInvoice {
|
|||
$this->settings->persist();
|
||||
}
|
||||
|
||||
add_filter(
|
||||
'ppcp_partner_referrals_option',
|
||||
function ( array $option ): array {
|
||||
if ( $option['valid'] ) {
|
||||
return $option;
|
||||
}
|
||||
if ( $option['field'] === 'ppcp-onboarding-pui' ) {
|
||||
$option['valid'] = true;
|
||||
$option['value'] = ( $option['value'] ? '1' : '' );
|
||||
}
|
||||
return $option;
|
||||
}
|
||||
);
|
||||
|
||||
add_filter(
|
||||
'ppcp_partner_referrals_data',
|
||||
function ( array $data ): array {
|
||||
|
|
|
@ -14,6 +14,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusProduct;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\FailureRegistry;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
|
@ -37,6 +38,14 @@ class DCCProductStatus {
|
|||
* @var bool|null
|
||||
*/
|
||||
private $current_status_cache;
|
||||
|
||||
/**
|
||||
* If there was a request failure.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $has_request_failure = false;
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*
|
||||
|
@ -65,6 +74,13 @@ class DCCProductStatus {
|
|||
*/
|
||||
private $onboarding_state;
|
||||
|
||||
/**
|
||||
* The API failure registry
|
||||
*
|
||||
* @var FailureRegistry
|
||||
*/
|
||||
private $api_failure_registry;
|
||||
|
||||
/**
|
||||
* DccProductStatus constructor.
|
||||
*
|
||||
|
@ -73,19 +89,22 @@ class DCCProductStatus {
|
|||
* @param Cache $cache The cache.
|
||||
* @param DccApplies $dcc_applies The dcc applies helper.
|
||||
* @param State $onboarding_state The onboarding state.
|
||||
* @param FailureRegistry $api_failure_registry The API failure registry.
|
||||
*/
|
||||
public function __construct(
|
||||
Settings $settings,
|
||||
PartnersEndpoint $partners_endpoint,
|
||||
Cache $cache,
|
||||
DccApplies $dcc_applies,
|
||||
State $onboarding_state
|
||||
State $onboarding_state,
|
||||
FailureRegistry $api_failure_registry
|
||||
) {
|
||||
$this->settings = $settings;
|
||||
$this->partners_endpoint = $partners_endpoint;
|
||||
$this->cache = $cache;
|
||||
$this->dcc_applies = $dcc_applies;
|
||||
$this->onboarding_state = $onboarding_state;
|
||||
$this->settings = $settings;
|
||||
$this->partners_endpoint = $partners_endpoint;
|
||||
$this->cache = $cache;
|
||||
$this->dcc_applies = $dcc_applies;
|
||||
$this->onboarding_state = $onboarding_state;
|
||||
$this->api_failure_registry = $api_failure_registry;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,9 +130,17 @@ class DCCProductStatus {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Check API failure registry to prevent multiple failed API requests.
|
||||
if ( $this->api_failure_registry->has_failure_in_timeframe( FailureRegistry::SELLER_STATUS_KEY, HOUR_IN_SECONDS ) ) {
|
||||
$this->has_request_failure = true;
|
||||
$this->current_status_cache = false;
|
||||
return $this->current_status_cache;
|
||||
}
|
||||
|
||||
try {
|
||||
$seller_status = $this->partners_endpoint->seller_status();
|
||||
} catch ( Throwable $error ) {
|
||||
$this->has_request_failure = true;
|
||||
$this->current_status_cache = false;
|
||||
return false;
|
||||
}
|
||||
|
@ -149,4 +176,14 @@ class DCCProductStatus {
|
|||
$this->current_status_cache = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if there was a request failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has_request_failure(): bool {
|
||||
return $this->has_request_failure;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ use Throwable;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusProduct;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\FailureRegistry;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
|
@ -36,6 +37,14 @@ class PayUponInvoiceProductStatus {
|
|||
* @var bool|null
|
||||
*/
|
||||
private $current_status_cache;
|
||||
|
||||
/**
|
||||
* If there was a request failure.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $has_request_failure = false;
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*
|
||||
|
@ -57,6 +66,13 @@ class PayUponInvoiceProductStatus {
|
|||
*/
|
||||
private $onboarding_state;
|
||||
|
||||
/**
|
||||
* The API failure registry
|
||||
*
|
||||
* @var FailureRegistry
|
||||
*/
|
||||
private $api_failure_registry;
|
||||
|
||||
/**
|
||||
* PayUponInvoiceProductStatus constructor.
|
||||
*
|
||||
|
@ -64,17 +80,20 @@ class PayUponInvoiceProductStatus {
|
|||
* @param PartnersEndpoint $partners_endpoint The Partner Endpoint.
|
||||
* @param Cache $cache The cache.
|
||||
* @param State $onboarding_state The onboarding state.
|
||||
* @param FailureRegistry $api_failure_registry The API failure registry.
|
||||
*/
|
||||
public function __construct(
|
||||
Settings $settings,
|
||||
PartnersEndpoint $partners_endpoint,
|
||||
Cache $cache,
|
||||
State $onboarding_state
|
||||
State $onboarding_state,
|
||||
FailureRegistry $api_failure_registry
|
||||
) {
|
||||
$this->settings = $settings;
|
||||
$this->partners_endpoint = $partners_endpoint;
|
||||
$this->cache = $cache;
|
||||
$this->onboarding_state = $onboarding_state;
|
||||
$this->settings = $settings;
|
||||
$this->partners_endpoint = $partners_endpoint;
|
||||
$this->cache = $cache;
|
||||
$this->onboarding_state = $onboarding_state;
|
||||
$this->api_failure_registry = $api_failure_registry;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,9 +118,17 @@ class PayUponInvoiceProductStatus {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Check API failure registry to prevent multiple failed API requests.
|
||||
if ( $this->api_failure_registry->has_failure_in_timeframe( FailureRegistry::SELLER_STATUS_KEY, HOUR_IN_SECONDS ) ) {
|
||||
$this->has_request_failure = true;
|
||||
$this->current_status_cache = false;
|
||||
return $this->current_status_cache;
|
||||
}
|
||||
|
||||
try {
|
||||
$seller_status = $this->partners_endpoint->seller_status();
|
||||
} catch ( Throwable $error ) {
|
||||
$this->has_request_failure = true;
|
||||
$this->current_status_cache = false;
|
||||
return false;
|
||||
}
|
||||
|
@ -136,4 +163,14 @@ class PayUponInvoiceProductStatus {
|
|||
$this->current_status_cache = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if there was a request failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has_request_failure(): bool {
|
||||
return $this->has_request_failure;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -456,7 +456,7 @@ return function ( ContainerInterface $container, array $fields ): array {
|
|||
'description' => __( 'If you use your PayPal account with more than one installation, please use a distinct prefix to separate those installations. Please use only English letters and "-", "_" characters.', 'woocommerce-paypal-payments' ),
|
||||
'maxlength' => 15,
|
||||
'custom_attributes' => array(
|
||||
'pattern' => '[a-zA-Z_-]+',
|
||||
'pattern' => '[a-zA-Z_\\-]+',
|
||||
),
|
||||
'default' => ( static function (): string {
|
||||
$site_url = get_site_url( get_current_blog_id() );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue