load identity token also if dcc is enabled, phpcs

This commit is contained in:
David Remer 2020-07-23 14:28:16 +03:00
parent 158db47134
commit bb4fbd2dbd

View file

@ -206,13 +206,18 @@ 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'; $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'); $canRenderDcc = $this->dccApplies->forCountryCurrency()
&& $this->settings->has('client_id')
&& $this->settings->get('client_id');
if (! $canRenderDcc) { if (! $canRenderDcc) {
return; return;
} }
$product = wc_get_product(); $product = wc_get_product();
if ( if (
! $miniCart && !is_checkout() && is_a($product, \WC_Product::class) ! $miniCart && !is_checkout() && is_a($product, \WC_Product::class)
@ -234,9 +239,10 @@ class SmartButton implements SmartButtonInterface
name="vault" name="vault"
> >
</div>', </div>',
$id, esc_attr($id),
esc_html__('Save your card', 'woocommerce-paypal-commerce-gateway') esc_html__('Save your card', 'woocommerce-paypal-commerce-gateway')
) : ''; ) : '';
printf( printf(
'<form id="%1$s"> '<form id="%1$s">
<div class="ppcp-dcc-credit-card-wrapper"> <div class="ppcp-dcc-credit-card-wrapper">
@ -258,13 +264,16 @@ class SmartButton implements SmartButtonInterface
esc_html__('Card number', 'woocommerce-paypal-commerce-gateway'), esc_html__('Card number', 'woocommerce-paypal-commerce-gateway'),
esc_html__('Expiration Date', 'woocommerce-paypal-commerce-gateway'), esc_html__('Expiration Date', 'woocommerce-paypal-commerce-gateway'),
esc_html__('CVV', 'woocommerce-paypal-commerce-gateway'), esc_html__('CVV', 'woocommerce-paypal-commerce-gateway'),
//phpcs:ignore
$saveCard, $saveCard,
esc_html__('Pay with Card', 'woocommerce-paypal-commerce-gateway') 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());