diff --git a/Block/Info/Invoice.php b/Block/Info/Invoice.php
new file mode 100644
index 00000000000..7d6ca420465
--- /dev/null
+++ b/Block/Info/Invoice.php
@@ -0,0 +1,207 @@
+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();
+ }
+}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8e07b266a3b..3c7d0df4777 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/Controller/Adminhtml/Order/Shipment/Save.php b/Controller/Adminhtml/Order/Shipment/Save.php
index 178f4189668..189a053f003 100644
--- a/Controller/Adminhtml/Order/Shipment/Save.php
+++ b/Controller/Adminhtml/Order/Shipment/Save.php
@@ -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;
@@ -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.'));
+ }
}
}
}
diff --git a/Controller/Index/Index.php b/Controller/Index/Index.php
index 3c459be99a2..23b051f6e2a 100644
--- a/Controller/Index/Index.php
+++ b/Controller/Index/Index.php
@@ -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;
}
diff --git a/Controller/Index/Push.php b/Controller/Index/Push.php
index 279378faa1a..cbef27a4992 100644
--- a/Controller/Index/Push.php
+++ b/Controller/Index/Push.php
@@ -3,6 +3,7 @@
namespace Heidelpay\Gateway\Controller\Index;
use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
+use Magento\Sales\Model\Order\Payment\Transaction;
use Magento\Sales\Model\Order\Invoice;
use Magento\Sales\Model\Order;
@@ -143,8 +144,12 @@ public function execute()
$this->_logger->debug('Push Response: ' . print_r($this->heidelpayPush->getResponse(), true));
- // in case of invoice receipts, we process the push message
- if ($this->heidelpayPush->getResponse()->getPayment()->getCode() == 'IV.RC') {
+ list($paymentMethod, $paymentType) = $this->_paymentHelper->splitPaymentCode(
+ $this->heidelpayPush->getResponse()->getPayment()->getCode()
+ );
+
+ // in case of receipts, we process the push message for receipts.
+ if ($this->_paymentHelper->isReceiptAble($paymentMethod, $paymentType)) {
// only when the Response is ACK.
if ($this->heidelpayPush->getResponse()->isSuccess()) {
// load the reference quote to receive the quote information.
@@ -160,12 +165,12 @@ public function execute()
$dueLeft = (float)($order->getTotalDue() - $paidAmount);
$state = Order::STATE_COMPLETE;
- $comment = 'heidelpay - Purchase complete';
+ $comment = 'heidelpay - Purchase Complete';
// if payment is not complete
if ($dueLeft > 0.00) {
$state = Order::STATE_PAYMENT_REVIEW;
- $comment = 'heidelpay - Partly paid ('
+ $comment = 'heidelpay - Partly Paid ('
. $this->_paymentHelper->format(
$this->heidelpayPush->getResponse()->getPresentation()->getAmount()
)
@@ -181,9 +186,28 @@ public function execute()
}
$order->setTotalPaid($order->getTotalPaid() + $paidAmount)
+ ->setBaseTotalPaid($order->getBaseTotalPaid() + $paidAmount)
->setState($state)
->addStatusHistoryComment($comment, $state);
+ // create a heidelpay Transaction.
+ $order->getPayment()->getMethodInstance()->saveHeidelpayTransaction(
+ $this->heidelpayPush->getResponse(),
+ $paymentMethod,
+ $paymentType,
+ 'PUSH',
+ []
+ );
+
+ // create a child transaction.
+ $order->getPayment()->setTransactionId($this->heidelpayPush->getResponse()->getPaymentReferenceId());
+ $order->getPayment()->setParentTransactionId(
+ $this->heidelpayPush->getResponse()->getIdentification()->getReferenceId()
+ );
+ $order->getPayment()->setIsTransactionClosed(true);
+
+ $order->getPayment()->addTransaction(Transaction::TYPE_CAPTURE, null, true);
+
$order->save();
}
}
diff --git a/Controller/Index/Redirect.php b/Controller/Index/Redirect.php
index bcfc22ac6b8..04f990b9654 100644
--- a/Controller/Index/Redirect.php
+++ b/Controller/Index/Redirect.php
@@ -35,6 +35,9 @@ class Redirect extends \Heidelpay\Gateway\Controller\HgwAbstract
/** @var \Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory */
protected $transactionCollectionFactory;
+ /** @var \Magento\Sales\Helper\Data */
+ protected $salesHelper;
+
/**
* heidelpay Redirect constructor.
*
@@ -48,6 +51,7 @@ class Redirect extends \Heidelpay\Gateway\Controller\HgwAbstract
* @param \Magento\Quote\Api\CartRepositoryInterface $quoteObject
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param HeidelpayHelper $paymentHelper
+ * @param \Magento\Sales\Helper\Data $salesHelper
* @param OrderSender $orderSender
* @param InvoiceSender $invoiceSender
* @param OrderCommentSender $orderCommentSender
@@ -67,6 +71,7 @@ public function __construct(
\Magento\Quote\Api\CartRepositoryInterface $quoteObject,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
HeidelpayHelper $paymentHelper,
+ \Magento\Sales\Helper\Data $salesHelper,
OrderSender $orderSender,
InvoiceSender $invoiceSender,
OrderCommentSender $orderCommentSender,
@@ -95,6 +100,7 @@ public function __construct(
$this->heidelpayResponse = $heidelpayResponse;
$this->transactionCollectionFactory = $transactionCollectionFactory;
+ $this->salesHelper = $salesHelper;
}
public function execute()
@@ -154,15 +160,19 @@ public function execute()
);
}
- // send invoice(s) to the customer
- if (!$order->canInvoice()) {
- $invoices = $order->getInvoiceCollection();
+ // Check send Invoice Mail enabled
+ if ($this->salesHelper->canSendNewInvoiceEmail($session->getQuote()->getStore()->getId())) {
+ // send invoice(s) to the customer
+ if (!$order->canInvoice()) {
+ $invoices = $order->getInvoiceCollection();
- foreach ($invoices as $invoice) {
- $this->_invoiceSender->send($invoice);
+ foreach ($invoices as $invoice) {
+ $this->_invoiceSender->send($invoice);
+ }
}
}
+
$session->clearHelperData();
// set QouteIds
diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php
index 38a70eb57a7..e339cfc8780 100644
--- a/Controller/Index/Response.php
+++ b/Controller/Index/Response.php
@@ -261,26 +261,19 @@ public function execute()
try {
// save the response details into the heidelpay Transactions table.
- $transaction = $this->transactionFactory->create();
- $transaction->setPaymentMethod($paymentMethod)
- ->setPaymentType($paymentType)
- ->setTransactionId($this->heidelpayResponse->getIdentification()->getTransactionId())
- ->setUniqueId($this->heidelpayResponse->getIdentification()->getUniqueId())
- ->setShortId($this->heidelpayResponse->getIdentification()->getShortId())
- ->setStatusCode($this->heidelpayResponse->getProcessing()->getStatusCode())
- ->setResult($this->heidelpayResponse->getProcessing()->getResult())
- ->setReturnMessage($this->heidelpayResponse->getProcessing()->getReturn())
- ->setReturnCode($this->heidelpayResponse->getProcessing()->getReturnCode())
- ->setJsonResponse(json_encode($data))
- ->setSource('RESPONSE')
- ->save();
+ $order->getPayment()->getMethodInstance()->saveHeidelpayTransaction(
+ $this->heidelpayResponse,
+ $paymentMethod,
+ $paymentType,
+ 'RESPONSE',
+ $data
+ );
} catch (\Exception $e) {
$this->_logger->error('Heidelpay - Response: Save transaction error. ' . $e->getMessage());
}
// return the heidelpay response url as raw response instead of echoing it out.
$result->setContents($redirectUrl);
-
return $result;
}
}
diff --git a/Helper/Payment.php b/Helper/Payment.php
index 05a01e749cc..3b8c30d3c94 100644
--- a/Helper/Payment.php
+++ b/Helper/Payment.php
@@ -175,6 +175,75 @@ public function isProcessing($paymentCode, $data)
&& $data['PROCESSING_STATUS_CODE'] != 80;
}
+ /**
+ * @param array $data
+ *
+ * @return bool
+ */
+ public function isPreAuthorization(array $data)
+ {
+ if (!isset($data['PAYMENT_CODE'])) {
+ return false;
+ }
+
+ $paymentCode = $this->splitPaymentCode($data['PAYMENT_CODE']);
+
+ if ($paymentCode[1] == 'PA') {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Determines if the payment code and type are for a receipt.
+ *
+ * @param string $paymentMethod
+ * @param string $paymentType
+ *
+ * @return bool
+ */
+ public function isReceiptAble($paymentMethod, $paymentType)
+ {
+ if ($paymentType !== 'RC') {
+ return false;
+ }
+
+ switch ($paymentMethod) {
+ case 'DD':
+ case 'PP':
+ case 'IV':
+ case 'OT':
+ case 'PC':
+ case 'MP':
+ case 'HP':
+ $return = true;
+ break;
+
+ default:
+ $return = false;
+ break;
+ }
+
+ return $return;
+ }
+
+ /**
+ * Checks if the given paymentcode is viable for a refund transaction.
+ *
+ * @param string $paymentcode
+ *
+ * @return bool
+ */
+ public function isRefundable($paymentcode)
+ {
+ if ($paymentcode === 'DB' || $paymentcode === 'CP' || $paymentcode === 'RC') {
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Saves a transaction by the given invoice.
*
diff --git a/Model/Config/Source/BookingMode.php b/Model/Config/Source/BookingMode.php
new file mode 100644
index 00000000000..8f304e3ac8b
--- /dev/null
+++ b/Model/Config/Source/BookingMode.php
@@ -0,0 +1,36 @@
+ self::AUTHORIZATION, 'label' => __('Authorization')],
+ ['value' => self::DEBIT, 'label' => __('Debit')],
+ ];
+ }
+}
diff --git a/Model/ResourceModel/Transaction/Collection.php b/Model/ResourceModel/Transaction/Collection.php
index 73e28a9985f..ad89d161a25 100644
--- a/Model/ResourceModel/Transaction/Collection.php
+++ b/Model/ResourceModel/Transaction/Collection.php
@@ -45,21 +45,41 @@ public function loadByTransactionId($transactionId)
}
/**
- * Adds a filter for the customer/guest e-mail address
+ * Adds a filter for the quote id
*
* @param string $quoteId
*
* @return $this
*/
- private function addQuoteIdFilter($quoteId)
+ public function addQuoteIdFilter($quoteId)
{
$this->addFieldToFilter('transactionid', $quoteId);
return $this;
}
- private function addTransactionIdFilter($transactionId)
+ /**
+ * Adds a filter for unique transaction id.
+ *
+ * @param string $transactionId
+ *
+ * @return $this
+ */
+ public function addTransactionIdFilter($transactionId)
{
$this->addFieldToFilter('uniqeid', $transactionId);
return $this;
}
+
+ /**
+ * Adds a filter for unique transaction id.
+ *
+ * @param string|array $paymentType
+ *
+ * @return $this
+ */
+ public function addPaymentTypeFilter($paymentType)
+ {
+ $this->addFieldToFilter('payment_type', $paymentType);
+ return $this;
+ }
}
diff --git a/Model/Transaction.php b/Model/Transaction.php
index a9995abeee3..43fe0d75d3a 100644
--- a/Model/Transaction.php
+++ b/Model/Transaction.php
@@ -93,7 +93,7 @@ public function setTransactionId($transactionId)
*/
public function getUniqueId()
{
- return $this->getData('uniqueid');
+ return $this->getData('uniqeid');
}
/**
diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php
index d9def1b1c4d..0fffd85cadc 100644
--- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php
+++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php
@@ -2,7 +2,10 @@
namespace Heidelpay\Gateway\PaymentMethods;
+use Heidelpay\Gateway\Model\Config\Source\BookingMode;
use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory;
+use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
+use Heidelpay\PhpApi\Response;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Invoice;
use Magento\Sales\Model\Order\Payment\Transaction;
@@ -133,6 +136,9 @@ class HeidelpayAbstractPaymentMethod extends \Magento\Payment\Model\Method\Abstr
*/
protected $productMetadata;
+ /** @var \Magento\Sales\Helper\Data */
+ protected $salesHelper;
+
/**
* Resource information about modules
*
@@ -147,6 +153,16 @@ class HeidelpayAbstractPaymentMethod extends \Magento\Payment\Model\Method\Abstr
*/
protected $paymentInformationCollectionFactory;
+ /**
+ * @var \Heidelpay\Gateway\Model\TransactionFactory
+ */
+ protected $transactionFactory;
+
+ /**
+ * @var HeidelpayTransactionCollectionFactory
+ */
+ protected $transactionCollectionFactory;
+
/**
* heidelpay Abstract Payment method constructor
*
@@ -164,7 +180,10 @@ class HeidelpayAbstractPaymentMethod extends \Magento\Payment\Model\Method\Abstr
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param \Magento\Framework\Module\ResourceInterface $moduleResource
* @param \Heidelpay\Gateway\Helper\Payment $paymentHelper
+ * @param \Magento\Sales\Helper\Data $salesHelper
* @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory
+ * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory
+ * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
@@ -184,20 +203,32 @@ public function __construct(
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
\Magento\Framework\Module\ResourceInterface $moduleResource,
\Heidelpay\Gateway\Helper\Payment $paymentHelper,
+ \Magento\Sales\Helper\Data $salesHelper,
PaymentInformationCollectionFactory $paymentInformationCollectionFactory,
+ \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory,
+ HeidelpayTransactionCollectionFactory $transactionCollectionFactory,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
parent::__construct(
- $context, $registry, $extensionFactory, $customAttributeFactory, $paymentData, $scopeConfig,
- $logger, $resource, $resourceCollection, $data
+ $context,
+ $registry,
+ $extensionFactory,
+ $customAttributeFactory,
+ $paymentData,
+ $scopeConfig,
+ $logger,
+ $resource,
+ $resourceCollection,
+ $data
);
$this->urlBuilder = $urlinterface;
$this->logger = $logger;
$this->_requestHttp = $request;
$this->_paymentHelper = $paymentHelper;
+ $this->salesHelper = $salesHelper;
$this->_encryptor = $encryptor;
$this->_localResolver = $localeResolver;
@@ -205,6 +236,8 @@ public function __construct(
$this->moduleResource = $moduleResource;
$this->paymentInformationCollectionFactory = $paymentInformationCollectionFactory;
+ $this->transactionFactory = $transactionFactory;
+ $this->transactionCollectionFactory = $transactionCollectionFactory;
}
/**
@@ -235,19 +268,203 @@ public function getConfigData($field, $storeId = null)
return $this->_scopeConfig->getValue($path, StoreScopeInterface::SCOPE_STORE, $storeId);
}
+ /**
+ * @inheritdoc
+ *
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
+ {
+ /** @var \Magento\Sales\Model\Order\Payment $payment */
+ if (!$this->canCapture()) {
+ throw new \Magento\Framework\Exception\LocalizedException(__('The capture action is not available.'));
+ }
+
+ // skip the bottom part, if the booking mode is not authorization.
+ if ($this->getBookingMode() !== BookingMode::AUTHORIZATION) {
+ return $this;
+ }
+
+ // create the transactioncollection factory to get the parent authorization.
+ $factory = $this->transactionCollectionFactory->create();
+ /** @var \Heidelpay\Gateway\Model\Transaction $transactionInfo */
+ $transactionInfo = $factory->loadByTransactionId($payment->getParentTransactionId());
+
+ // if there is no heidelpay transaction, something went wrong.
+ if ($transactionInfo === null || $transactionInfo->isEmpty()) {
+ throw new \Magento\Framework\Exception\LocalizedException(__('heidelpay - No transaction data available'));
+ }
+
+ // we can only Capture on Pre-Authorization payment types.
+ // so is the payment type of this Transaction is no PA, we won't capture anything.
+ if ($transactionInfo->getPaymentType() !== 'PA') {
+ throw new \Magento\Framework\Exception\LocalizedException(
+ __('heidelpay - Cannot capture this transaction.')
+ );
+ }
+
+ // get the configuration for the heidelpay Capture Request
+ $config = $this->getMainConfig($this->getCode(), $payment->getOrder()->getStoreId());
+
+ // set authentification data
+ $this->_heidelpayPaymentMethod->getRequest()->authentification(
+ $config['SECURITY.SENDER'],
+ $config['USER.LOGIN'],
+ $config['USER.PWD'],
+ $config['TRANSACTION.CHANNEL'],
+ $config['TRANSACTION.MODE']
+ );
+
+ // set basket data
+ $this->_heidelpayPaymentMethod->getRequest()->basketData(
+ $payment->getOrder()->getQuoteId(),
+ $this->_paymentHelper->format($amount),
+ $payment->getOrder()->getOrderCurrencyCode(),
+ $this->_encryptor->exportKeys()
+ );
+
+ // send the capture request
+ $this->_heidelpayPaymentMethod->capture($transactionInfo->getUniqueId());
+
+ $this->_logger->debug(
+ 'heidelpay - Capture Response: ' . print_r($this->_heidelpayPaymentMethod->getResponse(), 1)
+ );
+
+ // if the heidelpay Request wasn't successful, throw an Exception with the heidelpay message
+ if (!$this->_heidelpayPaymentMethod->getResponse()->isSuccess()) {
+ throw new \Magento\Framework\Exception\LocalizedException(
+ __('heidelpay - ' . $this->_heidelpayPaymentMethod->getResponse()->getProcessing()->getReturn())
+ );
+ }
+
+ list($paymentMethod, $paymentType) = $this->_paymentHelper->splitPaymentCode(
+ $this->_heidelpayPaymentMethod->getResponse()->getPayment()->getCode()
+ );
+
+ // Create a new heidelpay Transaction
+ $this->saveHeidelpayTransaction(
+ $this->_heidelpayPaymentMethod->getResponse(),
+ $paymentMethod,
+ $paymentType,
+ 'RESPONSE',
+ []
+ );
+
+ // create a child transaction.
+ $payment->setTransactionId($this->_heidelpayPaymentMethod->getResponse()->getPaymentReferenceId());
+ $payment->setParentTransactionId($transactionInfo->getUniqueId());
+ $payment->setIsTransactionClosed(true);
+ $payment->addTransaction(Transaction::TYPE_CAPTURE, null, true);
+
+ // set the last transaction id to the Pre-Authorization.
+ $payment->setLastTransId($this->_heidelpayPaymentMethod->getResponse()->getPaymentReferenceId());
+ $payment->save();
+
+ return $this;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
+ {
+ /** @var \Magento\Sales\Model\Order\Payment\Interceptor $payment */
+ if (!$this->canRefund()) {
+ throw new \Magento\Framework\Exception\LocalizedException(__('The refund action is not available.'));
+ }
+
+ // create the transactioncollection to get the parent authorization.
+ $collection = $this->transactionCollectionFactory->create();
+
+ /** @var \Heidelpay\Gateway\Model\Transaction $transactionInfo */
+ $transactionInfo = $collection->loadByTransactionId($payment->getLastTransId());
+
+ // if there is no heidelpay transaction, something went wrong.
+ if ($transactionInfo === null || $transactionInfo->isEmpty()) {
+ throw new \Magento\Framework\Exception\LocalizedException(__('heidelpay - No transaction data available'));
+ }
+
+ // we can only refund on transaction where money has been credited/debited
+ // so is the payment type of this Transaction none of them, we won't refund anything.
+ if (!$this->_paymentHelper->isRefundable($transactionInfo->getPaymentType())) {
+ throw new \Magento\Framework\Exception\LocalizedException(
+ __('heidelpay - Cannot refund this transaction.')
+ );
+ }
+
+ // get the configuration for the heidelpay Capture Request
+ $config = $this->getMainConfig($this->getCode(), $payment->getOrder()->getStoreId());
+
+ // set authentification data
+ $this->_heidelpayPaymentMethod->getRequest()->authentification(
+ $config['SECURITY.SENDER'],
+ $config['USER.LOGIN'],
+ $config['USER.PWD'],
+ $config['TRANSACTION.CHANNEL'],
+ $config['TRANSACTION.MODE']
+ );
+
+ // set basket data
+ $this->_heidelpayPaymentMethod->getRequest()->basketData(
+ $payment->getOrder()->getQuoteId(),
+ $this->_paymentHelper->format($amount),
+ $payment->getOrder()->getOrderCurrencyCode(),
+ $this->_encryptor->exportKeys()
+ );
+
+ // send the refund request
+ $this->_heidelpayPaymentMethod->refund($transactionInfo->getUniqueId());
+
+ $this->_logger->debug(
+ 'heidelpay - Refund Response: ' . print_r($this->_heidelpayPaymentMethod->getResponse(), 1)
+ );
+
+ // if the heidelpay Request wasn't successful, throw an Exception with the heidelpay message
+ if (!$this->_heidelpayPaymentMethod->getResponse()->isSuccess()) {
+ throw new \Magento\Framework\Exception\LocalizedException(
+ __('heidelpay - ' . $this->_heidelpayPaymentMethod->getResponse()->getProcessing()->getReturn())
+ );
+ }
+
+ list($paymentMethod, $paymentType) = $this->_paymentHelper->splitPaymentCode(
+ $this->_heidelpayPaymentMethod->getResponse()->getPayment()->getCode()
+ );
+
+ // Create a new heidelpay Transaction
+ $this->saveHeidelpayTransaction(
+ $this->_heidelpayPaymentMethod->getResponse(),
+ $paymentMethod,
+ $paymentType,
+ 'RESPONSE',
+ []
+ );
+
+ // create a child transaction.
+ $payment->setTransactionId($this->_heidelpayPaymentMethod->getResponse()->getPaymentReferenceId());
+ $payment->setParentTransactionId($transactionInfo->getUniqueId());
+ $payment->setIsTransactionClosed(true);
+ $payment->addTransaction(Transaction::TYPE_REFUND, null, true);
+
+ // set the last transaction id to the Pre-Authorization.
+ $payment->setLastTransId($this->_heidelpayPaymentMethod->getResponse()->getPaymentReferenceId());
+ $payment->save();
+
+ return $this;
+ }
+
/**
* @param \Magento\Quote\Model\Quote $quote
*/
public function getHeidelpayUrl($quote)
{
- $config = $this->getMainConfig($this->_code, $this->getStore());
+ $config = $this->getMainConfig($this->getCode(), $this->getStore());
$this->_heidelpayPaymentMethod->getRequest()->authentification(
- $config ['SECURITY.SENDER'], // SecuritySender
- $config ['USER.LOGIN'], // UserLogin
- $config ['USER.PWD'], // UserPassword
- $config ['TRANSACTION.CHANNEL'], // TransactionChannel credit card without 3d secure
- $config ['TRANSACTION.MODE'] // Enable sandbox mode
+ $config['SECURITY.SENDER'], // SecuritySender
+ $config['USER.LOGIN'], // UserLogin
+ $config['USER.PWD'], // UserPassword
+ $config['TRANSACTION.CHANNEL'], // TransactionChannel credit card without 3d secure
+ $config['TRANSACTION.MODE'] // Enable sandbox mode
);
$frontend = $this->getFrontend();
@@ -304,6 +521,30 @@ public function getHeidelpayUrl($quote)
);
}
+ /**
+ * @param Response $response
+ * @param $paymentMethod
+ * @param $paymentType
+ * @param string $source
+ * @param array $data
+ */
+ public function saveHeidelpayTransaction(Response $response, $paymentMethod, $paymentType, $source, array $data)
+ {
+ $transaction = $this->transactionFactory->create();
+ $transaction->setPaymentMethod($paymentMethod)
+ ->setPaymentType($paymentType)
+ ->setTransactionId($response->getIdentification()->getTransactionId())
+ ->setUniqueId($response->getIdentification()->getUniqueId())
+ ->setShortId($response->getIdentification()->getShortId())
+ ->setStatusCode($response->getProcessing()->getStatusCode())
+ ->setResult($response->getProcessing()->getResult())
+ ->setReturnMessage($response->getProcessing()->getReturn())
+ ->setReturnCode($response->getProcessing()->getReturnCode())
+ ->setJsonResponse(json_encode($data))
+ ->setSource($source)
+ ->save();
+ }
+
/**
* Returns the heidelpay PhpApi Paymentmethod Instance.
*
@@ -430,7 +671,7 @@ public function cancelledTransactionProcessing(&$order, $message = null)
if ($order->canCancel()) {
$order->cancel()
->setState(Order::STATE_CANCELED)
- ->addStatusHistoryComment($message, Order::STATE_CANCELED)
+ ->addStatusHistoryComment('heidelpay - ' . $message, Order::STATE_CANCELED)
->setIsCustomerNotified(false);
}
}
@@ -448,7 +689,7 @@ public function pendingTransactionProcessing($data, &$order, $message = null)
$order->getPayment()->addTransaction(Transaction::TYPE_AUTH, null, true);
$order->setState(Order::STATE_PENDING_PAYMENT)
- ->addStatusHistoryComment($message, Order::STATE_PENDING_PAYMENT)
+ ->addStatusHistoryComment('heidelpay - ' . $message, Order::STATE_PENDING_PAYMENT)
->setIsCustomerNotified(true);
}
@@ -471,7 +712,7 @@ public function processingTransactionProcessing($data, &$order)
&& $this->_paymentHelper->isMatchingCurrency($order, $data)
) {
$order->setState(Order::STATE_PROCESSING)
- ->addStatusHistoryComment($message, Order::STATE_PROCESSING)
+ ->addStatusHistoryComment('heidelpay - ' . $message, Order::STATE_PROCESSING)
->setIsCustomerNotified(true);
} else {
// in case rc is ack and amount is to low/heigh or curreny missmatch
@@ -481,24 +722,46 @@ public function processingTransactionProcessing($data, &$order)
);
$order->setState(Order::STATE_PAYMENT_REVIEW)
- ->addStatusHistoryComment($message, Order::STATE_PAYMENT_REVIEW)
+ ->addStatusHistoryComment('heidelpay - ' . $message, Order::STATE_PAYMENT_REVIEW)
->setIsCustomerNotified(true);
}
- // if the order can be invoiced, create one and save it into a transaction.
- if ($order->canInvoice()) {
- $invoice = $order->prepareInvoice();
- $invoice->setRequestedCaptureCase(Invoice::CAPTURE_ONLINE);
- $invoice->register();
- $invoice->setIsPaid(true);
- $invoice->pay();
+ // if the order can be invoiced and is no Pre-Authorization,
+ // create one and save it into a transaction.
+ if ($this->salesHelper->canSendNewInvoiceEmail($order->getStore()->getId())) {
+ if ($order->canInvoice() && !$this->_paymentHelper->isPreAuthorization($data)) {
+ $invoice = $order->prepareInvoice();
- $this->_paymentHelper->saveTransaction($invoice);
+ $invoice->setRequestedCaptureCase(Invoice::CAPTURE_ONLINE);
+ $invoice->setTransactionId($data['IDENTIFICATION_UNIQUEID']);
+ $invoice->register()->pay();
+
+ $this->_paymentHelper->saveTransaction($invoice);
+ }
}
$order->getPayment()->addTransaction(Transaction::TYPE_CAPTURE, null, true);
}
+ /**
+ * Returns the booking mode.
+ * This is needed for payment methods with multiple booking modes like 'debit' or 'preauthorization' and 'capture'.
+ *
+ * @param int $storeId
+ *
+ * @return string|null
+ */
+ public function getBookingMode($storeId = null)
+ {
+ $store = $storeId === null ? $this->getStore() : $storeId;
+
+ return $this->_scopeConfig->getValue(
+ 'payment/' . $this->getCode() . '/bookingmode',
+ \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
+ $store
+ );
+ }
+
/**
* Additional payment information
*
diff --git a/PaymentMethods/HeidelpayCreditCardPaymentMethod.php b/PaymentMethods/HeidelpayCreditCardPaymentMethod.php
index 0dae9901d6c..bd6813f95da 100644
--- a/PaymentMethods/HeidelpayCreditCardPaymentMethod.php
+++ b/PaymentMethods/HeidelpayCreditCardPaymentMethod.php
@@ -2,7 +2,9 @@
namespace Heidelpay\Gateway\PaymentMethods;
+use Heidelpay\Gateway\Model\Config\Source\BookingMode;
use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory;
+use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
/**
* Heidelpay credit card payment method
@@ -44,6 +46,26 @@ class HeidelpayCreditCardPaymentMethod extends HeidelpayAbstractPaymentMethod
*/
protected $_canAuthorize = true;
+ /**
+ * @var boolean
+ */
+ protected $_canCapture = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canCapturePartial = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canRefund = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canRefundInvoicePartial = true;
+
/**
* HeidelpayCreditCardPaymentMethod constructor.
*
@@ -61,7 +83,10 @@ class HeidelpayCreditCardPaymentMethod extends HeidelpayAbstractPaymentMethod
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param \Magento\Framework\Module\ResourceInterface $moduleResource
* @param \Heidelpay\Gateway\Helper\Payment $paymentHelper
+ * @param \Magento\Sales\Helper\Data $salesHelper
* @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory
+ * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory
+ * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory
* @param \Heidelpay\PhpApi\PaymentMethods\CreditCardPaymentMethod $creditCardPaymentMethod
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
@@ -82,7 +107,10 @@ public function __construct(
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
\Magento\Framework\Module\ResourceInterface $moduleResource,
\Heidelpay\Gateway\Helper\Payment $paymentHelper,
+ \Magento\Sales\Helper\Data $salesHelper,
PaymentInformationCollectionFactory $paymentInformationCollectionFactory,
+ \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory,
+ HeidelpayTransactionCollectionFactory $transactionCollectionFactory,
\Heidelpay\PhpApi\PaymentMethods\CreditCardPaymentMethod $creditCardPaymentMethod,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
@@ -103,7 +131,10 @@ public function __construct(
$productMetadata,
$moduleResource,
$paymentHelper,
+ $salesHelper,
$paymentInformationCollectionFactory,
+ $transactionFactory,
+ $transactionCollectionFactory,
$resource,
$resourceCollection,
$data
@@ -145,8 +176,15 @@ public function getHeidelpayUrl($quote)
$this->getStore()
);
- // send the debit request
- $this->_heidelpayPaymentMethod->debit($paymentFrameOrigin, $preventAsyncRedirect, $cssPath);
+ // make an authorize request, if set...
+ if ($this->getBookingMode() === BookingMode::AUTHORIZATION) {
+ $this->_heidelpayPaymentMethod->authorize($paymentFrameOrigin, $preventAsyncRedirect, $cssPath);
+ }
+
+ // ... else if no booking mode is set or bookingmode is set to 'debit', make a debit request.
+ if ($this->getBookingMode() === null || $this->getBookingMode() === BookingMode::DEBIT) {
+ $this->_heidelpayPaymentMethod->debit($paymentFrameOrigin, $preventAsyncRedirect, $cssPath);
+ }
return $this->_heidelpayPaymentMethod->getResponse();
}
diff --git a/PaymentMethods/HeidelpayDebitCardPaymentMethod.php b/PaymentMethods/HeidelpayDebitCardPaymentMethod.php
index 9b41137a798..20a4b937057 100644
--- a/PaymentMethods/HeidelpayDebitCardPaymentMethod.php
+++ b/PaymentMethods/HeidelpayDebitCardPaymentMethod.php
@@ -2,7 +2,9 @@
namespace Heidelpay\Gateway\PaymentMethods;
+use Heidelpay\Gateway\Model\Config\Source\BookingMode;
use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory;
+use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
/**
* Heidelpay dibit card payment method
@@ -44,6 +46,26 @@ class HeidelpayDebitCardPaymentMethod extends HeidelpayAbstractPaymentMethod
*/
protected $_canAuthorize = true;
+ /**
+ * @var boolean
+ */
+ protected $_canCapture = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canCapturePartial = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canRefund = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canRefundInvoicePartial = true;
+
/**
* HeidelpayDebitCardPaymentMethod constructor.
*
@@ -61,7 +83,10 @@ class HeidelpayDebitCardPaymentMethod extends HeidelpayAbstractPaymentMethod
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param \Magento\Framework\Module\ResourceInterface $moduleResource
* @param \Heidelpay\Gateway\Helper\Payment $paymentHelper
+ * @param \Magento\Sales\Helper\Data $salesHelper
* @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory
+ * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory
+ * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory
* @param \Heidelpay\PhpApi\PaymentMethods\DebitCardPaymentMethod $debitCardPaymentMethod
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
@@ -82,7 +107,10 @@ public function __construct(
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
\Magento\Framework\Module\ResourceInterface $moduleResource,
\Heidelpay\Gateway\Helper\Payment $paymentHelper,
+ \Magento\Sales\Helper\Data $salesHelper,
PaymentInformationCollectionFactory $paymentInformationCollectionFactory,
+ \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory,
+ HeidelpayTransactionCollectionFactory $transactionCollectionFactory,
\Heidelpay\PhpApi\PaymentMethods\DebitCardPaymentMethod $debitCardPaymentMethod,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
@@ -103,7 +131,10 @@ public function __construct(
$productMetadata,
$moduleResource,
$paymentHelper,
+ $salesHelper,
$paymentInformationCollectionFactory,
+ $transactionFactory,
+ $transactionCollectionFactory,
$resource,
$resourceCollection,
$data
@@ -145,8 +176,15 @@ public function getHeidelpayUrl($quote)
$this->getStore()
);
- // send the debit request
- $this->_heidelpayPaymentMethod->debit($paymentFrameOrigin, $preventAsyncRedirect, $cssPath);
+ // make an authorize request, if set...
+ if ($this->getBookingMode() === BookingMode::AUTHORIZATION) {
+ $this->_heidelpayPaymentMethod->authorize($paymentFrameOrigin, $preventAsyncRedirect, $cssPath);
+ }
+
+ // ... else if no booking mode is set or bookingmode is set to 'debit', make a debit request.
+ if ($this->getBookingMode() === null || $this->getBookingMode() === BookingMode::DEBIT) {
+ $this->_heidelpayPaymentMethod->debit($paymentFrameOrigin, $preventAsyncRedirect, $cssPath);
+ }
return $this->_heidelpayPaymentMethod->getResponse();
}
diff --git a/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php b/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php
index 4391e9f62da..59b39896329 100644
--- a/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php
+++ b/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php
@@ -3,6 +3,7 @@
namespace Heidelpay\Gateway\PaymentMethods;
use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory;
+use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
/**
* Heidelpay Direct Debit
@@ -27,6 +28,16 @@ class HeidelpayDirectDebitPaymentMethod extends HeidelpayAbstractPaymentMethod
/** @var bool */
protected $_canAuthorize = true;
+ /**
+ * @var boolean
+ */
+ protected $_canRefund = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canRefundInvoicePartial = true;
+
/**
* HeidelpayDirectDebitPaymentMethod constructor.
*
@@ -44,7 +55,10 @@ class HeidelpayDirectDebitPaymentMethod extends HeidelpayAbstractPaymentMethod
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param \Magento\Framework\Module\ResourceInterface $moduleResource
* @param \Heidelpay\Gateway\Helper\Payment $paymentHelper
+ * @param \Magento\Sales\Helper\Data $salesHelper
* @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory
+ * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory
+ * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory
* @param \Heidelpay\PhpApi\PaymentMethods\DirectDebitPaymentMethod $directDebitPaymentMethod
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
@@ -65,7 +79,10 @@ public function __construct(
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
\Magento\Framework\Module\ResourceInterface $moduleResource,
\Heidelpay\Gateway\Helper\Payment $paymentHelper,
+ \Magento\Sales\Helper\Data $salesHelper,
PaymentInformationCollectionFactory $paymentInformationCollectionFactory,
+ \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory,
+ HeidelpayTransactionCollectionFactory $transactionCollectionFactory,
\Heidelpay\PhpApi\PaymentMethods\DirectDebitPaymentMethod $directDebitPaymentMethod,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
@@ -86,7 +103,10 @@ public function __construct(
$productMetadata,
$moduleResource,
$paymentHelper,
+ $salesHelper,
$paymentInformationCollectionFactory,
+ $transactionFactory,
+ $transactionCollectionFactory,
$resource,
$resourceCollection,
$data
diff --git a/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php b/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php
index f905b47dfec..f1c0fb67e3b 100644
--- a/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php
+++ b/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php
@@ -3,6 +3,7 @@
namespace Heidelpay\Gateway\PaymentMethods;
use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory;
+use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
/**
* Heidelpay Direct Debit
@@ -27,6 +28,16 @@ class HeidelpayDirectDebitSecuredPaymentMethod extends HeidelpayAbstractPaymentM
/** @var bool */
protected $_canAuthorize = true;
+ /**
+ * @var boolean
+ */
+ protected $_canRefund = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canRefundInvoicePartial = true;
+
/**
* HeidelpayDirectDebitSecurePaymentMethod constructor.
*
@@ -44,7 +55,10 @@ class HeidelpayDirectDebitSecuredPaymentMethod extends HeidelpayAbstractPaymentM
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param \Magento\Framework\Module\ResourceInterface $moduleResource
* @param \Heidelpay\Gateway\Helper\Payment $paymentHelper
+ * @param \Magento\Sales\Helper\Data $salesHelper
* @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory
+ * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory
+ * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory
* @param \Heidelpay\PhpApi\PaymentMethods\DirectDebitB2CSecuredPaymentMethod $directDebitB2CSecuredPaymentMethod
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
@@ -65,7 +79,10 @@ public function __construct(
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
\Magento\Framework\Module\ResourceInterface $moduleResource,
\Heidelpay\Gateway\Helper\Payment $paymentHelper,
+ \Magento\Sales\Helper\Data $salesHelper,
PaymentInformationCollectionFactory $paymentInformationCollectionFactory,
+ \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory,
+ HeidelpayTransactionCollectionFactory $transactionCollectionFactory,
\Heidelpay\PhpApi\PaymentMethods\DirectDebitB2CSecuredPaymentMethod $directDebitB2CSecuredPaymentMethod,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
@@ -86,7 +103,10 @@ public function __construct(
$productMetadata,
$moduleResource,
$paymentHelper,
+ $salesHelper,
$paymentInformationCollectionFactory,
+ $transactionFactory,
+ $transactionCollectionFactory,
$resource,
$resourceCollection,
$data
diff --git a/PaymentMethods/HeidelpayGiropayPaymentMethod.php b/PaymentMethods/HeidelpayGiropayPaymentMethod.php
index 243c2b946e8..db35f737c0f 100644
--- a/PaymentMethods/HeidelpayGiropayPaymentMethod.php
+++ b/PaymentMethods/HeidelpayGiropayPaymentMethod.php
@@ -3,6 +3,7 @@
namespace Heidelpay\Gateway\PaymentMethods;
use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory;
+use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
/**
* heidelpay giropay Payment Method
@@ -26,6 +27,16 @@ class HeidelpayGiropayPaymentMethod extends HeidelpayAbstractPaymentMethod
/** @var bool */
protected $_canAuthorize = true;
+ /**
+ * @var boolean
+ */
+ protected $_canRefund = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canRefundInvoicePartial = true;
+
/**
* HeidelpayGiropayPaymentMethod constructor.
*
@@ -43,7 +54,10 @@ class HeidelpayGiropayPaymentMethod extends HeidelpayAbstractPaymentMethod
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param \Magento\Framework\Module\ResourceInterface $moduleResource
* @param \Heidelpay\Gateway\Helper\Payment $paymentHelper
+ * @param \Magento\Sales\Helper\Data $salesHelper
* @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory
+ * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory
+ * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory
* @param \Heidelpay\PhpApi\PaymentMethods\GiropayPaymentMethod $giropayPaymentMethod
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
@@ -64,7 +78,10 @@ public function __construct(
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
\Magento\Framework\Module\ResourceInterface $moduleResource,
\Heidelpay\Gateway\Helper\Payment $paymentHelper,
+ \Magento\Sales\Helper\Data $salesHelper,
PaymentInformationCollectionFactory $paymentInformationCollectionFactory,
+ \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory,
+ HeidelpayTransactionCollectionFactory $transactionCollectionFactory,
\Heidelpay\PhpApi\PaymentMethods\GiropayPaymentMethod $giropayPaymentMethod,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
@@ -85,7 +102,10 @@ public function __construct(
$productMetadata,
$moduleResource,
$paymentHelper,
+ $salesHelper,
$paymentInformationCollectionFactory,
+ $transactionFactory,
+ $transactionCollectionFactory,
$resource,
$resourceCollection,
$data
diff --git a/PaymentMethods/HeidelpayInvoicePaymentMethod.php b/PaymentMethods/HeidelpayInvoicePaymentMethod.php
new file mode 100644
index 00000000000..74304e30ad2
--- /dev/null
+++ b/PaymentMethods/HeidelpayInvoicePaymentMethod.php
@@ -0,0 +1,206 @@
+_heidelpayPaymentMethod = $invoicePaymentMethod;
+ }
+
+ /**
+ * Initial Request to heidelpay payment server to get the form / iframe url
+ * {@inheritDoc}
+ * @see \Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod::getHeidelpayUrl()
+ */
+ public function getHeidelpayUrl($quote)
+ {
+ // set initial data for the request
+ parent::getHeidelpayUrl($quote);
+
+ // send the authorize request
+ $this->_heidelpayPaymentMethod->authorize();
+
+ return $this->_heidelpayPaymentMethod->getResponse();
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function additionalPaymentInformation($response)
+ {
+ return __(
+ 'Please transfer the amount of %1 %2 '
+ . 'to the following account after your order has arrived:
'
+ . 'Holder: %3 IBAN: %4 BIC: %5
'
+ . 'Please use only this identification number as the descriptor : %6',
+ $this->_paymentHelper->format($response['PRESENTATION_AMOUNT']),
+ $response['PRESENTATION_CURRENCY'],
+ $response['CONNECTOR_ACCOUNT_HOLDER'],
+ $response['CONNECTOR_ACCOUNT_IBAN'],
+ $response['CONNECTOR_ACCOUNT_BIC'],
+ $response['IDENTIFICATION_SHORTID']
+ );
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function pendingTransactionProcessing($data, &$order, $message = null)
+ {
+ $order->getPayment()->setTransactionId($data['IDENTIFICATION_UNIQUEID']);
+ $order->getPayment()->setIsTransactionClosed(false);
+ $order->getPayment()->addTransaction(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_AUTH, null, true);
+
+ $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING)
+ ->addStatusHistoryComment($message, \Magento\Sales\Model\Order::STATE_PROCESSING)
+ ->setIsCustomerNotified(true);
+
+ // payment is pending at the beginning, so we set the total paid sum to 0.
+ $order->setTotalPaid(0.00)->setBaseTotalPaid(0.00);
+
+ // if the order can be invoiced, create one and save it into a transaction.
+ if ($this->salesHelper->canSendNewInvoiceEmail($order->getStore()->getId())) {
+ if ($order->canInvoice()) {
+ $invoice = $order->prepareInvoice();
+ $invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_ONLINE)
+ ->setTransactionId($data['IDENTIFICATION_UNIQUEID'])
+ ->setIsPaid(false)
+ ->register();
+
+ $this->_paymentHelper->saveTransaction($invoice);
+ }
+ }
+ }
+}
diff --git a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php
index 706a12b77d8..da4d9612519 100644
--- a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php
+++ b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php
@@ -3,6 +3,7 @@
namespace Heidelpay\Gateway\PaymentMethods;
use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory;
+use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
/**
* Heidelpay prepayment payment method
@@ -50,6 +51,16 @@ class HeidelpayInvoiceSecuredPaymentMethod extends HeidelpayAbstractPaymentMetho
*/
protected $_canAuthorize = true;
+ /**
+ * @var boolean
+ */
+ protected $_canRefund = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canRefundInvoicePartial = true;
+
/**
* HeidelpayPrepaymentPaymentMethod constructor.
*
@@ -67,7 +78,10 @@ class HeidelpayInvoiceSecuredPaymentMethod extends HeidelpayAbstractPaymentMetho
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param \Magento\Framework\Module\ResourceInterface $moduleResource
* @param \Heidelpay\Gateway\Helper\Payment $paymentHelper
+ * @param \Magento\Sales\Helper\Data $salesHelper
* @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory
+ * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory
+ * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory
* @param \Heidelpay\PhpApi\PaymentMethods\InvoiceB2CSecuredPaymentMethod $invoiceB2CSecuredPaymentMethod
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
@@ -88,7 +102,10 @@ public function __construct(
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
\Magento\Framework\Module\ResourceInterface $moduleResource,
\Heidelpay\Gateway\Helper\Payment $paymentHelper,
+ \Magento\Sales\Helper\Data $salesHelper,
PaymentInformationCollectionFactory $paymentInformationCollectionFactory,
+ \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory,
+ HeidelpayTransactionCollectionFactory $transactionCollectionFactory,
\Heidelpay\PhpApi\PaymentMethods\InvoiceB2CSecuredPaymentMethod $invoiceB2CSecuredPaymentMethod,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
@@ -109,7 +126,10 @@ public function __construct(
$productMetadata,
$moduleResource,
$paymentHelper,
+ $salesHelper,
$paymentInformationCollectionFactory,
+ $transactionFactory,
+ $transactionCollectionFactory,
$resource,
$resourceCollection,
$data
@@ -209,16 +229,19 @@ public function pendingTransactionProcessing($data, &$order, $message = null)
->setIsCustomerNotified(true);
// payment is pending at the beginning, so we set the total paid sum to 0.
- $order->setTotalPaid(0.00);
+ $order->setTotalPaid(0.00)->setBaseTotalPaid(0.00);
// if the order can be invoiced, create one and save it into a transaction.
- if ($order->canInvoice()) {
- $invoice = $order->prepareInvoice();
- $invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_ONLINE)
- ->setIsPaid(false)
- ->register();
-
- $this->_paymentHelper->saveTransaction($invoice);
+ if ($this->salesHelper->canSendNewInvoiceEmail($order->getStore()->getId())) {
+ if ($order->canInvoice()) {
+ $invoice = $order->prepareInvoice();
+ $invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_ONLINE)
+ ->setTransactionId($data['IDENTIFICATION_UNIQUEID'])
+ ->setIsPaid(false)
+ ->register();
+
+ $this->_paymentHelper->saveTransaction($invoice);
+ }
}
}
}
diff --git a/PaymentMethods/HeidelpayPayPalPaymentMethod.php b/PaymentMethods/HeidelpayPayPalPaymentMethod.php
index 3443ac82fa8..d9e4b829693 100644
--- a/PaymentMethods/HeidelpayPayPalPaymentMethod.php
+++ b/PaymentMethods/HeidelpayPayPalPaymentMethod.php
@@ -2,7 +2,9 @@
namespace Heidelpay\Gateway\PaymentMethods;
+use Heidelpay\Gateway\Model\Config\Source\BookingMode;
use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory;
+use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
/**
* heidelpay PayPal payment method
@@ -44,6 +46,26 @@ class HeidelpayPayPalPaymentMethod extends HeidelpayAbstractPaymentMethod
*/
protected $_canAuthorize = true;
+ /**
+ * @var boolean
+ */
+ protected $_canCapture = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canCapturePartial = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canRefund = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canRefundInvoicePartial = true;
+
/**
* HeidelpayPayPalPaymentMethod constructor.
*
@@ -61,7 +83,10 @@ class HeidelpayPayPalPaymentMethod extends HeidelpayAbstractPaymentMethod
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param \Magento\Framework\Module\ResourceInterface $moduleResource
* @param \Heidelpay\Gateway\Helper\Payment $paymentHelper
+ * @param \Magento\Sales\Helper\Data $salesHelper
* @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory
+ * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory
+ * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory
* @param \Heidelpay\PhpApi\PaymentMethods\PayPalPaymentMethod $payPalPaymentMethod
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
@@ -82,7 +107,10 @@ public function __construct(
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
\Magento\Framework\Module\ResourceInterface $moduleResource,
\Heidelpay\Gateway\Helper\Payment $paymentHelper,
+ \Magento\Sales\Helper\Data $salesHelper,
PaymentInformationCollectionFactory $paymentInformationCollectionFactory,
+ \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory,
+ HeidelpayTransactionCollectionFactory $transactionCollectionFactory,
\Heidelpay\PhpApi\PaymentMethods\PayPalPaymentMethod $payPalPaymentMethod,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
@@ -103,7 +131,10 @@ public function __construct(
$productMetadata,
$moduleResource,
$paymentHelper,
+ $salesHelper,
$paymentInformationCollectionFactory,
+ $transactionFactory,
+ $transactionCollectionFactory,
$resource,
$resourceCollection,
$data
@@ -122,8 +153,15 @@ public function getHeidelpayUrl($quote)
// set initial data for the request
parent::getHeidelpayUrl($quote);
- // send the debit request
- $this->_heidelpayPaymentMethod->debit();
+ // make an authorize request, if set...
+ if ($this->getBookingMode() === BookingMode::AUTHORIZATION) {
+ $this->_heidelpayPaymentMethod->authorize();
+ }
+
+ // ... else if no booking mode is set or bookingmode is set to 'debit', make a debit request.
+ if ($this->getBookingMode() === null || $this->getBookingMode() === BookingMode::DEBIT) {
+ $this->_heidelpayPaymentMethod->debit();
+ }
return $this->_heidelpayPaymentMethod->getResponse();
}
diff --git a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php
index 695ead046de..218d7bc11f1 100644
--- a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php
+++ b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php
@@ -3,6 +3,7 @@
namespace Heidelpay\Gateway\PaymentMethods;
use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory;
+use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
/**
* Heidelpay prepayment payment method
@@ -44,6 +45,16 @@ class HeidelpayPrepaymentPaymentMethod extends HeidelpayAbstractPaymentMethod
*/
protected $_canAuthorize = true;
+ /**
+ * @var boolean
+ */
+ protected $_canRefund = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canRefundInvoicePartial = true;
+
/**
* HeidelpayPrepaymentPaymentMethod constructor.
*
@@ -61,7 +72,10 @@ class HeidelpayPrepaymentPaymentMethod extends HeidelpayAbstractPaymentMethod
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param \Magento\Framework\Module\ResourceInterface $moduleResource
* @param \Heidelpay\Gateway\Helper\Payment $paymentHelper
+ * @param \Magento\Sales\Helper\Data $salesHelper
* @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory
+ * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory
+ * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory
* @param \Heidelpay\PhpApi\PaymentMethods\PrepaymentPaymentMethod $prepaymentPaymentMethod
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
@@ -82,7 +96,10 @@ public function __construct(
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
\Magento\Framework\Module\ResourceInterface $moduleResource,
\Heidelpay\Gateway\Helper\Payment $paymentHelper,
+ \Magento\Sales\Helper\Data $salesHelper,
PaymentInformationCollectionFactory $paymentInformationCollectionFactory,
+ \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory,
+ HeidelpayTransactionCollectionFactory $transactionCollectionFactory,
\Heidelpay\PhpApi\PaymentMethods\PrepaymentPaymentMethod $prepaymentPaymentMethod,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
@@ -103,7 +120,10 @@ public function __construct(
$productMetadata,
$moduleResource,
$paymentHelper,
+ $salesHelper,
$paymentInformationCollectionFactory,
+ $transactionFactory,
+ $transactionCollectionFactory,
$resource,
$resourceCollection,
$data
@@ -162,13 +182,16 @@ public function pendingTransactionProcessing($data, &$order, $message = null)
$order->setTotalPaid(0.00);
// if the order can be invoiced, create one and save it into a transaction.
- if ($order->canInvoice()) {
- $invoice = $order->prepareInvoice();
- $invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_ONLINE)
- ->setIsPaid(false)
- ->register();
-
- $this->_paymentHelper->saveTransaction($invoice);
+ if ($this->salesHelper->canSendNewInvoiceEmail($order->getStore()->getId())) {
+ if ($order->canInvoice()) {
+ $invoice = $order->prepareInvoice();
+ $invoice->setRequestedCaptureCase(\Magento\Sales\Model\Order\Invoice::CAPTURE_ONLINE)
+ ->setTransactionId($data['IDENTIFICATION_UNIQUEID'])
+ ->setIsPaid(false)
+ ->register();
+
+ $this->_paymentHelper->saveTransaction($invoice);
+ }
}
}
}
diff --git a/PaymentMethods/HeidelpaySofortPaymentMethod.php b/PaymentMethods/HeidelpaySofortPaymentMethod.php
index 306de2c3e2f..1a641742c12 100644
--- a/PaymentMethods/HeidelpaySofortPaymentMethod.php
+++ b/PaymentMethods/HeidelpaySofortPaymentMethod.php
@@ -3,6 +3,7 @@
namespace Heidelpay\Gateway\PaymentMethods;
use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory;
+use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory;
/**
* heidelpay sofort payment method
@@ -44,6 +45,16 @@ class HeidelpaySofortPaymentMethod extends HeidelpayAbstractPaymentMethod
*/
protected $_canAuthorize = true;
+ /**
+ * @var boolean
+ */
+ protected $_canRefund = true;
+
+ /**
+ * @var boolean
+ */
+ protected $_canRefundInvoicePartial = true;
+
/**
* HeidelpaySofortPaymentMethod constructor.
*
@@ -61,7 +72,10 @@ class HeidelpaySofortPaymentMethod extends HeidelpayAbstractPaymentMethod
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param \Magento\Framework\Module\ResourceInterface $moduleResource
* @param \Heidelpay\Gateway\Helper\Payment $paymentHelper
+ * @param \Magento\Sales\Helper\Data $salesHelper
* @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory
+ * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory
+ * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory
* @param \Heidelpay\PhpApi\PaymentMethods\SofortPaymentMethod $sofortPaymentMethod
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
@@ -82,7 +96,10 @@ public function __construct(
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
\Magento\Framework\Module\ResourceInterface $moduleResource,
\Heidelpay\Gateway\Helper\Payment $paymentHelper,
+ \Magento\Sales\Helper\Data $salesHelper,
PaymentInformationCollectionFactory $paymentInformationCollectionFactory,
+ \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory,
+ HeidelpayTransactionCollectionFactory $transactionCollectionFactory,
\Heidelpay\PhpApi\PaymentMethods\SofortPaymentMethod $sofortPaymentMethod,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
@@ -103,7 +120,10 @@ public function __construct(
$productMetadata,
$moduleResource,
$paymentHelper,
+ $salesHelper,
$paymentInformationCollectionFactory,
+ $transactionFactory,
+ $transactionCollectionFactory,
$resource,
$resourceCollection,
$data
diff --git a/README.md b/README.md
index 98cc09cb9dc..76801d7b36e 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
[![Latest Version on Packagist](https://img.shields.io/packagist/v/heidelpay/magento2.svg?style=flat-square)](https://packagist.org/packages/heidelpay/magento2)
[![Codacy Badge](https://api.codacy.com/project/badge/grade/fb5b516ad21f44a591a58761a8c3ef42)](https://www.codacy.com/app/heidelpay/magento2/dashboard)
+[![PHP 5.6](https://img.shields.io/badge/php-5.6-blue.svg)](http://www.php.net)
+[![PHP 7.0](https://img.shields.io/badge/php-7.0-blue.svg)](http://www.php.net)
![Logo](https://dev.heidelpay.de/devHeidelpay_400_180.jpg)
@@ -15,6 +17,7 @@ Currently supported payment methods are:
* Sofortüberweisung
* PayPal
* Prepayment
+* Invoice
* Invoice (Secured) (B2C)
* giropay
@@ -38,11 +41,11 @@ All versions greater than 16.10.17 are based on the heidelpay php-api. (https://
### Install the heidelpay Magento 2 composer package
-```composer require "heidelpay/magento2:17.5.9"```
+```composer require "heidelpay/magento2:17.6.16"```
### Enable the extension in Magento 2
-```php -f bin/magento module:enable --clear-static-content Heidelpay_Gateway```
+```php -f bin/magento module:enable Heidelpay_Gateway --clear-static-content```
### Setup the extension and refresh cache
diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php
index 99d57ed3dd4..ac32d0c3251 100644
--- a/Setup/InstallSchema.php
+++ b/Setup/InstallSchema.php
@@ -29,7 +29,7 @@ public function install(SchemaSetupInterface $installer, ModuleContextInterface
// create transactions table
$tablerealname = 'heidelpay_transaction';
$tablename = $installer->getTable($tablerealname);
- if ($installer->getConnection()->isTableExists($tablename) != true) {
+ if (!$installer->getConnection()->isTableExists($tablename)) {
$table = $installer->getConnection()->newTable($tablename)
->addColumn('id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, [
'unsigned' => true,
@@ -109,7 +109,7 @@ public function install(SchemaSetupInterface $installer, ModuleContextInterface
$tablerealname = 'heidelpay_payment_information';
$tablename = $installer->getTable($tablerealname);
- if ($installer->getConnection()->isTableExists($tablename) != true) {
+ if (!$installer->getConnection()->isTableExists($tablename)) {
$table = $installer->getConnection()->newTable($tablename)
->addColumn('id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, [
'unsigned' => true,
diff --git a/composer.json b/composer.json
index 5477e6d85fa..579fb94b517 100644
--- a/composer.json
+++ b/composer.json
@@ -12,7 +12,7 @@
"magento/module-payment" : "<100.2.0",
"magento/module-backend" : "<100.2.0",
"magento/framework" : "<100.2.0",
- "heidelpay/php-api" : "~17.4.13",
+ "heidelpay/php-api" : "~17.5.2",
"heidelpay/php-customer-messages": "~17.2.3"
},
"require-dev" : {
diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml
index 298951c2d96..44c1ce4988c 100644
--- a/etc/adminhtml/di.xml
+++ b/etc/adminhtml/di.xml
@@ -2,7 +2,4 @@
-
-
\ No newline at end of file
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index 1f906bf687e..86c72d28bc6 100644
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -17,7 +17,7 @@
payment/hgwmain/user_login
-
+
Magento\Config\Model\Config\Backend\Encryptedpayment/hgwmain/user_passwd
@@ -47,12 +47,12 @@
payment/hgwcc/channel
-
+ If 'Debit' is enabled, the card will be charged immediately. Otherwise the amount will just be authorised.
+
payment/hgwcc/sort_order
@@ -92,12 +92,12 @@
payment/hgwdc/channel
-
+ If 'Debit' is enabled, the card will be charged immediately. Otherwise the amount will just be authorised.
+
payment/hgwdc/sort_order
@@ -176,12 +176,12 @@
payment/hgwpal/channel
-
+ If 'Debit' is enabled, the Account will be charged immediately. Otherwise the amount will just be authorised.
+
payment/hgwpal/sort_order
@@ -374,6 +374,45 @@
Insert 0 to disable limit.
+
+
+
+
+ Magento\Config\Model\Config\Source\Yesno
+ payment/hgwiv/active
+
+
+
+ payment/hgwiv/title
+
+
+
+ payment/hgwiv/channel
+
+
+
+ payment/hgwiv/sort_order
+
+
+
+ Magento\Payment\Model\Config\Source\Allspecificcountries
+ payment/hgwiv/allowspecific
+
+
+
+ Magento\Directory\Model\Config\Source\Country
+ payment/hgwiv/specificcountry
+
+
+
+ payment/hgwiv/min_order_total
+
+
+
+ payment/hgwiv/max_order_total
+ Insert 0 to disable limit.
+
+
diff --git a/etc/config.xml b/etc/config.xml
index 9df26ef1b0d..c1ee18b0930 100644
--- a/etc/config.xml
+++ b/etc/config.xml
@@ -23,8 +23,9 @@
0authorize
-
+ 31HA07BC8142C5A171744F3D6D155865
+ debit000
@@ -33,8 +34,9 @@
0authorize
-
+ 31HA07BC8142C5A171744F3D6D155865
+ debit000
@@ -56,6 +58,7 @@
authorize31HA07BC8142C5A171749A60D979B6E4
+ debit000
@@ -83,6 +86,16 @@
0Heidelpay\Gateway\PaymentMethods\HeidelpayDirectDebitPaymentMethod
+
+ 0
+ authorize
+
+ 31HA07BC8142C5A171749A60D979B6E4
+ 0
+ 0
+ 0
+ Heidelpay\Gateway\PaymentMethods\HeidelpayInvoicePaymentMethod
+ 0authorize
diff --git a/etc/module.xml b/etc/module.xml
index e6e8e0e476e..14bbe53c324 100644
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv
index bffa3e0f751..5ca9f8a2fc4 100644
--- a/i18n/de_DE.csv
+++ b/i18n/de_DE.csv
@@ -3,20 +3,23 @@
"HGWCC","Kreditkarte"
"HGWDC","Debitkarte"
"HGWSUE","Sofortüberweisung"
-"HGWPAL","Paypal"
+"HGWPAL","PayPal"
"HGWPP","Vorkasse"
"HGWGP","giropay"
"HGWDD","Lastschrift"
"HGWDDS","Gesicherte Lastschrift (B2C)"
+"HGWIV","Rechnungskauf"
"HGWIVS","Gesicherter Rechnungskauf (B2C)"
"HGW_ABOUT_US","Die Heidelberger Payment GmbH, kurz: heidelpay, ist ein führendes, von der BaFin zugelassenes und beaufsichtigtes Zahlungsinstitut für Online-Paymentverfahren, welches das komplette Leistungsspektrum in Sachen elektronische Zahlungsabwicklung abdeckt: vom Processing der Transaktionen über die Vergabe der Akzeptanzstellenverträge bis hin zum Monitoring und Risk Management.
Mehr Informationen finden Sie auf www.heidelpay.de"
+"Security Sender","Sender-ID"
+"User Login","Login"
+"User Password","Kennwort"
"Sandbox Mode","Testsystem"
-"If this is enabled the heidelpay sandbox will be used. Otherwise the real payment system will be used.","Wenn diese Einstellung auf Ja steht, werden alle Transaktionen ans Testsysten gesenden. Ansonsten wird das Live System benutzt"
-"UserPassword","User Password"
+"If this is enabled the heidelpay sandbox will be used. Otherwise the real payment system will be used.","Wenn diese Einstellung auf Ja steht, werden alle Transaktionen ans Testsysten gesenden. Ansonsten wird das Live System benutzt"
"Enabled","Aktiviert"
-"Directbooking","Sofortbuchung"
+"Channel","Kanal-ID"
"Insert 0 to disable limit.","Tragen Sie 0 ein um das Limit zu deaktivieren."
"If this is enabled the card will be charged immediately. Otherwise the amount will just be authorised.","Wenn diese Einstellung auf Ja steht, wird die Karte sofort belastet. Ansonsten wird der Betrag nur reserviert."
"An unexpected error occurred. Please contact us to get further information.","Es ist ein Fehler aufgetreten. Bitte kontaktieren Sie uns für weitere Informationen."
@@ -79,18 +82,3 @@
"Heidelpay Error at sending Finalize Request. The Shipment was not created.","Heidelpay Fehler beim Senden des Finalize Requests. Der Versand wurde nicht erstellt."
"Shipping Notification has been sent to Heidelpay.","Versandbenachrichtigung wurde an Heidelpay gesendet."
-
-"HPError-100.100.101","Bitte überprüfen Sie Ihre Eingaben"
-"HPError-100.100.303","Die Karte ist abgelaufen"
-"HPError-100.100.500","Bitte überprüfen Sie Ihre Eingaben"
-"HPError-100.396.101","Abbruch durch Benutzer"
-"HPError-100.400.110","Bitte wählen Sie eine andere Zahlart"
-"HPError-800.100.151","Bitte wählen Sie eine andere Zahlart"
-"HPError-800.100.152","Bitte wählen Sie eine andere Zahlart"
-"HPError-800.100.153","Bitte überprüfen Sie Ihre Eingaben"
-"HPError-800.100.157","Bitte überprüfen Sie Ihre Eingaben"
-"HPError-800.100.159","Bitte wählen Sie eine andere Zahlart"
-"HPError-800.100.160","Bitte wählen Sie eine andere Zahlart"
-"HPError-800.100.168","Bitte wählen Sie eine andere Zahlart"
-"HPError-800.100.171","Bitte wählen Sie eine andere Zahlart"
-"HPError-800.300.101","Bitte wählen Sie eine andere Zahlart"
diff --git a/i18n/en_US.csv b/i18n/en_US.csv
index b58b58f813d..0b3e68a4fb0 100644
--- a/i18n/en_US.csv
+++ b/i18n/en_US.csv
@@ -3,16 +3,16 @@
"HGWCC","Credit Card"
"HGWDC","Debit Card"
"HGWSUE","Sofortüberweisung"
-"HGWPAL","Paypal"
+"HGWPAL","PayPal"
"HGWPP","Prepayment"
"HGWGP","giropay"
"HGWDD","Direct Debit"
"HGWDDS","Direct Debit Secured (B2C)"
+"HGWIV","Invoice"
"HGWIVS","Invoice Secured (B2C)"
"HGW_ABOUT_US","Heidelberger Payment GmbH, shortly: heidelpay, is a leading payment institution for online payment methods authorized and regulated by BaFin, which offers the full range of services for an electronic payment processing from one single source: from processing of transactions and providing of acceptance contracts to monitoring and risk management.
For more information please visit www.heidelpay.de"
-"UserPassword","User Password"
"If this is enabled the heidelpay sandbox will be used. Otherwise the real payment system will be used.","If this is enabled the heidelpay sandbox will be used. Otherwise the real payment system will be used."
"An unexpected error occurred. Please contact us to get further information.","An unexpected error occurred. Please contact us to get further information."
@@ -73,18 +73,3 @@
"Heidelpay Error at sending Finalize Request. The Shipment was not created.","Heidelpay Error at sending Finalize Request. The Shipment was not created."
"Shipping Notification has been sent to Heidelpay.","Shipping Notification has been sent to Heidelpay."
-
-"HPError-100.100.101","Please verify your payment data"
-"HPError-100.100.303","card expired"
-"HPError-100.100.500","Please verify your payment data"
-"HPError-100.396.101","Canceled by user"
-"HPError-100.400.110","Please choose another payment method"
-"HPError-800.100.151","Please choose another payment method"
-"HPError-800.100.152","Please choose another payment method"
-"HPError-800.100.153","Please verify your payment data"
-"HPError-800.100.157","Please verify your payment data"
-"HPError-800.100.159","Please choose another payment method"
-"HPError-800.100.160","Please choose another payment method"
-"HPError-800.100.168","Please choose another payment method"
-"HPError-800.100.171","Please choose another payment method"
-"HPError-800.300.101","Please choose another payment method"
\ No newline at end of file
diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml
index 92ab70e349f..6b460ebe489 100644
--- a/view/frontend/layout/checkout_index_index.xml
+++ b/view/frontend/layout/checkout_index_index.xml
@@ -50,6 +50,9 @@
false
+
+ false
+ false
diff --git a/view/frontend/templates/info/invoice.phtml b/view/frontend/templates/info/invoice.phtml
new file mode 100644
index 00000000000..3cd33a7aa77
--- /dev/null
+++ b/view/frontend/templates/info/invoice.phtml
@@ -0,0 +1,20 @@
+
+