Merge pull request #1186 from woocommerce/PCP-1447-fix-preview-country

Do not send buyer-country for previews in live mode to avoid error
This commit is contained in:
Emili Castells 2023-02-23 11:52:28 +01:00 committed by GitHub
commit 018ef8603a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 2 deletions

View file

@ -114,10 +114,13 @@ import {setVisibleByClass, isVisible} from "../../../ppcp-button/resources/js/mo
'integration-date': PayPalCommerceGatewaySettings.integration_date,
'components': ['buttons', 'funding-eligibility', 'messages'],
'enable-funding': ['venmo', 'paylater'],
'buyer-country': PayPalCommerceGatewaySettings.country,
};
if(payLaterButtonPreview?.length) {
if (PayPalCommerceGatewaySettings.environment === 'sandbox') {
settings['buyer-country'] = PayPalCommerceGatewaySettings.country;
}
if (payLaterButtonPreview?.length) {
disabledSources = Object.keys(PayPalCommerceGatewaySettings.all_funding_sources);
}

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
/**
@ -58,6 +59,13 @@ class SettingsPageAssets {
*/
private $country;
/**
* The environment object.
*
* @var Environment
*/
private $environment;
/**
* Whether Pay Later button is enabled either for checkout, cart or product page.
*
@ -88,6 +96,7 @@ class SettingsPageAssets {
* @param string $client_id The PayPal SDK client ID.
* @param string $currency 3-letter currency code of the shop.
* @param string $country 2-letter country code of the shop.
* @param Environment $environment The environment object.
* @param bool $is_pay_later_button_enabled Whether Pay Later button is enabled either for checkout, cart or product page.
* @param array $disabled_sources The list of disabled funding sources.
* @param array $all_funding_sources The list of all existing funding sources.
@ -99,6 +108,7 @@ class SettingsPageAssets {
string $client_id,
string $currency,
string $country,
Environment $environment,
bool $is_pay_later_button_enabled,
array $disabled_sources,
array $all_funding_sources
@ -109,6 +119,7 @@ class SettingsPageAssets {
$this->client_id = $client_id;
$this->currency = $currency;
$this->country = $country;
$this->environment = $environment;
$this->is_pay_later_button_enabled = $is_pay_later_button_enabled;
$this->disabled_sources = $disabled_sources;
$this->all_funding_sources = $all_funding_sources;
@ -191,6 +202,7 @@ class SettingsPageAssets {
'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,

View file

@ -174,6 +174,7 @@ class WCGatewayModule implements ModuleInterface {
$c->get( 'button.client_id_for_admin' ),
$c->get( 'api.shop.currency' ),
$c->get( 'api.shop.country' ),
$c->get( 'onboarding.environment' ),
$settings_status->is_pay_later_button_enabled(),
$settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(),
$c->get( 'wcgateway.all-funding-sources' )