PHP code example of smaex / additional-payment-checks
1. Go to this page and download the library: Download smaex/additional-payment-checks library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
smaex / additional-payment-checks example snippets
/**
* Combines several checks with logic "AND" operation.
*
* Use this class to register own specifications.
*/
class Composite implements SpecificationInterface
{
/**
* Check whether payment method is applicable to quote
*/
public function isApplicable(MethodInterface $paymentMethod, Quote $quote): bool
{
foreach ($this->list as $specification) {
if (!$specification->isApplicable($paymentMethod, $quote)) {
return false;
}
}
return true;
}
}
/**
* Creates complex specification.
*
* Use this class to register predefined list of specifications
* that should be added to any complex specification.
*/
class SpecificationFactory
{
/**
* Creates new instances of payment method models
*/
public function create(array $data): Composite
{
$specifications = array_intersect_key($this->mapping, array_flip((array)$data));
return $this->compositeFactory->create(['list' => $specifications]);
}
}
/**
* Methods List service class.
*/
class MethodList
{
/**
* Check payment method model
*/
protected function _canUseMethod(MethodInterface $method, CartInterface $quote): bool
{
return $this->methodSpecificationFactory->create(
[
AbstractMethod::CHECK_USE_CHECKOUT,
AbstractMethod::CHECK_USE_FOR_COUNTRY,
AbstractMethod::CHECK_USE_FOR_CURRENCY,
AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX,
]
)->isApplicable($method, $quote);
}
}