Skip to content

Commit

Permalink
Merge pull request #60 from unzerdev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
chrhas79 authored Feb 21, 2024
2 parents 59b390d + 48686f8 commit 9d41825
Show file tree
Hide file tree
Showing 24 changed files with 670 additions and 63 deletions.
186 changes: 186 additions & 0 deletions Block/Info/PaylaterDirectDebit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<?php
declare(strict_types=1);

namespace Unzer\PAPI\Block\Info;

use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Element\Template;
use Magento\Payment\Block\Info;
use Magento\Sales\Model\Order;
use Unzer\PAPI\Model\Config;
use UnzerSDK\Exceptions\UnzerApiException;
use UnzerSDK\Resources\Payment;
use UnzerSDK\Resources\TransactionTypes\Authorization;
use UnzerSDK\Resources\TransactionTypes\Charge;

/**
* Customer Account Order Installment Information Block
*
* @link https://docs.unzer.com/
*/
class PaylaterDirectDebit extends Info
{
/**
* @var Config
*/
protected Config $_moduleConfig;

/**
* @var Payment|null
*/
protected ?Payment $_payment = null;

/**
* @var string
*/
protected $_template = 'Unzer_PAPI::info/paylater_direct_debit.phtml';

/**
* Constructor
*
* @param Template\Context $context
* @param Config $moduleConfig
* @param array $data
*/
public function __construct(
Template\Context $context,
Config $moduleConfig,
array $data = []
) {
parent::__construct($context, $data);

$this->_moduleConfig = $moduleConfig;
}

/**
* Get Initial Transaction
*
* @return Authorization|Charge|null
* @throws UnzerApiException
* @throws LocalizedException
*/
protected function getInitialTransaction()
{
$transaction = $this->_getPayment()->getInitialTransaction();

if ($transaction instanceof Authorization || $transaction instanceof Charge) {
return $transaction;
}
return null;
}

/**
* Get Payment
*
* @throws UnzerApiException
* @throws LocalizedException
*/
protected function _getPayment(): Payment
{
if ($this->_payment === null) {
/** @var Order $order */
$order = $this->getInfo()->getOrder();

$storeId = $this->getStoreCode($order->getStoreId());
$client = $this->_moduleConfig->getUnzerClient($storeId, $order->getPayment()->getMethodInstance());

$this->_payment = $client->fetchPaymentByOrderId($order->getIncrementId());
}

return $this->_payment;
}

/**
* Get Store Code
*
* @param string|null $storeId
* @return string
* @throws NoSuchEntityException
*/
public function getStoreCode(string $storeId = null): string
{
return $this->_storeManager->getStore($storeId)->getCode();
}

/**
* Has Account Data
*
* @throws UnzerApiException
* @throws LocalizedException
*/
public function hasAccountData(): bool
{
return $this->getInitialTransaction() !== null;
}

/**
* Get Account Holder
*
* @throws UnzerApiException
* @throws LocalizedException
*/
public function getAccountHolder(): ?string
{
$initialTransaction = $this->getInitialTransaction();
if ($initialTransaction === null) {
return null;
}

return $initialTransaction->getHolder();
}

/**
* Get Account Iban
*
* @throws UnzerApiException
* @throws LocalizedException
*/
public function getAccountIban(): ?string
{
$initialTransaction = $this->getInitialTransaction();
if ($initialTransaction === null) {
return null;
}
return $initialTransaction->getIban();
}

/**
* Get Account Bic
*
* @throws UnzerApiException
* @throws LocalizedException
*/
public function getAccountBic(): ?string
{
$initialTransaction = $this->getInitialTransaction();
if ($initialTransaction === null) {
return null;
}
return $initialTransaction->getBic();
}

/**
* Get Reference
*
* @throws UnzerApiException
* @throws LocalizedException
*/
public function getReference(): ?string
{
$initialTransaction = $this->getInitialTransaction();
if ($initialTransaction === null) {
return null;
}
return $initialTransaction->getDescriptor();
}

/**
* @inheritDoc
*/
public function toPdf(): string
{
$this->setTemplate('Unzer_PAPI::info/pdf/paylater_direct_debit.phtml');
return $this->toHtml();
}
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [2.5.0](/~https://github.com/unzerdev/magento2/compare/2.4.1..2.5.0)
### Added
* Direct Debit Secured payment method
### Fixed
* active logging automatically switched to sandbox urls

## [2.4.1](/~https://github.com/unzerdev/magento2/compare/2.4.0..2.4.1)
### Removed
* Payment Details on success page for Paylater Invoice payment methods. Details are send by Paylater via email.
Expand Down
Loading

0 comments on commit 9d41825

Please sign in to comment.