mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 12:25:15 +08:00
load identity token also if dcc is enabled, phpcs
This commit is contained in:
parent
158db47134
commit
bb4fbd2dbd
1 changed files with 74 additions and 58 deletions
|
@ -206,65 +206,74 @@ class SmartButton implements SmartButtonInterface
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dccRenderer(bool $miniCart = false) {
|
// phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong
|
||||||
{
|
public function dccRenderer(bool $miniCart = false)
|
||||||
$id = ($miniCart) ? 'ppcp-hosted-fields-mini-cart' : 'ppcp-hosted-fields';
|
{
|
||||||
$canRenderDcc = $canRenderDcc = $this->dccApplies->forCountryCurrency() && $this->settings->has('client_id') && $this->settings->get('client_id');
|
|
||||||
if (! $canRenderDcc) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$product = wc_get_product();
|
|
||||||
if (
|
|
||||||
! $miniCart && !is_checkout() && is_a($product, \WC_Product::class)
|
|
||||||
&& (
|
|
||||||
$product->is_type(['external', 'grouped'])
|
|
||||||
|| !$product->is_in_stock()
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$saveCard = $this->saveVaultToken() ? sprintf(
|
|
||||||
'<div>
|
|
||||||
|
|
||||||
<label for="ppcp-vault-%1$s">%2$s</label>
|
$id = ($miniCart) ? 'ppcp-hosted-fields-mini-cart' : 'ppcp-hosted-fields';
|
||||||
<input
|
$canRenderDcc = $this->dccApplies->forCountryCurrency()
|
||||||
type="checkbox"
|
&& $this->settings->has('client_id')
|
||||||
id="ppcp-vault-%1$s"
|
&& $this->settings->get('client_id');
|
||||||
class="ppcp-credit-card-vault"
|
if (! $canRenderDcc) {
|
||||||
name="vault"
|
return;
|
||||||
>
|
}
|
||||||
</div>',
|
|
||||||
$id,
|
$product = wc_get_product();
|
||||||
esc_html__('Save your card', 'woocommerce-paypal-commerce-gateway')
|
if (
|
||||||
) : '';
|
! $miniCart && !is_checkout() && is_a($product, \WC_Product::class)
|
||||||
printf(
|
&& (
|
||||||
'<form id="%1$s">
|
$product->is_type(['external', 'grouped'])
|
||||||
<div class="ppcp-dcc-credit-card-wrapper">
|
|| !$product->is_in_stock()
|
||||||
<div>
|
)
|
||||||
<label for="ppcp-credit-card-%1$s">%2$s</label>
|
) {
|
||||||
<span id="ppcp-credit-card-%1$s" class="ppcp-credit-card"></span>
|
return;
|
||||||
</div><div>
|
}
|
||||||
<label for="ppcp-expiration-date-%1$s">%3$s</label>
|
$saveCard = $this->saveVaultToken() ? sprintf(
|
||||||
<span id="ppcp-expiration-date-%1$s" class="ppcp-expiration-date"></span>
|
'<div>
|
||||||
</div><div>
|
|
||||||
<label for="ppcp-cvv-%1$s">%4$s</label>
|
<label for="ppcp-vault-%1$s">%2$s</label>
|
||||||
<span id="ppcp-cvv-%1$s" class="ppcp-cvv"></span>
|
<input
|
||||||
</div>
|
type="checkbox"
|
||||||
%5$s
|
id="ppcp-vault-%1$s"
|
||||||
</div>
|
class="ppcp-credit-card-vault"
|
||||||
<button>%6$s</button>
|
name="vault"
|
||||||
</form><div id="payments-sdk__contingency-lightbox"></div>',
|
>
|
||||||
esc_attr($id),
|
</div>',
|
||||||
esc_html__('Card number', 'woocommerce-paypal-commerce-gateway'),
|
esc_attr($id),
|
||||||
esc_html__('Expiration Date', 'woocommerce-paypal-commerce-gateway'),
|
esc_html__('Save your card', 'woocommerce-paypal-commerce-gateway')
|
||||||
esc_html__('CVV', 'woocommerce-paypal-commerce-gateway'),
|
) : '';
|
||||||
$saveCard,
|
|
||||||
esc_html__('Pay with Card', 'woocommerce-paypal-commerce-gateway')
|
printf(
|
||||||
);
|
'<form id="%1$s">
|
||||||
};
|
<div class="ppcp-dcc-credit-card-wrapper">
|
||||||
|
<div>
|
||||||
|
<label for="ppcp-credit-card-%1$s">%2$s</label>
|
||||||
|
<span id="ppcp-credit-card-%1$s" class="ppcp-credit-card"></span>
|
||||||
|
</div><div>
|
||||||
|
<label for="ppcp-expiration-date-%1$s">%3$s</label>
|
||||||
|
<span id="ppcp-expiration-date-%1$s" class="ppcp-expiration-date"></span>
|
||||||
|
</div><div>
|
||||||
|
<label for="ppcp-cvv-%1$s">%4$s</label>
|
||||||
|
<span id="ppcp-cvv-%1$s" class="ppcp-cvv"></span>
|
||||||
|
</div>
|
||||||
|
%5$s
|
||||||
|
</div>
|
||||||
|
<button>%6$s</button>
|
||||||
|
</form><div id="payments-sdk__contingency-lightbox"></div>',
|
||||||
|
esc_attr($id),
|
||||||
|
esc_html__('Card number', 'woocommerce-paypal-commerce-gateway'),
|
||||||
|
esc_html__('Expiration Date', 'woocommerce-paypal-commerce-gateway'),
|
||||||
|
esc_html__('CVV', 'woocommerce-paypal-commerce-gateway'),
|
||||||
|
//phpcs:ignore
|
||||||
|
$saveCard,
|
||||||
|
esc_html__('Pay with Card', 'woocommerce-paypal-commerce-gateway')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
// phpcs:enable Inpsyde.CodeQuality.FunctionLength.TooLong
|
||||||
|
|
||||||
|
private function saveVaultToken(): bool
|
||||||
|
{
|
||||||
|
|
||||||
private function saveVaultToken() : bool {
|
|
||||||
if (! $this->settings->has('client_id') || ! $this->settings->get('client_id')) {
|
if (! $this->settings->has('client_id') || ! $this->settings->get('client_id')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -274,7 +283,9 @@ class SmartButton implements SmartButtonInterface
|
||||||
return is_user_logged_in();
|
return is_user_logged_in();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function hasSubscription() : bool {
|
private function hasSubscription(): bool
|
||||||
|
{
|
||||||
|
|
||||||
if (is_product()) {
|
if (is_product()) {
|
||||||
$product = wc_get_product();
|
$product = wc_get_product();
|
||||||
return is_a($product, \WC_Product::class) && $product->is_type('subscription');
|
return is_a($product, \WC_Product::class) && $product->is_type('subscription');
|
||||||
|
@ -297,6 +308,7 @@ class SmartButton implements SmartButtonInterface
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong
|
||||||
private function localizeScript(): array
|
private function localizeScript(): array
|
||||||
{
|
{
|
||||||
$this->requestData->enqueueNonceFix();
|
$this->requestData->enqueueNonceFix();
|
||||||
|
@ -353,6 +365,7 @@ class SmartButton implements SmartButtonInterface
|
||||||
$this->requestData->dequeueNonceFix();
|
$this->requestData->dequeueNonceFix();
|
||||||
return $localize;
|
return $localize;
|
||||||
}
|
}
|
||||||
|
//phpcs:enable Inpsyde.CodeQuality.FunctionLength.TooLong
|
||||||
|
|
||||||
private function payerData(): ?array
|
private function payerData(): ?array
|
||||||
{
|
{
|
||||||
|
@ -399,7 +412,10 @@ class SmartButton implements SmartButtonInterface
|
||||||
'data-partner-attribution-id' => $this->bnCodeForContext($this->context()),
|
'data-partner-attribution-id' => $this->bnCodeForContext($this->context()),
|
||||||
];
|
];
|
||||||
try {
|
try {
|
||||||
if (! $this->saveVaultToken()) {
|
if (!is_user_logged_in()) {
|
||||||
|
return $attributes;
|
||||||
|
}
|
||||||
|
if (! $this->dccIsEnabled() && ! $this->saveVaultToken()) {
|
||||||
return $attributes;
|
return $attributes;
|
||||||
}
|
}
|
||||||
$clientToken = $this->identityToken->generateForCustomer((int) get_current_user_id());
|
$clientToken = $this->identityToken->generateForCustomer((int) get_current_user_id());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue