PHP code example of tmonier / sylius-order-hold-plugin
1. Go to this page and download the library: Download tmonier/sylius-order-hold-plugin 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/ */
tmonier / sylius-order-hold-plugin example snippets
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Payment\Model\PaymentInterface;
use Sylius\Component\Payment\Model\PaymentMethodInterface;
use Tmonier\SyliusOrderHoldPlugin\PaymentEntry\PaymentEntryBlock;
use Tmonier\SyliusOrderHoldPlugin\PaymentEntry\PaymentEntryBlockerInterface;
use Tmonier\SyliusOrderHoldPlugin\PaymentMethod\IneligibilityReason;
use Tmonier\SyliusOrderHoldPlugin\PaymentMethod\PaymentMethodEligibilityCheckerInterface;
use Tmonier\SyliusOrderHoldPlugin\PaymentMethod\PaymentMethodIneligibility;
use Tmonier\SyliusOrderHoldPlugin\UnpaidOrder\UnpaidOrderCancellationExclusionInterface;
use Tmonier\SyliusOrderHoldPlugin\UnpaidOrder\UnpaidOrderHold;
final class ApprovalHold implements UnpaidOrderCancellationExclusionInterface, PaymentEntryBlockerInterface, PaymentMethodEligibilityCheckerInterface
{
public function getHold(OrderInterface $order): ?UnpaidOrderHold
{
$approval = $this->approvals->findForOrder($order);
return match (true) {
null === $approval => null,
$approval->isPending() => UnpaidOrderHold::indefinitely('approval'),
default => UnpaidOrderHold::since($approval->getApprovedAt(), 'approval'),
};
}
public function getBlock(OrderInterface $order): ?PaymentEntryBlock
{
return $this->approvals->isPending($order) ? new PaymentEntryBlock('app.order.awaiting_approval') : null;
}
public function getIneligibility(PaymentMethodInterface $paymentMethod, PaymentInterface $payment): ?PaymentMethodIneligibility
{
return $this->isOnAccount($paymentMethod) && !$this->canBuyOnAccount($payment)
? new PaymentMethodIneligibility(IneligibilityReason::CreditLimitExceeded, null, ['%available%' => '120.00 EUR'])
: null;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.