We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit ea071d3a authored by Rik ter Beek's avatar Rik ter Beek Committed by GitHub

Merge pull request #258 from ho-nl-fork/order-payment-url

Show payment link in admin for remaining order balance
parents 6ad4e588 514f7bda
<?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,
array $data = [],
\Magento\Framework\Registry $registry,
\Adyen\Payment\Gateway\Command\PayByMailCommand $payByMailCommand
) {
$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
&& $this->_scopeConfig->getValue('payment/adyen_hpp/active')
&& $this->_scopeConfig->getValue('payment/adyen_pay_by_mail/active')
&& $this->getOrder()->getTotalInvoiced() > 0
&& $this->getOrder()->getTotalDue() > 0
? parent::_toHtml()
: '';
}
}
...@@ -80,13 +80,14 @@ class PayByMailCommand implements CommandInterface ...@@ -80,13 +80,14 @@ class PayByMailCommand implements CommandInterface
} }
/** /**
* @param $payment * @param \Magento\Sales\Model\Order\Payment $payment
* @param float|bool $paymentAmount
* @return string * @return string
*/ */
public function generatePaymentUrl($payment) public function generatePaymentUrl($payment, $paymentAmount = false)
{ {
$url = $this->getFormUrl(); $url = $this->getFormUrl();
$fields = $this->getFormFields($payment); $fields = $this->getFormFields($payment, $paymentAmount);
$count = 1; $count = 1;
$size = count($fields); $size = count($fields);
...@@ -120,10 +121,11 @@ class PayByMailCommand implements CommandInterface ...@@ -120,10 +121,11 @@ class PayByMailCommand implements CommandInterface
/** /**
* @param $payment * @param \Magento\Sales\Model\Order\Payment $payment
* @param float|bool $paymentAmount
* @return array * @return array
*/ */
protected function getFormFields($payment) protected function getFormFields($payment, $paymentAmount = false)
{ {
$order = $payment->getOrder(); $order = $payment->getOrder();
...@@ -144,7 +146,7 @@ class PayByMailCommand implements CommandInterface ...@@ -144,7 +146,7 @@ class PayByMailCommand implements CommandInterface
$hmacKey = $this->_adyenHelper->getHmacPayByMail(); $hmacKey = $this->_adyenHelper->getHmacPayByMail();
} }
$amount = $this->_adyenHelper->formatAmount($order->getGrandTotal(), $orderCurrencyCode); $amount = $this->_adyenHelper->formatAmount($paymentAmount ?: $order->getGrandTotal(), $orderCurrencyCode);
$merchantAccount = trim($this->_adyenHelper->getAdyenAbstractConfigData('merchant_account', $storeId)); $merchantAccount = trim($this->_adyenHelper->getAdyenAbstractConfigData('merchant_account', $storeId));
$shopperEmail = $order->getCustomerEmail(); $shopperEmail = $order->getCustomerEmail();
$customerId = $order->getCustomerId(); $customerId = $order->getCustomerId();
......
<?xml version="1.0"?>
<!--
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* 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>
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="payment_additional_info">
<block class="Adyen\Payment\Block\Info\PaymentLink" name="adyen_paymentlink" template="Adyen_Payment::info/adyen_paymentlink.phtml" />
</referenceContainer>
</body>
</page>
<?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>
*/
/** @var \Adyen\Payment\Block\Info\PaymentLink $block */
?>
<br />
<div class="admin__page-section-item-title">
<span class="title"><?php echo __('Adyen Payment Link');?></span>
</div>
<p id="paymentlink"></p>
<a href="<?=$block->getPaymentLinkUrl();?>" onclick="copyToClipboard(event, '<?=$block->getPaymentLinkUrl();?>')" style="cursor:pointer;">
<?php echo __('Copy payment link to clipboard'); ?>
</a>
<script type="text/javascript">
function copyToClipboard(e, text) {
e.preventDefault();
var $temp = jQuery("<input>");
jQuery("body").append($temp);
$temp.val(text).select();
document.execCommand("copy");
$temp.remove();
}
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment