mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Add module boilerplate
This commit is contained in:
parent
ac7779bc41
commit
1125ca6ad5
14 changed files with 2565 additions and 0 deletions
45
modules/ppcp-card-fields/src/CardFieldsModule.php
Normal file
45
modules/ppcp-card-fields/src/CardFieldsModule.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
/**
|
||||
* The Card Fields module.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\CardFields
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\CardFields;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
class CardFieldsModule implements ModuleInterface {
|
||||
|
||||
public function setup(): ServiceProviderInterface {
|
||||
return new ServiceProvider(
|
||||
require __DIR__ . '/../services.php',
|
||||
require __DIR__ . '/../extensions.php'
|
||||
);
|
||||
}
|
||||
|
||||
public function run(ContainerInterface $c): void {
|
||||
if ( ! $c->get( 'card-fields.eligible' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action(
|
||||
'wp_enqueue_scripts',
|
||||
function () use ($c) {
|
||||
$module_url = $c->get( 'card-fields.module.url' );
|
||||
wp_enqueue_script(
|
||||
'ppcp-card-fields-boot',
|
||||
untrailingslashit( $module_url ) . '/assets/js/boot.js',
|
||||
array( 'jquery' ),
|
||||
$c->get( 'ppcp.asset-version' ),
|
||||
true
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
66
modules/ppcp-card-fields/src/Helper/CardFieldsApplies.php
Normal file
66
modules/ppcp-card-fields/src/Helper/CardFieldsApplies.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
* Service for checking whether Card Fields can be used in the current country and the current currency.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\CardFields\Helper
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\CardFields\Helper;
|
||||
|
||||
/**
|
||||
* Class CardFieldsApplies
|
||||
*/
|
||||
class CardFieldsApplies {
|
||||
|
||||
/**
|
||||
* The matrix which countries and currency combinations can be used.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $allowed_country_currency_matrix;
|
||||
|
||||
/**
|
||||
* 3-letter currency code of the shop.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $currency;
|
||||
|
||||
/**
|
||||
* 2-letter country code of the shop.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $country;
|
||||
|
||||
/**
|
||||
* CardFieldsApplies constructor.
|
||||
*
|
||||
* @param array $allowed_country_currency_matrix The matrix which countries and currency combinations can be used.
|
||||
* @param string $currency 3-letter currency code of the shop.
|
||||
* @param string $country 2-letter country code of the shop.
|
||||
*/
|
||||
public function __construct(
|
||||
array $allowed_country_currency_matrix,
|
||||
string $currency,
|
||||
string $country
|
||||
) {
|
||||
$this->allowed_country_currency_matrix = $allowed_country_currency_matrix;
|
||||
$this->currency = $currency;
|
||||
$this->country = $country;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether Card Fields can be used in the current country and the current currency.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function for_country_currency(): bool {
|
||||
if ( ! in_array( $this->country, array_keys( $this->allowed_country_currency_matrix ), true ) ) {
|
||||
return false;
|
||||
}
|
||||
return in_array( $this->currency, $this->allowed_country_currency_matrix[ $this->country ], true );
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue