Skip to content

Commit

Permalink
更新設定及更新程式
Browse files Browse the repository at this point in the history
  • Loading branch information
AllennChang committed Oct 30, 2024
1 parent 7c2dd11 commit 1b155ba
Show file tree
Hide file tree
Showing 40 changed files with 1,447 additions and 309 deletions.
37 changes: 33 additions & 4 deletions Api/InvoiceInterface.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,65 @@
<?php
namespace Ecpay\General\Api;

use Magento\Framework\Controller\Result\Json;

interface InvoiceInterface {

/**
*
* @param string $barcode
* @return Json
*/
public function checkBarcode($barcode);

/**
*
* @param string $loveCode
* @return Json
*/
public function checkLoveCode($loveCode);

/**
*
* @param string $carrierNumber
* @return Json
*/
public function checkCitizenDigitalCertificate($carrierNumber);

/**
*
* @param string $businessNumber
* @return Json
*/
public function checkBusinessNumber($businessNumber);

/**
*
* @param string $orderId
* @param string $protectCode
* @return []
* @return Json
*/
public function createInvoice($orderId, $protectCode);

/**
*
* @param string $orderId
* @param string $protectCode
* @return []
* @return Json
*/
public function invalidInvoice($orderId, $protectCode);

/**
*
* @param string $orderId
* @param string $protectCode
* @return []
* @return Json
*/
public function getInvoiceTag($orderId, $protectCode);

/**
*
* @return []
* @return Json
*/
public function getInvoiceMainConfig();
}
13 changes: 7 additions & 6 deletions Api/LogisticInterface.php
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
<?php
namespace Ecpay\General\Api;

use Magento\Framework\Controller\Result\Json;

interface LogisticInterface {

/**
* changeStore
* @param string $orderId
* @param string $protectCode
* @return []
* @return Json
*/
public function changeStore($orderId, $protectCode);

/**
* createOrder
* @param string $orderId
* @param string $protectCode
* @return []
* @return Json
*/
public function createOrder($orderId, $protectCode);

/**
* printOrder
* @param string $orderId
* @param string $protectCode
* @return []
* @return Json
*/
public function printOrder($orderId, $protectCode);

/**
* getLogisticMainConfig
* @return []
* @return Json
*/
public function getLogisticMainConfig();

/**
* getShippingMethod
* @param string $orderId
* @param string $protectCode
* @return []
* @return Json
*/
public function getShippingMethod($orderId, $protectCode);

/**
* getShippingTag
* @param string $orderId
* @param string $protectCode
* @return []
* @return Json
*/
public function getShippingTag($orderId, $protectCode);

Expand Down
74 changes: 74 additions & 0 deletions Block/Adminhtml/Order/PaymentInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Ecpay\General\Block\Adminhtml\Order;

use Magento\Sales\Block\Adminhtml\Order\View\Tab\Info;
use Magento\Shipping\Helper\Data as ShippingHelper;
use Magento\Tax\Helper\Data as TaxHelper;
use Ecpay\General\Helper\Services\Common\OrderService;
use Ecpay\General\Helper\Services\Config\PaymentService;

class PaymentInfo extends Info
{
protected $_orderService;
protected $_paymentService;
protected $_orderRepository;

protected $orderId;

public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Sales\Helper\Admin $adminHelper,
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
OrderService $orderService,
PaymentService $paymentService,
array $data = [],
?ShippingHelper $shippingHelper = null,
?TaxHelper $taxHelper = null
) {
parent::__construct($context, $registry, $adminHelper, $data, $shippingHelper, $taxHelper);

$this->_orderService = $orderService;
$this->_paymentService = $paymentService;
$this->_orderRepository = $orderRepository;

$this->orderId = $this->getOrder()->getId();
$this->_logger->debug('Admin PaymentInfo Block $this->orderId : ' . $this->getOrder()->getIdFieldName() . ' ' . $this->orderId);
}

/**
* 是否顯示綠界付款資訊
*
* @return bool
*/
public function isShowEcpayPaymentInfo()
{
$allowedPaymentInfoList = ['ecpay_atm_gateway', 'ecpay_cvs_gateway', 'ecpay_barcode_gateway', 'ecpay_credit_installment_gateway'];
$paymentMethod = $this->_orderService->getPaymentMethod($this->orderId);

if (in_array($paymentMethod, $allowedPaymentInfoList)) {
return true;
}

return false;
}

/**
* 取得綠界付款資訊
*
* @return array $paymentInfo
*/
public function getEcpayPaymentInfo()
{
$paymentInfo = [];

$paymentMethod = $this->_orderService->getPaymentMethod($this->orderId);

if ($this->_paymentService->isEcpayPayment($paymentMethod)) {
$paymentInfo = $this->_orderService->getEcpayPaymentInfoContent($this->orderId, $paymentMethod);
}

return $paymentInfo;
}
}
85 changes: 85 additions & 0 deletions Block/Frontend/Order/PaymentInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Ecpay\General\Block\Frontend\Order;

use Magento\Sales\Block\Order\Info;
use Magento\Framework\View\Element\Template\Context as TemplateContext;
use Magento\Framework\Registry;
use Magento\Payment\Helper\Data as PaymentHelper;
use Magento\Sales\Model\Order\Address\Renderer as AddressRenderer;
use Ecpay\General\Helper\Services\Common\OrderService;
use Ecpay\General\Helper\Services\Config\PaymentService;

class PaymentInfo extends Info
{
protected $_orderService;
protected $_paymentService;

protected $orderId;

/**
* @param TemplateContext $context
* @param Registry $registry
* @param PaymentHelper $paymentHelper
* @param AddressRenderer $addressRenderer
* @param OrderService $orderService
* @param PaymentService $paymentService
* @param array $data
*/
public function __construct(
TemplateContext $context,
Registry $registry,
PaymentHelper $paymentHelper,
AddressRenderer $addressRenderer,
OrderService $orderService,
PaymentService $paymentService,
array $data = []
) {
parent::__construct($context, $registry, $paymentHelper, $addressRenderer, $data);

$this->_orderService = $orderService;
$this->_paymentService = $paymentService;

$this->orderId = $this->getOrder()->getId();
$this->_logger->debug('Frontend PaymentInfo Block $this->orderId : ' . $this->getOrder()->getIdFieldName() . ' ' . $this->orderId);
}

/**
* @return string
*/
public function getPaymentInfoHtml()
{
return parent::getPaymentInfoHtml() . $this->getEcpayPaymentInfoHtml();
}

/**
* @return string
*/
public function getEcpayPaymentInfoHtml()
{
$html = '<dl class="ecpay-payment-method">';
foreach ($this->getEcpayPaymentInfo() as $info) {
$html .= ' <dt class="title">' . $info['key'] . '' . $info['val'] . '</dt>';
}
$html .= '</dl>';

return $html;
}

/**
* 取得綠界付款資訊
*
* @return array $paymentInfo
*/
public function getEcpayPaymentInfo()
{
$paymentInfo = [];
$paymentMethod = $this->_orderService->getPaymentMethod($this->orderId);

if ($this->_paymentService->isEcpayPayment($paymentMethod)) {
$paymentInfo = $this->_orderService->getEcpayPaymentInfoContent($this->orderId, $paymentMethod);
}

return $paymentInfo;
}
}
66 changes: 66 additions & 0 deletions Block/Onepage/RedirectToEcpay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
namespace Ecpay\General\Block\Onepage;

use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Psr\Log\LoggerInterface;

use Ecpay\General\Helper\Services\Common\EncryptionsService;
use Ecpay\General\Helper\Services\Common\OrderService;
use Ecpay\General\Helper\Services\Common\ToEcpayService;
use Ecpay\General\Helper\Services\Config\PaymentService;
use Ecpay\General\Helper\Services\Config\LogisticService;

class RedirectToEcpay extends Template
{
protected $_checkoutSession;

protected $_loggerInterface;

protected $_encryptionsService;
protected $_orderService;
protected $_toEcpayService;

protected $_paymentService;
protected $_logisticService;

protected $orderId;

public function __construct(
Context $context,
CheckoutSession $checkoutSession,
LoggerInterface $loggerInterface,
EncryptionsService $encryptionsService,
OrderService $orderService,
ToEcpayService $toEcpayService,
PaymentService $paymentService,
LogisticService $logisticService,
array $data = []
) {
$this->_checkoutSession = $checkoutSession;
$this->_loggerInterface = $loggerInterface;

$this->_encryptionsService = $encryptionsService;
$this->_orderService = $orderService;
$this->_toEcpayService = $toEcpayService;

$this->_paymentService = $paymentService;
$this->_logisticService = $logisticService;

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

/**
* 產生綠界金、物流表單後至前端 echo
*/
public function getFormHtml() {
$enctyOrderId = $this->getRequest()->getParam('id');
$formType = $this->getRequest()->getParam('type');

if ($formType == 'payment') $form = $this->_toEcpayService->preparePayment($enctyOrderId);
else $form = $this->_toEcpayService->prepareLogistic($enctyOrderId);

return $form;
}
}
Loading

0 comments on commit 1b155ba

Please sign in to comment.