/** * @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod * @throws \Magento\Framework\Exception\CouldNotSaveException * @return void */ protected function validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $paymentMethod) { $agreements = $paymentMethod->getExtensionAttributes() === null ? [] : $paymentMethod->getExtensionAttributes()->getAgreementIds(); if (!$this->agreementsValidator->isValid($agreements)) { throw new \Magento\Framework\Exception\CouldNotSaveException(__('Please agree to all the terms and conditions before placing the order.')); } }
/** * @param \Magento\Checkout\Api\PaymentInformationManagementInterface $subject * @param int $cartId * @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod * @param \Magento\Quote\Api\Data\AddressInterface $billingAddress * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeSavePaymentInformation(\Magento\Checkout\Api\PaymentInformationManagementInterface $subject, $cartId, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress) { if ($this->isAgreementEnabled()) { $this->validateAgreements($paymentMethod->getExtensionAttributes()->getAgreementIds()); } }