mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
call partners endpoint when rendering the dcc settings to check whether the pp account is able to process dcc.
In order to do so, it was also necessary to store the merchant id during onboarding. includes a bugfix where the cache invalidation did not work because the cache object was constructed with the wrong prefix key.
This commit is contained in:
parent
22c7e3975f
commit
c09e314baa
14 changed files with 638 additions and 29 deletions
|
@ -9,13 +9,13 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\ApiClient;
|
||||
|
||||
use Dhii\Data\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\IdentityToken;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\LoginSeller;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnerReferrals;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentTokenEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\WebhookEndpoint;
|
||||
|
@ -32,6 +32,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentsFactory;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentSourceFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentTokenFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\SellerStatusFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookFactory;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
|
@ -85,6 +86,19 @@ return array(
|
|||
$logger
|
||||
);
|
||||
},
|
||||
'api.endpoint.partners' => static function ( $container ) : PartnersEndpoint {
|
||||
return new PartnersEndpoint(
|
||||
$container->get( 'api.host' ),
|
||||
$container->get( 'api.bearer' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
$container->get( 'api.factory.sellerstatus' ),
|
||||
$container->get( 'api.partner_merchant_id' ),
|
||||
$container->get( 'api.merchant_id' )
|
||||
);
|
||||
},
|
||||
'api.factory.sellerstatus' => static function ( $container ) : SellerStatusFactory {
|
||||
return new SellerStatusFactory();
|
||||
},
|
||||
'api.endpoint.payment-token' => static function ( $container ) : PaymentTokenEndpoint {
|
||||
return new PaymentTokenEndpoint(
|
||||
$container->get( 'api.host' ),
|
||||
|
|
149
modules/ppcp-api-client/src/Endpoint/class-partnersendpoint.php
Normal file
149
modules/ppcp-api-client/src/Endpoint/class-partnersendpoint.php
Normal file
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
/**
|
||||
* The Partners Endpoint.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\ApiClient\Endpoint
|
||||
*/
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\SellerStatusFactory;
|
||||
|
||||
/**
|
||||
* Class PartnersEndpoint
|
||||
*/
|
||||
class PartnersEndpoint {
|
||||
|
||||
use RequestTrait;
|
||||
|
||||
/**
|
||||
* The Host URL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $host;
|
||||
|
||||
/**
|
||||
* The bearer.
|
||||
*
|
||||
* @var Bearer
|
||||
*/
|
||||
private $bearer;
|
||||
|
||||
/**
|
||||
* The logger.
|
||||
*
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* The seller status factory.
|
||||
*
|
||||
* @var SellerStatusFactory
|
||||
*/
|
||||
private $seller_status_factory;
|
||||
|
||||
/**
|
||||
* The partner ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $partner_id;
|
||||
|
||||
/**
|
||||
* The merchant ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $merchant_id;
|
||||
|
||||
/**
|
||||
* PartnersEndpoint constructor.
|
||||
*
|
||||
* @param string $host The host.
|
||||
* @param Bearer $bearer The bearer.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @param SellerStatusFactory $seller_status_factory The seller status factory.
|
||||
* @param string $partner_id The partner ID.
|
||||
* @param string $merchant_id The merchant ID.
|
||||
*/
|
||||
public function __construct(
|
||||
string $host,
|
||||
Bearer $bearer,
|
||||
LoggerInterface $logger,
|
||||
SellerStatusFactory $seller_status_factory,
|
||||
string $partner_id,
|
||||
string $merchant_id
|
||||
) {
|
||||
$this->host = $host;
|
||||
$this->bearer = $bearer;
|
||||
$this->logger = $logger;
|
||||
$this->seller_status_factory = $seller_status_factory;
|
||||
$this->partner_id = $partner_id;
|
||||
$this->merchant_id = $merchant_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current seller status.
|
||||
*
|
||||
* @return SellerStatus
|
||||
* @throws RuntimeException When request could not be fullfilled.
|
||||
*/
|
||||
public function seller_status() : SellerStatus {
|
||||
$url = trailingslashit( $this->host ) . 'v1/customer/partners/' . $this->partner_id . '/merchant-integrations/' . $this->merchant_id;
|
||||
$bearer = $this->bearer->bearer();
|
||||
$args = array(
|
||||
'method' => 'GET',
|
||||
'headers' => array(
|
||||
'Authorization' => 'Bearer ' . $bearer->token(),
|
||||
'Content-Type' => 'application/json',
|
||||
),
|
||||
);
|
||||
$response = $this->request( $url, $args );
|
||||
if ( is_wp_error( $response ) ) {
|
||||
|
||||
$error = new RuntimeException(
|
||||
__(
|
||||
'Could not fetch sellers status.',
|
||||
'paypal-payments-for-woocommerce'
|
||||
)
|
||||
);
|
||||
|
||||
$this->logger->log(
|
||||
'warning',
|
||||
$error->getMessage(),
|
||||
array(
|
||||
'args' => $args,
|
||||
'response' => $response,
|
||||
)
|
||||
);
|
||||
throw $error;
|
||||
}
|
||||
|
||||
$json = json_decode( wp_remote_retrieve_body( $response ) );
|
||||
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
||||
if ( 200 !== $status_code ) {
|
||||
$error = new PayPalApiException( $json, $status_code );
|
||||
$this->logger->log(
|
||||
'warning',
|
||||
$error->getMessage(),
|
||||
array(
|
||||
'args' => $args,
|
||||
'response' => $response,
|
||||
)
|
||||
);
|
||||
throw $error;
|
||||
}
|
||||
|
||||
$status = $this->seller_status_factory->from_paypal_reponse( $json );
|
||||
return $status;
|
||||
}
|
||||
}
|
65
modules/ppcp-api-client/src/Entity/class-sellerstatus.php
Normal file
65
modules/ppcp-api-client/src/Entity/class-sellerstatus.php
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/**
|
||||
* The seller status entity.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
||||
*/
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
||||
|
||||
/**
|
||||
* Class SellerStatus
|
||||
*/
|
||||
class SellerStatus {
|
||||
|
||||
/**
|
||||
* The products.
|
||||
*
|
||||
* @var SellerStatusProduct[]
|
||||
*/
|
||||
private $products;
|
||||
|
||||
/**
|
||||
* SellerStatus constructor.
|
||||
*
|
||||
* @param SellerStatusProduct[] $products The products.
|
||||
*/
|
||||
public function __construct( array $products ) {
|
||||
foreach ( $products as $key => $product ) {
|
||||
if ( is_a( $product, SellerStatusProduct::class ) ) {
|
||||
continue;
|
||||
}
|
||||
unset( $products[ $key ] );
|
||||
}
|
||||
$this->products = $products;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the products.
|
||||
*
|
||||
* @return SellerStatusProduct[]
|
||||
*/
|
||||
public function products() : array {
|
||||
return $this->products;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enitity as array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function to_array() : array {
|
||||
$products = array_map(
|
||||
function( SellerStatusProduct $product ) : array {
|
||||
return $product->to_array();
|
||||
},
|
||||
$this->products()
|
||||
);
|
||||
|
||||
return array(
|
||||
'products' => $products,
|
||||
);
|
||||
}
|
||||
}
|
108
modules/ppcp-api-client/src/Entity/class-sellerstatusproduct.php
Normal file
108
modules/ppcp-api-client/src/Entity/class-sellerstatusproduct.php
Normal file
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
/**
|
||||
* The products of a seller status.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
||||
*/
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
||||
|
||||
/**
|
||||
* Class SellerStatusProduct
|
||||
*/
|
||||
class SellerStatusProduct {
|
||||
|
||||
const VETTING_STATUS_APPROVED = 'APPROVED';
|
||||
const VETTING_STATUS_PENDING = 'PENDING';
|
||||
const VETTING_STATUS_DECLINED = 'DECLINED';
|
||||
const VETTING_STATUS_SUBSCRIBED = 'SUBSCRIBED';
|
||||
const VETTING_STATUS_IN_REVIEW = 'IN_REVIEW';
|
||||
const VETTING_STATUS_DENIED = 'DENIED';
|
||||
/**
|
||||
* The name of the product.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* The vetting status of the product.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $vetting_status;
|
||||
|
||||
/**
|
||||
* The capabilities of the product.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $capabilities;
|
||||
|
||||
/**
|
||||
* SellerStatusProduct constructor.
|
||||
*
|
||||
* @param string $name The name of the product.
|
||||
* @param string $vetting_status The vetting status of the product.
|
||||
* @param string[] $capabilities The capabilities of the product.
|
||||
*/
|
||||
public function __construct(
|
||||
string $name,
|
||||
string $vetting_status,
|
||||
array $capabilities
|
||||
) {
|
||||
foreach ( $capabilities as $key => $capability ) {
|
||||
if ( is_string( $capability ) ) {
|
||||
continue;
|
||||
}
|
||||
unset( $capabilities[ $key ] );
|
||||
}
|
||||
$this->name = $name;
|
||||
$this->vetting_status = $vetting_status;
|
||||
$this->capabilities = $capabilities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the product.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function name() : string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the vetting status for this product.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function vetting_status() : string {
|
||||
return $this->vetting_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the capabilities of this product.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function capabilities() : array {
|
||||
return $this->capabilities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity as array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function to_array() : array {
|
||||
return array(
|
||||
'name' => $this->name(),
|
||||
'vetting_status' => $this->vetting_status(),
|
||||
'capabilities' => $this->capabilities(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Factory for the SellerStatus object.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\ApiClient\Factory
|
||||
*/
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusProduct;
|
||||
|
||||
/**
|
||||
* Class SellerStatusFactory
|
||||
*/
|
||||
class SellerStatusFactory {
|
||||
|
||||
/**
|
||||
* Creates a SellerStatus Object out of a PayPal response.
|
||||
*
|
||||
* @param \stdClass $json The response object.
|
||||
*
|
||||
* @return SellerStatus
|
||||
*/
|
||||
public function from_paypal_reponse( \stdClass $json ) : SellerStatus {
|
||||
$products = array_map(
|
||||
function( $json ) : SellerStatusProduct {
|
||||
$product = new SellerStatusProduct(
|
||||
isset( $json->name ) ? (string) $json->name : '',
|
||||
isset( $json->vetting_status ) ? (string) $json->vetting_status : '',
|
||||
isset( $json->capabilities ) ? (array) $json->capabilities : array()
|
||||
);
|
||||
return $product;
|
||||
},
|
||||
isset( $json->products ) ? (array) $json->products : array()
|
||||
);
|
||||
|
||||
return new SellerStatus( $products );
|
||||
}
|
||||
}
|
|
@ -49,7 +49,8 @@ class Cache {
|
|||
* @return bool
|
||||
*/
|
||||
public function has( string $key ): bool {
|
||||
return $this->get( $key ) !== false;
|
||||
$value = $this->get( $key );
|
||||
return false !== $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
}
|
||||
|
||||
#field-client_secret,
|
||||
#field-client_id {
|
||||
#field-client_id,
|
||||
#field-merchant_id {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ const groupToggleSelect = (selector, group) => {
|
|||
(event) => {
|
||||
event.preventDefault();
|
||||
document.querySelector('#field-toggle_manual_input').style.display = 'none';
|
||||
document.querySelector('#field-merchant_id').style.display = 'table-row';
|
||||
document.querySelector('#field-client_id').style.display = 'table-row';
|
||||
document.querySelector('#field-client_secret').style.display = 'table-row';
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ return array(
|
|||
$partner_referrals_data = $container->get( 'api.repository.partner-referrals-data' );
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
|
||||
$cache = new Cache( 'ppcp-token' );
|
||||
$cache = new Cache( 'ppcp-paypal-bearer' );
|
||||
return new LoginSellerEndpoint(
|
||||
$request_data,
|
||||
$login_seller,
|
||||
|
|
|
@ -20,6 +20,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Checkout\DisableGateways;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use Woocommerce\PayPalCommerce\WcGateway\Helper\DccProductStatus;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
||||
|
@ -92,12 +93,14 @@ return array(
|
|||
$fields = $container->get( 'wcgateway.settings.fields' );
|
||||
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
|
||||
$messages_apply = $container->get( 'button.helper.messages-apply' );
|
||||
$dcc_product_status = $container->get( 'wcgateway.helper.dcc-product-status' );
|
||||
return new SettingsRenderer(
|
||||
$settings,
|
||||
$state,
|
||||
$fields,
|
||||
$dcc_applies,
|
||||
$messages_apply
|
||||
$messages_apply,
|
||||
$dcc_product_status
|
||||
);
|
||||
},
|
||||
'wcgateway.settings.listener' => static function ( $container ): SettingsListener {
|
||||
|
@ -105,7 +108,7 @@ return array(
|
|||
$fields = $container->get( 'wcgateway.settings.fields' );
|
||||
$webhook_registrar = $container->get( 'webhook.registrar' );
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
$cache = new Cache( 'ppcp-token' );
|
||||
$cache = new Cache( 'ppcp-paypal-bearer' );
|
||||
return new SettingsListener( $settings, $fields, $webhook_registrar, $cache, $state );
|
||||
},
|
||||
'wcgateway.order-processor' => static function ( $container ): OrderProcessor {
|
||||
|
@ -242,6 +245,20 @@ return array(
|
|||
'requirements' => array(),
|
||||
'gateway' => 'paypal',
|
||||
),
|
||||
'merchant_id' => array(
|
||||
'title' => __( 'Merchant Id', 'paypal-payments-for-woocommerce' ),
|
||||
'type' => 'ppcp-text-input',
|
||||
'desc_tip' => true,
|
||||
'description' => __( 'The merchant id of your account ', 'paypal-payments-for-woocommerce' ),
|
||||
'default' => false,
|
||||
'screens' => array(
|
||||
State::STATE_START,
|
||||
State::STATE_PROGRESSIVE,
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array(),
|
||||
'gateway' => 'paypal',
|
||||
),
|
||||
'client_id' => array(
|
||||
'title' => __( 'Client Id', 'paypal-payments-for-woocommerce' ),
|
||||
'type' => 'ppcp-text-input',
|
||||
|
@ -1589,4 +1606,10 @@ return array(
|
|||
$prefix
|
||||
);
|
||||
},
|
||||
'wcgateway.helper.dcc-product-status' => static function ( $container ) : DccProductStatus {
|
||||
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$partner_endpoint = $container->get( 'api.endpoint.partners' );
|
||||
return new DccProductStatus( $settings, $partner_endpoint );
|
||||
},
|
||||
);
|
||||
|
|
102
modules/ppcp-wc-gateway/src/Helper/class-dccproductstatus.php
Normal file
102
modules/ppcp-wc-gateway/src/Helper/class-dccproductstatus.php
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
/**
|
||||
* Manage the Seller status.
|
||||
*
|
||||
* @package Woocommerce\PayPalCommerce\WcGateway\Helper
|
||||
*/
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Woocommerce\PayPalCommerce\WcGateway\Helper;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusProduct;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
* Class DccProductStatus
|
||||
*/
|
||||
class DccProductStatus {
|
||||
|
||||
/**
|
||||
* Caches the status for the current load.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $current_status_cache;
|
||||
/**
|
||||
* The settings.
|
||||
*
|
||||
* @var Settings
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* The partners endpoint.
|
||||
*
|
||||
* @var PartnersEndpoint
|
||||
*/
|
||||
private $partners_endpoint;
|
||||
|
||||
/**
|
||||
* DccProductStatus constructor.
|
||||
*
|
||||
* @param Settings $settings The Settings.
|
||||
* @param PartnersEndpoint $partners_endpoint The Partner Endpoint.
|
||||
*/
|
||||
public function __construct(
|
||||
Settings $settings,
|
||||
PartnersEndpoint $partners_endpoint
|
||||
) {
|
||||
$this->settings = $settings;
|
||||
$this->partners_endpoint = $partners_endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the active/subscribed products support DCC.
|
||||
*
|
||||
* @return bool
|
||||
* @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException Should a setting not be found.
|
||||
*/
|
||||
public function dcc_is_active() : bool {
|
||||
if ( is_bool( $this->current_status_cache ) ) {
|
||||
return $this->current_status_cache;
|
||||
}
|
||||
if ( $this->settings->has( 'products_dcc_enabled' ) && $this->settings->get( 'products_dcc_enabled' ) ) {
|
||||
$this->current_status_cache = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
$seller_status = $this->partners_endpoint->seller_status();
|
||||
} catch ( RuntimeException $error ) {
|
||||
$this->current_status_cache = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ( $seller_status->products() as $product ) {
|
||||
if ( ! in_array(
|
||||
$product->vetting_status(),
|
||||
array(
|
||||
SellerStatusProduct::VETTING_STATUS_APPROVED,
|
||||
SellerStatusProduct::VETTING_STATUS_SUBSCRIBED,
|
||||
),
|
||||
true
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( in_array( 'CUSTOM_CARD_PROCESSING', $product->capabilities(), true ) ) {
|
||||
$this->settings->set( 'products_dcc_enabled', true );
|
||||
$this->settings->persist();
|
||||
$this->current_status_cache = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->current_status_cache = false;
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -83,6 +83,29 @@ class SettingsListener {
|
|||
$this->state = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens if the merchant ID should be updated.
|
||||
*/
|
||||
public function listen_for_merchant_id() {
|
||||
|
||||
if ( ! $this->is_valid_site_request() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* No nonce provided.
|
||||
* phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
* phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
*/
|
||||
if ( isset( $_GET['merchantIdInPayPal'] ) ) {
|
||||
$this->settings->set( 'merchant_id', sanitize_text_field( wp_unslash( $_GET['merchantIdInPayPal'] ) ) );
|
||||
$this->settings->persist();
|
||||
}
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens to the request.
|
||||
*
|
||||
|
@ -246,18 +269,7 @@ class SettingsListener {
|
|||
*/
|
||||
private function is_valid_update_request(): bool {
|
||||
|
||||
if (
|
||||
! isset( $_REQUEST['section'] )
|
||||
|| ! in_array(
|
||||
sanitize_text_field( wp_unslash( $_REQUEST['section'] ) ),
|
||||
array( 'ppcp-gateway', 'ppcp-credit-card-gateway' ),
|
||||
true
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
if ( ! $this->is_valid_site_request() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -272,4 +284,37 @@ class SettingsListener {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether we are on the settings page and are allowed to be here.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_valid_site_request() : bool {
|
||||
|
||||
/**
|
||||
* No nonce needed at this point.
|
||||
*
|
||||
* phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
* phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
*/
|
||||
if (
|
||||
! isset( $_REQUEST['section'] )
|
||||
|| ! in_array(
|
||||
sanitize_text_field( wp_unslash( $_REQUEST['section'] ) ),
|
||||
array( 'ppcp-gateway', 'ppcp-credit-card-gateway' ),
|
||||
true
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
|||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Woocommerce\PayPalCommerce\WcGateway\Helper\DccProductStatus;
|
||||
|
||||
/**
|
||||
* Class SettingsRenderer
|
||||
|
@ -55,28 +56,38 @@ class SettingsRenderer {
|
|||
*/
|
||||
private $messages_apply;
|
||||
|
||||
/**
|
||||
* The DCC Product Status.
|
||||
*
|
||||
* @var DccProductStatus
|
||||
*/
|
||||
private $dcc_product_status;
|
||||
|
||||
/**
|
||||
* SettingsRenderer constructor.
|
||||
*
|
||||
* @param ContainerInterface $settings The Settings.
|
||||
* @param State $state The current state.
|
||||
* @param array $fields The setting fields.
|
||||
* @param DccApplies $dcc_applies Whether DCC gateway can be shown.
|
||||
* @param State $state The current state.
|
||||
* @param array $fields The setting fields.
|
||||
* @param DccApplies $dcc_applies Whether DCC gateway can be shown.
|
||||
* @param MessagesApply $messages_apply Whether messages can be shown.
|
||||
* @param DccProductStatus $dcc_product_status The product status.
|
||||
*/
|
||||
public function __construct(
|
||||
ContainerInterface $settings,
|
||||
State $state,
|
||||
array $fields,
|
||||
DccApplies $dcc_applies,
|
||||
MessagesApply $messages_apply
|
||||
MessagesApply $messages_apply,
|
||||
DccProductStatus $dcc_product_status
|
||||
) {
|
||||
|
||||
$this->settings = $settings;
|
||||
$this->state = $state;
|
||||
$this->fields = $fields;
|
||||
$this->dcc_applies = $dcc_applies;
|
||||
$this->messages_apply = $messages_apply;
|
||||
$this->settings = $settings;
|
||||
$this->state = $state;
|
||||
$this->fields = $fields;
|
||||
$this->dcc_applies = $dcc_applies;
|
||||
$this->messages_apply = $messages_apply;
|
||||
$this->dcc_product_status = $dcc_product_status;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -235,6 +246,12 @@ class SettingsRenderer {
|
|||
) {
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
in_array( 'dcc', $config['requirements'], true )
|
||||
&& ! $this->dcc_product_status->dcc_is_active()
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
in_array( 'messages', $config['requirements'], true )
|
||||
&& ! $this->messages_apply->for_country()
|
||||
|
@ -281,9 +298,10 @@ class SettingsRenderer {
|
|||
if ( $this->dcc_applies->for_country_currency() ) {
|
||||
if ( State::STATE_ONBOARDED > $this->state->current_state() ) {
|
||||
$this->render_dcc_onboarding_info();
|
||||
}
|
||||
if ( State::STATE_ONBOARDED === $this->state->current_state() ) {
|
||||
} elseif ( State::STATE_ONBOARDED === $this->state->current_state() && $this->dcc_product_status->dcc_is_active() ) {
|
||||
$this->render_3d_secure_info();
|
||||
} elseif ( ! $this->dcc_product_status->dcc_is_active() ) {
|
||||
$this->render_dcc_not_active_yet();
|
||||
}
|
||||
} else {
|
||||
$this->render_dcc_does_not_apply_info();
|
||||
|
@ -310,6 +328,27 @@ class SettingsRenderer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the information that the PayPal account can not yet process DCC.
|
||||
*/
|
||||
private function render_dcc_not_active_yet() {
|
||||
?>
|
||||
<tr>
|
||||
<th><?php esc_html_e( 'Onboarding', 'paypal-payments-for-woocommerce' ); ?></th>
|
||||
<td class="notice notice-error">
|
||||
<p>
|
||||
<?php
|
||||
esc_html_e(
|
||||
'Credit Card processing for your account has not yet been activated by PayPal. If your account is new, this can take some days. Otherwise, please get in contact with PayPal.',
|
||||
'paypal-payments-for-woocommerce'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the 3d secure info text.
|
||||
*/
|
||||
|
|
|
@ -24,6 +24,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\SectionsRenderer;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
|
||||
use Interop\Container\ServiceProviderInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
@ -193,9 +194,27 @@ class WcGatewayModule implements ModuleInterface {
|
|||
'woocommerce_settings_save_checkout',
|
||||
static function () use ( $container ) {
|
||||
$listener = $container->get( 'wcgateway.settings.listener' );
|
||||
|
||||
/**
|
||||
* The settings listener.
|
||||
*
|
||||
* @var SettingsListener $listener
|
||||
*/
|
||||
$listener->listen();
|
||||
}
|
||||
);
|
||||
add_action(
|
||||
'admin_init',
|
||||
static function () use ( $container ) {
|
||||
$listener = $container->get( 'wcgateway.settings.listener' );
|
||||
/**
|
||||
* The settings listener.
|
||||
*
|
||||
* @var SettingsListener $listener
|
||||
*/
|
||||
$listener->listen_for_merchant_id();
|
||||
}
|
||||
);
|
||||
|
||||
add_filter(
|
||||
'woocommerce_form_field',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue