PaymentLink.php 2.85 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
<?php
/**
 *                       ######
 *                       ######
 * ############    ####( ######  #####. ######  ############   ############
 * #############  #####( ######  #####. ######  #############  #############
 *        ######  #####( ######  #####. ######  #####  ######  #####  ######
 * ###### ######  #####( ######  #####. ######  #####  #####   #####  ######
 * ###### ######  #####( ######  #####. ######  #####          #####  ######
 * #############  #############  #############  #############  #####  ######
 *  ############   ############  #############   ############  #####  ######
 *                                      ######
 *                               #############
 *                               ############
 *
 * Adyen Payment module (https://www.adyen.com/)
 *
 * Copyright (c) 2018 Adyen BV (https://www.adyen.com/)
 * See LICENSE.txt for license details.
 *
 * Author: Adyen <magento@adyen.com>
 */

namespace Adyen\Payment\Block\Info;

use Magento\Framework\View\Element\Template;

class PaymentLink extends AbstractInfo
{
    /**
     * @var \Magento\Framework\Registry
     */
    private $registry;

    /**
     * @var \Adyen\Payment\Gateway\Command\PayByMailCommand
     */
    private $payByMail;

    public function __construct(
        \Adyen\Payment\Helper\Data $adyenHelper,
        \Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory,
        Template\Context $context,
        \Magento\Framework\Registry $registry,
Imran Shakil's avatar
Imran Shakil committed
45 46
        \Adyen\Payment\Gateway\Command\PayByMailCommand $payByMailCommand,
        array $data = []
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    ) {
        $this->registry = $registry;
        $this->payByMail = $payByMailCommand;

        parent::__construct($adyenHelper, $adyenOrderPaymentCollectionFactory, $context, $data);
    }

    /**
     * @return \Magento\Sales\Model\Order
     */
    public function getOrder()
    {
        return $this->registry->registry('current_order');
    }

    /**
     * @return \Magento\Sales\Model\Order\Payment
     */
    public function getPayment()
    {
        $order = $this->getOrder();

        return $order->getPayment();
    }

    /**
     * @return string
     */
    public function getPaymentLinkUrl()
    {
        return $this->payByMail->generatePaymentUrl($this->getPayment(), $this->getOrder()->getTotalDue());
    }

    /**
     * Check if order was placed using Adyen payment method
     * and if total due is greater than zero while one or more payments have been made
     *
     * @return string
     */
    public function _toHtml()
    {
        return strpos($this->getPayment()->getMethod(), 'adyen_') === 0
89 90 91 92 93
        && $this->_scopeConfig->getValue('payment/adyen_hpp/active')
        && $this->_scopeConfig->getValue('payment/adyen_pay_by_mail/active')
        && $this->getOrder()->getTotalDue() > 0
            ? parent::_toHtml()
            : '';
94 95
    }
}