Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #25 from heidelpay/develop
Browse files Browse the repository at this point in the history
Version 17.6.16
  • Loading branch information
devheidelpay authored Jun 19, 2017
2 parents eb865ee + a01fcc3 commit de5187c
Show file tree
Hide file tree
Showing 34 changed files with 1,327 additions and 177 deletions.
207 changes: 207 additions & 0 deletions Block/Info/Invoice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
<?php

namespace Heidelpay\Gateway\Block\Info;

use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
use Heidelpay\Gateway\Model\Transaction;
use Magento\Framework\View\Element\Template;

/**
* Summary
* @license Use of this software requires acceptance of the License Agreement. See LICENSE file.
* @copyright Copyright © 2016-present Heidelberger Payment GmbH. All rights reserved.
* @link https://dev.heidelpay.de/magento2
* @author Stephano Vogel
* @package heidelpay
* @subpackage magento2
* @category magento2
*/
class Invoice extends \Magento\Payment\Block\Info
{
/** @var HeidelpayTransactionCollectionFactory */
protected $transactionCollectionFactory;

/** @var Transaction */
protected $transactionInfo;

/**
* @var \Heidelpay\Gateway\Helper\Payment
*/
protected $paymentHelper = null;

/**
* @var string
*/
protected $_template = 'Heidelpay_Gateway::info/invoice.phtml';

/**
* InvoiceSecured constructor.
*
* @param Template\Context $context
* @param HeidelpayTransactionCollectionFactory $collectionFactory
* @param \Heidelpay\Gateway\Helper\Payment $paymentHelper
* @param array $data
*/
public function __construct(
Template\Context $context,
HeidelpayTransactionCollectionFactory $collectionFactory,
\Heidelpay\Gateway\Helper\Payment $paymentHelper,
array $data = []
) {
$this->transactionCollectionFactory = $collectionFactory;
$this->paymentHelper = $paymentHelper;

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

/**
* Returns the Connector Account Holder Name.
*
* @return string
*/
public function getAccountHolder()
{
if ($this->transactionInfo === null) {
$this->loadTransactionInfo();
}

if (isset($this->transactionInfo->getJsonResponse()['CONNECTOR_ACCOUNT_HOLDER'])) {
return $this->transactionInfo->getJsonResponse()['CONNECTOR_ACCOUNT_HOLDER'];
}

return '-';
}

/**
* Returns the Connector Account IBAN.
*
* @return string
*/
public function getAccountIban()
{
if ($this->transactionInfo === null) {
$this->loadTransactionInfo();
}

if (isset($this->transactionInfo->getJsonResponse()['CONNECTOR_ACCOUNT_IBAN'])) {
return $this->transactionInfo->getJsonResponse()['CONNECTOR_ACCOUNT_IBAN'];
}

return '-';
}

/**
* Returns the Connector Account BIC.
*
* @return string
*/
public function getAccountBic()
{
if ($this->transactionInfo === null) {
$this->loadTransactionInfo();
}

if (isset($this->transactionInfo->getJsonResponse()['CONNECTOR_ACCOUNT_BIC'])) {
return $this->transactionInfo->getJsonResponse()['CONNECTOR_ACCOUNT_BIC'];
}

return '-';
}

public function printAdditionalInformationHtml()
{
if ($this->transactionInfo === null) {
$this->loadTransactionInfo();
}

return $this->getMethod()->additionalPaymentInformation($this->transactionInfo->getJsonResponse());
}

/**
* Returns the Short ID for this order/transaction.
*
* @return string
*/
public function getIdentificationNumber()
{
if ($this->transactionInfo === null) {
$this->loadTransactionInfo();
}

if (isset($this->transactionInfo->getJsonResponse()['IDENTIFICATION_SHORTID'])) {
return $this->transactionInfo->getJsonResponse()['IDENTIFICATION_SHORTID'];
}

return '-';
}

/**
* Returns the Amount to be paid.
*
* @return string
*/
public function getPresentationAmount()
{
if ($this->transactionInfo === null) {
$this->loadTransactionInfo();
}

if (isset($this->transactionInfo->getJsonResponse()['PRESENTATION_AMOUNT'])) {
return $this->paymentHelper->format($this->transactionInfo->getJsonResponse()['PRESENTATION_AMOUNT']);
}

return '-';
}

/**
* Returns the Currency of the Amount to be paid.
*
* @return string
*/
public function getPresentationCurrency()
{
if ($this->transactionInfo === null) {
$this->loadTransactionInfo();
}

if (isset($this->transactionInfo->getJsonResponse()['PRESENTATION_CURRENCY'])) {
return $this->transactionInfo->getJsonResponse()['PRESENTATION_CURRENCY'];
}

return '-';
}

/**
* Returns Transaction information, if a transaction ID is set.
*
* @return Transaction|null
*/
public function getTransactionInfo()
{
if ($this->transactionInfo === null) {
$this->loadTransactionInfo();
}

return $this->transactionInfo;
}

/**
* Loads heidelpay transaction details by the last_trans_id of this order.
*/
private function loadTransactionInfo()
{
if ($this->getInfo()->getLastTransId() !== null) {
$factory = $this->transactionCollectionFactory->create();
$this->transactionInfo = $factory->loadByTransactionId($this->getInfo()->getLastTransId());
}
}

/**
* @return string
*/
public function toPdf()
{
$this->setTemplate('Heidelpay_Gateway::info/pdf/invoice.phtml');
return $this->toHtml();
}
}
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Release Notes - heidelpay Payment Gateway for Magento 2

## v17.6.16

### Added
- Invoice (non-secure) payment method
- Online Capture and Refund functionality for all payment methods

### Fixed
- Wrong parent transaction id was set for Receipts in Push notifications
- Added an additional validator for sending invoices (PR #24)

## v17.5.9

### Fixed
Expand Down
92 changes: 49 additions & 43 deletions Controller/Adminhtml/Order/Shipment/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Heidelpay\Gateway\Controller\Adminhtml\Order\Shipment;

use Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod;
use Heidelpay\PhpApi\TransactionTypes\FinalizeTransactionType;
use Magento\Sales\Model\Order;

Expand Down Expand Up @@ -91,55 +92,60 @@ public function beforeExecute()
// get the payment method instance and the heidelpay method instance
/** @var \Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod $method */
$method = $order->getPayment()->getMethodInstance();
$heidelpayMethod = $method->getHeidelpayPaymentMethodInstance();

// if the payment method uses the Finalize Transaction type, we'll send a FIN request to the payment api.
if (in_array(FinalizeTransactionType::class, class_uses($heidelpayMethod))) {
// get the heidelpay configuration for the given payment method and store.
$paymentConfig = $method->getMainConfig($method->getCode(), $method->getStore());

// set the authentification data
$heidelpayMethod->getRequest()->authentification(
$paymentConfig['SECURITY.SENDER'],
$paymentConfig['USER.LOGIN'],
$paymentConfig['USER.PWD'],
$paymentConfig['TRANSACTION.CHANNEL'],
$paymentConfig['TRANSACTION.MODE']
);

// set the basket data (for amount and currency and a secret hash for fraud checking)
$heidelpayMethod->getRequest()->basketData(
$order->getQuoteId(),
$this->paymentHelper->format($order->getGrandTotal()),
$order->getOrderCurrencyCode(),
$this->encryptor->exportKeys()
);

// send the finalize request
/** @var \Heidelpay\PhpApi\Response $response */
$heidelpayMethod->finalize($order->getPayment()->getLastTransId());

// if the response isn't successful, redirect back to the order view.
if (!$heidelpayMethod->getResponse()->isSuccess()) {
$this->messageManager->addErrorMessage(
__('Heidelpay Error at sending Finalize Request. The Shipment was not created.')
. ' Error Message: ' . $heidelpayMethod->getResponse()->getError()['message']

// only fire the shipping when a heidelpay payment method is used.
if ($method instanceof HeidelpayAbstractPaymentMethod) {
// get the php-api instance.
$heidelpayMethod = $method->getHeidelpayPaymentMethodInstance();

// if the payment method uses the Finalize Transaction type, we'll send a FIN request to the payment api.
if (in_array(FinalizeTransactionType::class, class_uses($heidelpayMethod))) {
// get the heidelpay configuration for the given payment method and store.
$paymentConfig = $method->getMainConfig($method->getCode(), $method->getStore());

// set the authentification data
$heidelpayMethod->getRequest()->authentification(
$paymentConfig['SECURITY.SENDER'],
$paymentConfig['USER.LOGIN'],
$paymentConfig['USER.PWD'],
$paymentConfig['TRANSACTION.CHANNEL'],
$paymentConfig['TRANSACTION.MODE']
);

$this->logger->error(
'Heidelpay - Shipment Creation: Failure when sending finalize request. Error Message: '
. json_encode($heidelpayMethod->getResponse()->getError())
// set the basket data (for amount and currency and a secret hash for fraud checking)
$heidelpayMethod->getRequest()->basketData(
$order->getQuoteId(),
$this->paymentHelper->format($order->getGrandTotal()),
$order->getOrderCurrencyCode(),
$this->encryptor->exportKeys()
);

$this->_redirect('*/*/new', ['order_id' => $this->getRequest()->getParam('order_id')]);
}
// send the finalize request
/** @var \Heidelpay\PhpApi\Response $response */
$heidelpayMethod->finalize($order->getPayment()->getLastTransId());

// if the response isn't successful, redirect back to the order view.
if (!$heidelpayMethod->getResponse()->isSuccess()) {
$this->messageManager->addErrorMessage(
__('Heidelpay Error at sending Finalize Request. The Shipment was not created.')
. ' Error Message: ' . $heidelpayMethod->getResponse()->getError()['message']
);

// set order status to "pending payment"
$order->setStatus(Order::STATE_PENDING_PAYMENT)
->addStatusHistoryComment('heidelpay - Finalizing Order', Order::STATE_PENDING_PAYMENT)
->save();
$this->logger->error(
'Heidelpay - Shipment Creation: Failure when sending finalize request. Error Message: '
. json_encode($heidelpayMethod->getResponse()->getError())
);

$this->messageManager->addSuccessMessage(__('Shipping Notification has been sent to Heidelpay.'));
$this->_redirect('*/*/new', ['order_id' => $this->getRequest()->getParam('order_id')]);
}

// set order status to "pending payment"
$order->setStatus(Order::STATE_PENDING_PAYMENT)
->addStatusHistoryComment('heidelpay - Finalizing Order', Order::STATE_PENDING_PAYMENT)
->save();

$this->messageManager->addSuccessMessage(__('Shipping Notification has been sent to Heidelpay.'));
}
}
}
}
20 changes: 17 additions & 3 deletions Controller/Index/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,23 @@ public function __construct(
\Magento\Customer\Model\Url $customerUrl,
\Magento\Framework\Escaper $escaper
) {
parent::__construct($context, $customerSession, $checkoutSession, $orderFactory, $urlHelper, $logger,
$cartManagement, $quoteObject, $resultPageFactory, $paymentHelper, $orderSender, $invoiceSender,
$orderCommentSender, $encryptor, $customerUrl);
parent::__construct(
$context,
$customerSession,
$checkoutSession,
$orderFactory,
$urlHelper,
$logger,
$cartManagement,
$quoteObject,
$resultPageFactory,
$paymentHelper,
$orderSender,
$invoiceSender,
$orderCommentSender,
$encryptor,
$customerUrl
);

$this->escaper = $escaper;
}
Expand Down
Loading

0 comments on commit de5187c

Please sign in to comment.