From 43c77cbdf3b4bd4c6e64a2d053c53092ccf46ada Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Wed, 8 May 2019 09:35:31 +0200 Subject: [PATCH 001/114] [refactor](MAGE2-172) Process push notification only if the transaction is not saved already. --- CHANGELOG.md | 2 + Controller/Index/Push.php | 139 ++++++++++-------- .../HeidelpayAbstractPaymentMethod.php | 15 ++ 3 files changed, 92 insertions(+), 64 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab20cc6d274..64c0ec998ea 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ This project does not follow a versioning standard. Versions are crafted after t ### Fixed - An issue that prevented an invoice to be (partly) refunded twice. - An issue where different curencies can cause that order is created in base currency. +- A problem where a transaction was processed a second time vie push when using "sofort". That caused the paid amount to be displayed +incorrectly. ### Changed - Improved response handling if Post data is empty: Customer gets redirected to cart with an error message. Wording of diff --git a/Controller/Index/Push.php b/Controller/Index/Push.php index 875ac3d0a9c..75bfb8ba0cd 100755 --- a/Controller/Index/Push.php +++ b/Controller/Index/Push.php @@ -11,6 +11,7 @@ use Magento\Sales\Model\OrderRepository; use Magento\Sales\Model\Order; use Magento\Sales\Model\ResourceModel\Order\Collection; +use Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod; /** * heidelpay Push Controller @@ -132,78 +133,88 @@ public function execute() ); } - $this->_logger->debug('Push Response: ' . print_r($this->heidelpayPush->getResponse(), true)); + $pushResponse = $this->heidelpayPush->getResponse(); + $this->_logger->debug('Push Response: ' . print_r($pushResponse, true)); list($paymentMethod, $paymentType) = $this->_paymentHelper->splitPaymentCode( - $this->heidelpayPush->getResponse()->getPayment()->getCode() + $pushResponse->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 referenced order to receive the order information. - $criteria = $this->searchCriteriaBuilder - ->addFilter( - 'quote_id', - $this->heidelpayPush->getResponse()->getIdentification()->getTransactionId() - )->create(); - - /** @var Collection $orderList */ - $orderList = $this->orderRepository->getList($criteria); - - /** @var Order $order */ - $order = $orderList->getFirstItem(); - - $paidAmount = (float)$this->heidelpayPush->getResponse()->getPresentation()->getAmount(); - $dueLeft = $order->getTotalDue() - $paidAmount; - - $state = Order::STATE_PROCESSING; - $comment = 'heidelpay - Purchase Complete'; - - // if payment is not complete - if ($dueLeft > 0.00) { - $state = Order::STATE_PAYMENT_REVIEW; - $comment = 'heidelpay - Partly Paid (' - . $this->_paymentHelper->format( - $this->heidelpayPush->getResponse()->getPresentation()->getAmount() - ) - . ' ' . $this->heidelpayPush->getResponse()->getPresentation()->getCurrency() . ')'; - } + if ($this->_paymentHelper->isReceiptAble($paymentMethod, $paymentType) && $pushResponse->isSuccess()) { + // load the referenced order to receive the order information. + $criteria = $this->searchCriteriaBuilder + ->addFilter( + 'quote_id', + $pushResponse->getIdentification()->getTransactionId() + )->create(); + + /** @var Collection $orderList */ + $orderList = $this->orderRepository->getList($criteria); + + /** @var Order $order */ + $order = $orderList->getFirstItem(); + $payment = $order->getPayment(); + + /** @var HeidelpayAbstractPaymentMethod $methodInstance */ + $methodInstance = $payment->getMethodInstance(); + $transactionID = $pushResponse->getPaymentReferenceId(); + + /** @var bool $isNewTransaction Flag to identify new Transaction*/ + $isNewTransaction = $methodInstance->heidelpayTransactionExists($transactionID); + + // If Transaction already exists, push wont be processed. + if (!$isNewTransaction) { + $this->_logger->debug('heidelpay - Push Response: ' . $transactionID . ' already exists'); + return; + } - // set the invoice states to 'paid', if no due is left. - if ($dueLeft <= 0.00) { - /** @var \Magento\Sales\Model\Order\Invoice $invoice */ - foreach ($order->getInvoiceCollection() as $invoice) { - $invoice->setState(Invoice::STATE_PAID)->save(); - } - } + $paidAmount = (float)$pushResponse->getPresentation()->getAmount(); + $dueLeft = $order->getTotalDue() - $paidAmount; - $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(); + $state = Order::STATE_PROCESSING; + $comment = 'heidelpay - Purchase Complete'; + + // if payment is not complete + if ($dueLeft > 0.00) { + $state = Order::STATE_PAYMENT_REVIEW; + $comment = 'heidelpay - Partly Paid (' + . $this->_paymentHelper->format( + $pushResponse->getPresentation()->getAmount() + ) + . ' ' . $pushResponse->getPresentation()->getCurrency() . ')'; } + + // set the invoice states to 'paid', if no due is left. + if ($dueLeft <= 0.00) { + /** @var \Magento\Sales\Model\Order\Invoice $invoice */ + foreach ($order->getInvoiceCollection() as $invoice) { + $invoice->setState(Invoice::STATE_PAID)->save(); + } + } + + $order->setTotalPaid($order->getTotalPaid() + $paidAmount) + ->setBaseTotalPaid($order->getBaseTotalPaid() + $paidAmount) + ->setState($state) + ->addStatusHistoryComment($comment, $state); + + // create a heidelpay Transaction. + $methodInstance->saveHeidelpayTransaction( + $pushResponse, + $paymentMethod, + $paymentType, + 'PUSH', + [] + ); + + // create a child transaction. + $payment->setAmountPaid($paidAmount); + $payment->setTransactionId($transactionID) + ->setParentTransactionId($pushResponse->getIdentification()->getReferenceId()) + ->setIsTransactionClosed(true) + ->addTransaction(Transaction::TYPE_CAPTURE, null, true); + + $this->orderRepository->save($order); } } } diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 54337210b43..7ec1db6ccde 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -546,6 +546,7 @@ public function getHeidelpayUrl($quote) */ public function saveHeidelpayTransaction(Response $response, $paymentMethod, $paymentType, $source, array $data) { + $transaction = $this->transactionFactory->create(); $transaction->setPaymentMethod($paymentMethod) ->setPaymentType($paymentType) @@ -821,4 +822,18 @@ public function setAsync() $frontend['RESPONSE_URL'] // Response url from your application ); } + + /** + * @param $transactionID string + * @return bool + */ + public function heidelpayTransactionExists($transactionID) + { + $collection = $this->transactionCollectionFactory->create(); + + /** @var \Heidelpay\Gateway\Model\Transaction $transactionInfo */ + $heidelpayTransaction = $collection->loadByTransactionId($transactionID); + + return empty($heidelpayTransaction); + } } From 826b3a98084e8fcb428c1e5886a1b4abbf93442f Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Thu, 9 May 2019 11:08:27 +0200 Subject: [PATCH 002/114] (MAGE2-172) redefine condition to check for new transactions --- CHANGELOG.md | 4 ++++ PaymentMethods/HeidelpayAbstractPaymentMethod.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36ac3bdd12a..c22605487a5 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ ## Versioning This project does not follow a versioning standard. Versions are crafted after the dates; for example, the version 17.7.25 was released on July, 25th in 2017 +## X.X.X +### Fixed +- A problem where a transaction was processed a second time via push when using "sofort". That caused the paid amount to be displayed +incorrectly. ## 19.5.8 ### Fixed diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 7ec1db6ccde..ba3ff35616f 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -831,9 +831,9 @@ public function heidelpayTransactionExists($transactionID) { $collection = $this->transactionCollectionFactory->create(); - /** @var \Heidelpay\Gateway\Model\Transaction $transactionInfo */ + /** @var \Heidelpay\Gateway\Model\Transaction $heidelpayTransaction */ $heidelpayTransaction = $collection->loadByTransactionId($transactionID); - return empty($heidelpayTransaction); + return $heidelpayTransaction === null || $heidelpayTransaction->isEmpty(); } } From 6d4412ce247f6e28381a8a0910f95ea5a7c6b41a Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Fri, 10 May 2019 14:16:31 +0200 Subject: [PATCH 003/114] (MAGE2-157) Adjust basket calculation. Enable support for discounts including taxes --- Helper/BasketHelper.php | 30 ++++++++++++++++++++++-------- Wrapper/ItemWrapper.php | 10 ++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Helper/BasketHelper.php b/Helper/BasketHelper.php index 909ac5326a4..1a0d4b3b4a6 100755 --- a/Helper/BasketHelper.php +++ b/Helper/BasketHelper.php @@ -69,25 +69,37 @@ public function convertQuoteToBasket(Quote $quote) // initialize the basket request $basketRequest = new Request(); $basketReferenceId = $basketTotals->getBasketReferenceId(); - $basketRequest->getBasket() - ->setCurrencyCode($basketTotals->getCurrencyCode()) + $basket = $basketRequest->getBasket(); + $basket->setCurrencyCode($basketTotals->getCurrencyCode()) ->setAmountTotalNet($basketTotals->getSubtotalWithDiscountAndShipping()) ->setAmountTotalVat($basketTotals->getActualTaxAmount()) - ->setAmountTotalDiscount($basketTotals->getTotalDiscountAmount()) ->setBasketReferenceId($basketReferenceId); + $totalDiscountTax = 0; + /** @var string $discountTaxActive */ + $discountTaxActive = $quote->getStore()->getConfig('tax/calculation/discount_tax'); + /** @var \Magento\Quote\Model\Quote\Item $item */ foreach ($quote->getAllVisibleItems() as $item) { $basketItem = ObjectManager::getInstance()->create(BasketItem::class); /** @var ItemWrapper $itemTotals */ $itemTotals = ObjectManager::getInstance()->create(ItemWrapper::class, ['item' => $item]); + $itemDiscountTaxCompensation = $itemTotals->getDiscountTaxCompensationAmount(); + + if ($discountTaxActive == 0) { + /** In case discount amount contains no tax it is added/calculated here */ + $itemDiscountTaxCompensation = $itemTotals->calculateDiscountTaxAmount(); + $totalDiscountTax += $itemDiscountTaxCompensation; + } else { + $basket->addAmountTotalNet($itemDiscountTaxCompensation); + } $basketItem->setQuantity($item->getQty()) ->setVat($itemTotals->getTaxPercent()) ->setAmountPerUnit($itemTotals->getPrice()) ->setAmountNet($itemTotals->getRowTotal()) - ->setAmountVat($itemTotals->getTaxAmount()) + ->setAmountVat($itemTotals->getTaxAmount()+$itemDiscountTaxCompensation) ->setAmountGross($itemTotals->getRowTotalInclTax()) ->setTitle($item->getName()) @@ -95,7 +107,7 @@ public function convertQuoteToBasket(Quote $quote) ->setArticleId($item->getSku()) ->setBasketItemReferenceId($itemTotals->getReferenceId($basketReferenceId)); - $basketRequest->getBasket()->addBasketItem($basketItem); + $basket->addBasketItem($basketItem); } /** @var BasketItem $shippingPos */ @@ -110,7 +122,7 @@ public function convertQuoteToBasket(Quote $quote) ->setAmountNet($basketTotals->getShippingAmount()) ->setAmountGross($basketTotals->getShippingInclTax()) ->setBasketItemReferenceId($itemCount); - $basketRequest->getBasket()->addBasketItem($shippingPos); + $basket->addBasketItem($shippingPos); if ($basketTotals->getTotalDiscountAmount() > 0) { /** @var BasketItem $discountPosition */ @@ -120,11 +132,13 @@ public function convertQuoteToBasket(Quote $quote) ->setType('discount') ->setAmountPerUnit(0) ->setAmountNet(0) - ->setAmountDiscount($basketTotals->getTotalDiscountAmount()) + ->setAmountDiscount($basketTotals->getTotalDiscountAmount()+$totalDiscountTax) ->setBasketItemReferenceId($itemCount); - $basketRequest->getBasket()->addBasketItem($discountPosition); + $basket->addBasketItem($discountPosition); } + $basket->setAmountTotalDiscount($basketTotals->getTotalDiscountAmount()+$totalDiscountTax); + return $basketRequest; } diff --git a/Wrapper/ItemWrapper.php b/Wrapper/ItemWrapper.php index 8d098a0ca78..32c61509788 100755 --- a/Wrapper/ItemWrapper.php +++ b/Wrapper/ItemWrapper.php @@ -85,6 +85,11 @@ public function getRowTotal() return (int)floor(bcmul($this->item->getRowTotal(), 100, 10)); } + public function getDiscountTaxCompensationAmount () + { + return (int)floor(bcmul($this->item->getDiscountTaxCompensationAmount(), 100, 10)); + } + /** * @param string $prefix * @return string @@ -93,4 +98,9 @@ public function getReferenceId($prefix = '') { return $prefix . sprintf('%x%d', $this->item->getSku(), $this->item->getQty()); } + + public function calculateDiscountTaxAmount() + { + return bcmul($this->item->getDiscountAmount(), $this->item->getTaxPercent()); + } } From a7332be23a5d3e4d59c96215a6028fc3b962e3e3 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Tue, 14 May 2019 10:20:01 +0200 Subject: [PATCH 004/114] (MAGE2-157) simplify tax calculation for discount tax. --- Helper/BasketHelper.php | 19 ++++++++----------- Wrapper/BaseWrapper.php | 10 ++++++++++ Wrapper/ItemWrapper.php | 12 ++++++------ Wrapper/QuoteWrapper.php | 14 ++++++++++++-- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/Helper/BasketHelper.php b/Helper/BasketHelper.php index 1a0d4b3b4a6..39ce943ace4 100755 --- a/Helper/BasketHelper.php +++ b/Helper/BasketHelper.php @@ -75,9 +75,9 @@ public function convertQuoteToBasket(Quote $quote) ->setAmountTotalVat($basketTotals->getActualTaxAmount()) ->setBasketReferenceId($basketReferenceId); - $totalDiscountTax = 0; - /** @var string $discountTaxActive */ - $discountTaxActive = $quote->getStore()->getConfig('tax/calculation/discount_tax'); + /** @var string $discountContainsTax */ + $discountContainsTax = $quote->getStore()->getConfig('tax/calculation/discount_tax'); + $totalDiscountTaxCompensation = 0; /** @var \Magento\Quote\Model\Quote\Item $item */ foreach ($quote->getAllVisibleItems() as $item) { @@ -87,12 +87,9 @@ public function convertQuoteToBasket(Quote $quote) $itemTotals = ObjectManager::getInstance()->create(ItemWrapper::class, ['item' => $item]); $itemDiscountTaxCompensation = $itemTotals->getDiscountTaxCompensationAmount(); - if ($discountTaxActive == 0) { - /** In case discount amount contains no tax it is added/calculated here */ - $itemDiscountTaxCompensation = $itemTotals->calculateDiscountTaxAmount(); - $totalDiscountTax += $itemDiscountTaxCompensation; - } else { - $basket->addAmountTotalNet($itemDiscountTaxCompensation); + if ($discountContainsTax == '0') { + /** In case discount amount contains no tax it will be added */ + $totalDiscountTaxCompensation += $itemDiscountTaxCompensation; } $basketItem->setQuantity($item->getQty()) @@ -132,12 +129,12 @@ public function convertQuoteToBasket(Quote $quote) ->setType('discount') ->setAmountPerUnit(0) ->setAmountNet(0) - ->setAmountDiscount($basketTotals->getTotalDiscountAmount()+$totalDiscountTax) + ->setAmountDiscount($basketTotals->getTotalDiscountAmount()+$totalDiscountTaxCompensation) ->setBasketItemReferenceId($itemCount); $basket->addBasketItem($discountPosition); } - $basket->setAmountTotalDiscount($basketTotals->getTotalDiscountAmount()+$totalDiscountTax); + $basket->setAmountTotalDiscount($basketTotals->getTotalDiscountAmount()+$totalDiscountTaxCompensation); return $basketRequest; } diff --git a/Wrapper/BaseWrapper.php b/Wrapper/BaseWrapper.php index bfaa933f1f8..b91a1e9c9bb 100755 --- a/Wrapper/BaseWrapper.php +++ b/Wrapper/BaseWrapper.php @@ -16,4 +16,14 @@ class BaseWrapper { use DumpGetterReturnsTrait; + + /** + * Convert an euro amount to cent. + * @param $value + * @return int + */ + public function normalizeValue($value) + { + return (int)round(bcmul($value, 100)); + } } diff --git a/Wrapper/ItemWrapper.php b/Wrapper/ItemWrapper.php index 32c61509788..02f8cf0034b 100755 --- a/Wrapper/ItemWrapper.php +++ b/Wrapper/ItemWrapper.php @@ -87,7 +87,12 @@ public function getRowTotal() public function getDiscountTaxCompensationAmount () { - return (int)floor(bcmul($this->item->getDiscountTaxCompensationAmount(), 100, 10)); + $discountContainsTax = $this->item->getStore()->getConfig('tax/calculation/discount_tax'); + + if ($discountContainsTax == '0') { + return bcmul($this->item->getDiscountAmount(), $this->item->getTaxPercent()); + } + return $this->normalizeValue($this->item->getDiscountTaxCompensationAmount()); } /** @@ -98,9 +103,4 @@ public function getReferenceId($prefix = '') { return $prefix . sprintf('%x%d', $this->item->getSku(), $this->item->getQty()); } - - public function calculateDiscountTaxAmount() - { - return bcmul($this->item->getDiscountAmount(), $this->item->getTaxPercent()); - } } diff --git a/Wrapper/QuoteWrapper.php b/Wrapper/QuoteWrapper.php index 33d11ca8b97..436d500c1f7 100755 --- a/Wrapper/QuoteWrapper.php +++ b/Wrapper/QuoteWrapper.php @@ -85,7 +85,9 @@ public function getCurrencyCode() public function getSubtotalWithDiscountAndShipping() { // SubtotalWithDiscount already contains the ShippingDiscount but not the shipping itself. - return $this->getSubtotalWithDiscount() + $this->getShippingAmount(); + return $this->getSubtotalWithDiscount() + + $this->getShippingAmount() + + $this->getDiscountTaxCompensationAmount(); } /** @@ -268,6 +270,14 @@ public function getTaxAmountRaw() return $this->fetchNormalizeValue(self::FIELD_TAX_AMOUNT, true); } + /** + * @return int + */ + public function getDiscountTaxCompensationAmount() + { + return $this->normalizeValue($this->quote->getShippingAddress()->getDiscountTaxCompensationAmount()); + } + // /** @@ -280,7 +290,7 @@ private function fetchNormalizeValue($field, $raw = false) $value = $this->totals[$field]; if (!$raw) { - $value = (int)round(bcmul($value, 100)); + $value = $this->normalizeValue($value); } return $value; From 22467f6ee8f013c47dd8f26a2bd45592efc9eace Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Tue, 14 May 2019 15:17:01 +0200 Subject: [PATCH 005/114] (MAGE2-157) move basket calculation into wrapper --- Helper/BasketHelper.php | 16 +++------------- Wrapper/BaseWrapper.php | 3 ++- Wrapper/ItemWrapper.php | 3 ++- Wrapper/QuoteWrapper.php | 14 +++++++++++++- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Helper/BasketHelper.php b/Helper/BasketHelper.php index 39ce943ace4..5712f6b44b8 100755 --- a/Helper/BasketHelper.php +++ b/Helper/BasketHelper.php @@ -75,28 +75,18 @@ public function convertQuoteToBasket(Quote $quote) ->setAmountTotalVat($basketTotals->getActualTaxAmount()) ->setBasketReferenceId($basketReferenceId); - /** @var string $discountContainsTax */ - $discountContainsTax = $quote->getStore()->getConfig('tax/calculation/discount_tax'); - $totalDiscountTaxCompensation = 0; - /** @var \Magento\Quote\Model\Quote\Item $item */ foreach ($quote->getAllVisibleItems() as $item) { $basketItem = ObjectManager::getInstance()->create(BasketItem::class); /** @var ItemWrapper $itemTotals */ $itemTotals = ObjectManager::getInstance()->create(ItemWrapper::class, ['item' => $item]); - $itemDiscountTaxCompensation = $itemTotals->getDiscountTaxCompensationAmount(); - - if ($discountContainsTax == '0') { - /** In case discount amount contains no tax it will be added */ - $totalDiscountTaxCompensation += $itemDiscountTaxCompensation; - } $basketItem->setQuantity($item->getQty()) ->setVat($itemTotals->getTaxPercent()) ->setAmountPerUnit($itemTotals->getPrice()) ->setAmountNet($itemTotals->getRowTotal()) - ->setAmountVat($itemTotals->getTaxAmount()+$itemDiscountTaxCompensation) + ->setAmountVat($itemTotals->getTaxAmount()) ->setAmountGross($itemTotals->getRowTotalInclTax()) ->setTitle($item->getName()) @@ -129,12 +119,12 @@ public function convertQuoteToBasket(Quote $quote) ->setType('discount') ->setAmountPerUnit(0) ->setAmountNet(0) - ->setAmountDiscount($basketTotals->getTotalDiscountAmount()+$totalDiscountTaxCompensation) + ->setAmountDiscount($basketTotals->getTotalDiscountAmount()) ->setBasketItemReferenceId($itemCount); $basket->addBasketItem($discountPosition); } - $basket->setAmountTotalDiscount($basketTotals->getTotalDiscountAmount()+$totalDiscountTaxCompensation); + $basket->setAmountTotalDiscount($basketTotals->getTotalDiscountAmount()); return $basketRequest; } diff --git a/Wrapper/BaseWrapper.php b/Wrapper/BaseWrapper.php index b91a1e9c9bb..7c1950f7919 100755 --- a/Wrapper/BaseWrapper.php +++ b/Wrapper/BaseWrapper.php @@ -13,6 +13,7 @@ use Heidelpay\Gateway\Traits\DumpGetterReturnsTrait; + class BaseWrapper { use DumpGetterReturnsTrait; @@ -24,6 +25,6 @@ class BaseWrapper */ public function normalizeValue($value) { - return (int)round(bcmul($value, 100)); + return (int)round(bcmul($value, 100, 10)); } } diff --git a/Wrapper/ItemWrapper.php b/Wrapper/ItemWrapper.php index 02f8cf0034b..5bc6e7a4c18 100755 --- a/Wrapper/ItemWrapper.php +++ b/Wrapper/ItemWrapper.php @@ -66,7 +66,8 @@ public function getDiscountAmount() */ public function getTaxAmount() { - return (int)floor(bcmul($this->item->getTaxAmount(), 100, 10)); + return $this->normalizeValue($this->item->getTaxAmount()) + + $this->getDiscountTaxCompensationAmount(); } /** diff --git a/Wrapper/QuoteWrapper.php b/Wrapper/QuoteWrapper.php index 436d500c1f7..b56504adcf8 100755 --- a/Wrapper/QuoteWrapper.php +++ b/Wrapper/QuoteWrapper.php @@ -12,6 +12,7 @@ namespace Heidelpay\Gateway\Wrapper; use Magento\Quote\Model\Quote; +use Magento\Framework\App\ObjectManager; class QuoteWrapper extends BaseWrapper { @@ -106,7 +107,18 @@ public function getActualTaxAmount() */ public function getTotalDiscountAmount() { - return (int)round(bcmul($this->getTotalDiscountAmountRaw(), 100)); + /** @var string $discountContainsTax */ + $discountContainsTax = $this->quote->getStore()->getConfig('tax/calculation/discount_tax'); + $totalDiscountTaxCompensation = 0; + if ($discountContainsTax === '0') { + foreach ($this->quote->getAllVisibleItems() as $item) { + /** @var ItemWrapper $itemTotals */ + $itemTotals = ObjectManager::getInstance()->create(ItemWrapper::class, ['item' => $item]); + $totalDiscountTaxCompensation = $itemTotals->getDiscountTaxCompensationAmount(); + } + } + + return $this->normalizeValue($this->getTotalDiscountAmountRaw()) + $totalDiscountTaxCompensation; } /** From c041e666713442c158df6a698d30bcc3892ea2a8 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Tue, 14 May 2019 15:42:19 +0200 Subject: [PATCH 006/114] Update Wrapper/ItemWrapper.php Co-Authored-By: Simon Gabriel --- Wrapper/ItemWrapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Wrapper/ItemWrapper.php b/Wrapper/ItemWrapper.php index 5bc6e7a4c18..1008a11587e 100755 --- a/Wrapper/ItemWrapper.php +++ b/Wrapper/ItemWrapper.php @@ -90,7 +90,7 @@ public function getDiscountTaxCompensationAmount () { $discountContainsTax = $this->item->getStore()->getConfig('tax/calculation/discount_tax'); - if ($discountContainsTax == '0') { + if ($discountContainsTax === '0') { return bcmul($this->item->getDiscountAmount(), $this->item->getTaxPercent()); } return $this->normalizeValue($this->item->getDiscountTaxCompensationAmount()); From 0c3bda108764ae1ca9387281e90fbf399854e3a1 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Tue, 14 May 2019 15:47:26 +0200 Subject: [PATCH 007/114] Update Wrapper/QuoteWrapper.php Co-Authored-By: Simon Gabriel --- Wrapper/QuoteWrapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Wrapper/QuoteWrapper.php b/Wrapper/QuoteWrapper.php index b56504adcf8..4118aef1e0e 100755 --- a/Wrapper/QuoteWrapper.php +++ b/Wrapper/QuoteWrapper.php @@ -114,7 +114,7 @@ public function getTotalDiscountAmount() foreach ($this->quote->getAllVisibleItems() as $item) { /** @var ItemWrapper $itemTotals */ $itemTotals = ObjectManager::getInstance()->create(ItemWrapper::class, ['item' => $item]); - $totalDiscountTaxCompensation = $itemTotals->getDiscountTaxCompensationAmount(); + $totalDiscountTaxCompensation += $itemTotals->getDiscountTaxCompensationAmount(); } } From b80b7495d9450415339e417d7d79d53971e9164f Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Tue, 14 May 2019 15:48:20 +0200 Subject: [PATCH 008/114] (MAGE2-157) refactor --- Helper/BasketHelper.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Helper/BasketHelper.php b/Helper/BasketHelper.php index 5712f6b44b8..f30d3dacaae 100755 --- a/Helper/BasketHelper.php +++ b/Helper/BasketHelper.php @@ -73,6 +73,7 @@ public function convertQuoteToBasket(Quote $quote) $basket->setCurrencyCode($basketTotals->getCurrencyCode()) ->setAmountTotalNet($basketTotals->getSubtotalWithDiscountAndShipping()) ->setAmountTotalVat($basketTotals->getActualTaxAmount()) + ->setAmountTotalDiscount($basketTotals->getTotalDiscountAmount()) ->setBasketReferenceId($basketReferenceId); /** @var \Magento\Quote\Model\Quote\Item $item */ @@ -123,9 +124,6 @@ public function convertQuoteToBasket(Quote $quote) ->setBasketItemReferenceId($itemCount); $basket->addBasketItem($discountPosition); } - - $basket->setAmountTotalDiscount($basketTotals->getTotalDiscountAmount()); - return $basketRequest; } From 700dcac5f460b35016958ef541a1f8478d34c93b Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Tue, 14 May 2019 16:18:23 +0200 Subject: [PATCH 009/114] Update Controller/Index/Push.php Co-Authored-By: heidelpay --- Controller/Index/Push.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Controller/Index/Push.php b/Controller/Index/Push.php index 75bfb8ba0cd..392d5a55d63 100755 --- a/Controller/Index/Push.php +++ b/Controller/Index/Push.php @@ -208,7 +208,6 @@ public function execute() ); // create a child transaction. - $payment->setAmountPaid($paidAmount); $payment->setTransactionId($transactionID) ->setParentTransactionId($pushResponse->getIdentification()->getReferenceId()) ->setIsTransactionClosed(true) From 413b0adcf4bf983a197149fece098c32258ff696 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Tue, 14 May 2019 16:29:01 +0200 Subject: [PATCH 010/114] (MAGE2-172) Use variable name according to function logic. --- Controller/Index/Push.php | 6 +++--- PaymentMethods/HeidelpayAbstractPaymentMethod.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Controller/Index/Push.php b/Controller/Index/Push.php index 392d5a55d63..3869c30f014 100755 --- a/Controller/Index/Push.php +++ b/Controller/Index/Push.php @@ -160,11 +160,11 @@ public function execute() $methodInstance = $payment->getMethodInstance(); $transactionID = $pushResponse->getPaymentReferenceId(); - /** @var bool $isNewTransaction Flag to identify new Transaction*/ - $isNewTransaction = $methodInstance->heidelpayTransactionExists($transactionID); + /** @var bool $transactionExists Flag to identify new Transaction*/ + $transactionExists = $methodInstance->heidelpayTransactionExists($transactionID); // If Transaction already exists, push wont be processed. - if (!$isNewTransaction) { + if ($transactionExists) { $this->_logger->debug('heidelpay - Push Response: ' . $transactionID . ' already exists'); return; } diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index ba3ff35616f..d1e01275bdc 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -834,6 +834,6 @@ public function heidelpayTransactionExists($transactionID) /** @var \Heidelpay\Gateway\Model\Transaction $heidelpayTransaction */ $heidelpayTransaction = $collection->loadByTransactionId($transactionID); - return $heidelpayTransaction === null || $heidelpayTransaction->isEmpty(); + return !$heidelpayTransaction === null && !$heidelpayTransaction->isEmpty(); } } From 54e804828b7d547671b1f5e011037f70326ee4dc Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 22 May 2019 12:45:11 +0200 Subject: [PATCH 011/114] [cleanup] Fix typo. --- PaymentMethods/HeidelpayCreditCardPaymentMethod.php | 4 ++-- PaymentMethods/HeidelpayDebitCardPaymentMethod.php | 4 ++-- PaymentMethods/HeidelpayDirectDebitPaymentMethod.php | 2 +- PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php | 2 +- PaymentMethods/HeidelpayGiropayPaymentMethod.php | 2 +- PaymentMethods/HeidelpayPayPalPaymentMethod.php | 4 ++-- PaymentMethods/HeidelpayPrepaymentPaymentMethod.php | 4 ++-- PaymentMethods/HeidelpaySofortPaymentMethod.php | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/PaymentMethods/HeidelpayCreditCardPaymentMethod.php b/PaymentMethods/HeidelpayCreditCardPaymentMethod.php index 46d3953654c..c09d3ab6dca 100755 --- a/PaymentMethods/HeidelpayCreditCardPaymentMethod.php +++ b/PaymentMethods/HeidelpayCreditCardPaymentMethod.php @@ -26,13 +26,13 @@ class HeidelpayCreditCardPaymentMethod extends HeidelpayAbstractPaymentMethod { /** * Payment Code - * @var string PayentCode + * @var string PaymentCode */ const CODE = 'hgwcc'; /** * Payment Code - * @var string PayentCode + * @var string PaymentCode */ protected $_code = self::CODE; diff --git a/PaymentMethods/HeidelpayDebitCardPaymentMethod.php b/PaymentMethods/HeidelpayDebitCardPaymentMethod.php index b16db95bc90..5c3bdb0eeae 100755 --- a/PaymentMethods/HeidelpayDebitCardPaymentMethod.php +++ b/PaymentMethods/HeidelpayDebitCardPaymentMethod.php @@ -26,13 +26,13 @@ class HeidelpayDebitCardPaymentMethod extends HeidelpayAbstractPaymentMethod { /** * Payment Code - * @var string PayentCode + * @var string PaymentCode */ const CODE = 'hgwdc'; /** * Payment Code - * @var string PayentCode + * @var string PaymentCode */ protected $_code = self::CODE; diff --git a/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php b/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php index de87986b280..55334df11c9 100755 --- a/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php +++ b/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php @@ -26,7 +26,7 @@ class HeidelpayDirectDebitPaymentMethod extends HeidelpayAbstractPaymentMethod { /** * Payment Code - * @var string PayentCode + * @var string PaymentCode */ const CODE = 'hgwdd'; diff --git a/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php b/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php index 331f5181663..e7a60a43a12 100755 --- a/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php @@ -26,7 +26,7 @@ class HeidelpayDirectDebitSecuredPaymentMethod extends HeidelpayAbstractPaymentM { /** * Payment Code - * @var string PayentCode + * @var string PaymentCode */ const CODE = 'hgwdds'; diff --git a/PaymentMethods/HeidelpayGiropayPaymentMethod.php b/PaymentMethods/HeidelpayGiropayPaymentMethod.php index 49a90563494..394a1549e9a 100755 --- a/PaymentMethods/HeidelpayGiropayPaymentMethod.php +++ b/PaymentMethods/HeidelpayGiropayPaymentMethod.php @@ -25,7 +25,7 @@ class HeidelpayGiropayPaymentMethod extends HeidelpayAbstractPaymentMethod { /** * Payment Code - * @var string PayentCode + * @var string PaymentCode */ const CODE = 'hgwgp'; diff --git a/PaymentMethods/HeidelpayPayPalPaymentMethod.php b/PaymentMethods/HeidelpayPayPalPaymentMethod.php index 27cc91b16f3..244226f8eeb 100755 --- a/PaymentMethods/HeidelpayPayPalPaymentMethod.php +++ b/PaymentMethods/HeidelpayPayPalPaymentMethod.php @@ -26,13 +26,13 @@ class HeidelpayPayPalPaymentMethod extends HeidelpayAbstractPaymentMethod { /** * Payment Code - * @var string PayentCode + * @var string PaymentCode */ const CODE = 'hgwpal'; /** * Payment Code - * @var string PayentCode + * @var string PaymentCode */ protected $_code = self::CODE; diff --git a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php index 8b16d4860d1..1fa343fe427 100755 --- a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php +++ b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php @@ -25,13 +25,13 @@ class HeidelpayPrepaymentPaymentMethod extends HeidelpayAbstractPaymentMethod { /** * Payment Code - * @var string PayentCode + * @var string PaymentCode */ const CODE = 'hgwpp'; /** * Payment Code - * @var string PayentCode + * @var string PaymentCode */ protected $_code = self::CODE; diff --git a/PaymentMethods/HeidelpaySofortPaymentMethod.php b/PaymentMethods/HeidelpaySofortPaymentMethod.php index 891211b3f4d..618a20763de 100755 --- a/PaymentMethods/HeidelpaySofortPaymentMethod.php +++ b/PaymentMethods/HeidelpaySofortPaymentMethod.php @@ -25,13 +25,13 @@ class HeidelpaySofortPaymentMethod extends HeidelpayAbstractPaymentMethod { /** * Payment Code - * @var string PayentCode + * @var string PaymentCode */ const CODE = 'hgwsue'; /** * Payment Code - * @var string PayentCode + * @var string PaymentCode */ protected $_code = self::CODE; From fd837369c27fdc003fcfb59bc93504e94f9bf8f8 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 23 May 2019 09:34:01 +0200 Subject: [PATCH 012/114] [feature] (MAGE2-175) Santander Hire Purchase: Add new payment method. --- .../HgwSantanderHirePurchasePaymentConfig.php | 18 ++ ...nderHirePurchasePaymentConfigInterface.php | 18 ++ ...lpaySantanderHirePurchasePaymentMethod.php | 159 ++++++++++++++++++ etc/config.xml | 12 ++ etc/di.xml | 6 + view/frontend/layout/checkout_index_index.xml | 3 + .../web/js/view/payment/hgw-payments.js | 4 + 7 files changed, 220 insertions(+) create mode 100755 Gateway/Config/HgwSantanderHirePurchasePaymentConfig.php create mode 100755 Gateway/Config/HgwSantanderHirePurchasePaymentConfigInterface.php create mode 100755 PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php mode change 100644 => 100755 etc/config.xml mode change 100644 => 100755 view/frontend/layout/checkout_index_index.xml mode change 100644 => 100755 view/frontend/web/js/view/payment/hgw-payments.js diff --git a/Gateway/Config/HgwSantanderHirePurchasePaymentConfig.php b/Gateway/Config/HgwSantanderHirePurchasePaymentConfig.php new file mode 100755 index 00000000000..d1be26237ed --- /dev/null +++ b/Gateway/Config/HgwSantanderHirePurchasePaymentConfig.php @@ -0,0 +1,18 @@ + + * + * @package heidelpay/magento2 + */ +namespace Heidelpay\Gateway\Gateway\Config; + +class HgwSantanderHirePurchasePaymentConfig extends HgwBasePaymentConfig implements HgwSofortPaymentConfigInterface +{ +} diff --git a/Gateway/Config/HgwSantanderHirePurchasePaymentConfigInterface.php b/Gateway/Config/HgwSantanderHirePurchasePaymentConfigInterface.php new file mode 100755 index 00000000000..1dba98b7a13 --- /dev/null +++ b/Gateway/Config/HgwSantanderHirePurchasePaymentConfigInterface.php @@ -0,0 +1,18 @@ + + * + * @package heidelpay/magento2 + */ +namespace Heidelpay\Gateway\Gateway\Config; + +interface HgwSantanderHirePurchasePaymentConfigInterface extends HgwBasePaymentConfigInterface +{ +} diff --git a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php new file mode 100755 index 00000000000..c8ff6be7205 --- /dev/null +++ b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php @@ -0,0 +1,159 @@ +_heidelpayPaymentMethod = $paymentMethod; + } + + /** + * Initial Request to heidelpay payment server to get the form 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->initialize(); + + return $this->_heidelpayPaymentMethod->getResponse(); + } +} diff --git a/etc/config.xml b/etc/config.xml old mode 100644 new mode 100755 index 8260fc7131f..c533541c934 --- a/etc/config.xml +++ b/etc/config.xml @@ -132,6 +132,18 @@ 0 Heidelpay\Gateway\PaymentMethods\HeidelpayIDealPaymentMethod + + 0 + authorize + <![CDATA[Santander Hire Purchase]]> + 31HA07BC81302E8725994B52D85F062E + 1 + never + DE + 0 + 0 + Heidelpay\Gateway\PaymentMethods\HeidelpaySantanderHirePurchasePaymentMethod + \ No newline at end of file diff --git a/etc/di.xml b/etc/di.xml index 904e6db6169..0e1dd5960e4 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -69,6 +69,11 @@ Heidelpay\Gateway\PaymentMethods\HeidelpayIDealPaymentMethod::CODE + + + Heidelpay\Gateway\PaymentMethods\HeidelpaySantanderHirePurchasePaymentMethod::CODE + + @@ -86,4 +91,5 @@ + \ No newline at end of file diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml old mode 100644 new mode 100755 index e0c74392d53..e18b34785a1 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -59,6 +59,9 @@ false + + false + diff --git a/view/frontend/web/js/view/payment/hgw-payments.js b/view/frontend/web/js/view/payment/hgw-payments.js old mode 100644 new mode 100755 index 27a49694994..8850e2ab234 --- a/view/frontend/web/js/view/payment/hgw-payments.js +++ b/view/frontend/web/js/view/payment/hgw-payments.js @@ -52,6 +52,10 @@ define( { type: 'hgwidl', component: 'Heidelpay_Gateway/js/view/payment/method-renderer/hgw-ideal' + }, + { + type: 'hgwsanhp', + component: 'Heidelpay_Gateway/js/view/payment/method-renderer/hgw-abstract' } ); return Component.extend({}); From 7f31c460aa3e029d21c8721c5d90674bc2fde96c Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 23 May 2019 14:22:00 +0200 Subject: [PATCH 013/114] [feature] (MAGE2-175) Santander Hire Purchase: Add translations and backend config fields. --- etc/adminhtml/system.xml | 29 +++++++++++++++++++++++++++++ i18n/de_DE.csv | 2 ++ i18n/en_US.csv | 2 ++ 3 files changed, 33 insertions(+) mode change 100644 => 100755 etc/adminhtml/system.xml diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml old mode 100644 new mode 100755 index 093dc0ef43c..521e4e6f6f3 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -497,6 +497,35 @@ Insert 0 to disable limit. + + + + + Magento\Config\Model\Config\Source\Yesno + payment/hgwidl/active + + + + payment/hgwidl/title + + + + payment/hgwidl/channel + + + + payment/hgwidl/sort_order + + + + payment/hgwidl/min_order_total + + + + payment/hgwidl/max_order_total + Insert 0 to disable limit. + + diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index 1d11f9b8bdc..218a0511fb3 100755 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -11,6 +11,7 @@ "HGWIV","Rechnungskauf" "HGWIVS","Gesicherter Rechnungskauf (B2C)" "HGWIDL","iDeal" +"HGWSANHP","Ratenkauf von Santander" "HGW_ABOUT_US","Die heidelpay 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" @@ -44,6 +45,7 @@ "Mangirkart","MangirKart" "MasterPass","MasterPass" "Sofort.","Sofort." +"Santander Hire Purchase","Ratenkauf von Santander" "IBAN", "IBAN" "BIC","BIC" diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 30e5af84645..ec1b6cf2c60 100755 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -11,6 +11,7 @@ "HGWIV","Invoice" "HGWIVS","Invoice Secured (B2C)" "HGWIDL","iDeal" +"HGWSANHP","Ratenkauf von Santander" "HGW_ABOUT_US","heidelpay 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" @@ -33,6 +34,7 @@ "Mangirkart","MangirKart" "MasterPass","MasterPass" "Sofort.","Sofort." +"Santander Hire Purchase","Santander Hire Purchase" "IBAN","IBAN" "BIC","BIC" From a08793aee0965d056414eb5358f1bec7a69b4d60 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 23 May 2019 14:38:07 +0200 Subject: [PATCH 014/114] [feature] (MAGE2-175) Santander Hire Purchase: Fix config field paths. --- etc/adminhtml/system.xml | 12 ++++++------ i18n/en_US.csv | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 521e4e6f6f3..9324a7bdc70 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -502,27 +502,27 @@ Magento\Config\Model\Config\Source\Yesno - payment/hgwidl/active + payment/hgwsanhp/active - payment/hgwidl/title + payment/hgwsanhp/title - payment/hgwidl/channel + payment/hgwsanhp/channel - payment/hgwidl/sort_order + payment/hgwsanhp/sort_order - payment/hgwidl/min_order_total + payment/hgwsanhp/min_order_total - payment/hgwidl/max_order_total + payment/hgwsanhp/max_order_total Insert 0 to disable limit. diff --git a/i18n/en_US.csv b/i18n/en_US.csv index ec1b6cf2c60..a2dc66adaff 100755 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -11,7 +11,7 @@ "HGWIV","Invoice" "HGWIVS","Invoice Secured (B2C)" "HGWIDL","iDeal" -"HGWSANHP","Ratenkauf von Santander" +"HGWSANHP","Santander Hire Purchase" "HGW_ABOUT_US","heidelpay 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" From ca5ab92731a4c933c8514c7e560f7ce7eaef114b Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Thu, 23 May 2019 15:02:12 +0200 Subject: [PATCH 015/114] (MAGE2-191) Simplify payment config: Pass the paymentConfig parameter to payment method as an argument in di.xml --- Gateway/Config/HgwCreditCardPaymentConfig.php | 18 ---- .../HgwCreditCardPaymentConfigInterface.php | 18 ---- Gateway/Config/HgwDebitCardPaymentConfig.php | 18 ---- .../HgwDebitCardPaymentConfigInterface.php | 18 ---- .../Config/HgwDirectDebitPaymentConfig.php | 18 ---- .../HgwDirectDebitPaymentConfigInterface.php | 18 ---- .../Config/HgwDirectDebitSecPaymentConfig.php | 18 ---- ...gwDirectDebitSecPaymentConfigInterface.php | 18 ---- Gateway/Config/HgwGiropayPaymentConfig.php | 18 ---- .../HgwGiropayPaymentConfigInterface.php | 18 ---- Gateway/Config/HgwIDealPaymentConfig.php | 19 ---- .../Config/HgwIDealPaymentConfigInterface.php | 19 ---- Gateway/Config/HgwInvoicePaymentConfig.php | 18 ---- .../HgwInvoicePaymentConfigInterface.php | 18 ---- .../Config/HgwInvoiceSecuredPaymentConfig.php | 18 ---- ...gwInvoiceSecuredPaymentConfigInterface.php | 18 ---- Gateway/Config/HgwPayPalPaymentConfig.php | 18 ---- .../HgwPayPalPaymentConfigInterface.php | 18 ---- Gateway/Config/HgwPrepaymentPaymentConfig.php | 18 ---- .../HgwPrepaymentPaymentConfigInterface.php | 18 ---- Gateway/Config/HgwSofortPaymentConfig.php | 18 ---- .../HgwSofortPaymentConfigInterface.php | 18 ---- .../HeidelpayCreditCardPaymentMethod.php | 6 +- .../HeidelpayDebitCardPaymentMethod.php | 6 +- .../HeidelpayDirectDebitPaymentMethod.php | 6 +- ...idelpayDirectDebitSecuredPaymentMethod.php | 6 +- .../HeidelpayGiropayPaymentMethod.php | 6 +- .../HeidelpayIDealPaymentMethod.php | 4 +- .../HeidelpayInvoicePaymentMethod.php | 6 +- .../HeidelpayInvoiceSecuredPaymentMethod.php | 6 +- .../HeidelpayPayPalPaymentMethod.php | 6 +- .../HeidelpayPrepaymentPaymentMethod.php | 6 +- .../HeidelpaySofortPaymentMethod.php | 6 +- etc/di.xml | 91 ++++++++++++++----- 34 files changed, 100 insertions(+), 453 deletions(-) delete mode 100755 Gateway/Config/HgwCreditCardPaymentConfig.php delete mode 100755 Gateway/Config/HgwCreditCardPaymentConfigInterface.php delete mode 100755 Gateway/Config/HgwDebitCardPaymentConfig.php delete mode 100755 Gateway/Config/HgwDebitCardPaymentConfigInterface.php delete mode 100755 Gateway/Config/HgwDirectDebitPaymentConfig.php delete mode 100755 Gateway/Config/HgwDirectDebitPaymentConfigInterface.php delete mode 100755 Gateway/Config/HgwDirectDebitSecPaymentConfig.php delete mode 100755 Gateway/Config/HgwDirectDebitSecPaymentConfigInterface.php delete mode 100755 Gateway/Config/HgwGiropayPaymentConfig.php delete mode 100755 Gateway/Config/HgwGiropayPaymentConfigInterface.php delete mode 100644 Gateway/Config/HgwIDealPaymentConfig.php delete mode 100644 Gateway/Config/HgwIDealPaymentConfigInterface.php delete mode 100755 Gateway/Config/HgwInvoicePaymentConfig.php delete mode 100755 Gateway/Config/HgwInvoicePaymentConfigInterface.php delete mode 100755 Gateway/Config/HgwInvoiceSecuredPaymentConfig.php delete mode 100755 Gateway/Config/HgwInvoiceSecuredPaymentConfigInterface.php delete mode 100755 Gateway/Config/HgwPayPalPaymentConfig.php delete mode 100755 Gateway/Config/HgwPayPalPaymentConfigInterface.php delete mode 100755 Gateway/Config/HgwPrepaymentPaymentConfig.php delete mode 100755 Gateway/Config/HgwPrepaymentPaymentConfigInterface.php delete mode 100755 Gateway/Config/HgwSofortPaymentConfig.php delete mode 100755 Gateway/Config/HgwSofortPaymentConfigInterface.php diff --git a/Gateway/Config/HgwCreditCardPaymentConfig.php b/Gateway/Config/HgwCreditCardPaymentConfig.php deleted file mode 100755 index a045812b8aa..00000000000 --- a/Gateway/Config/HgwCreditCardPaymentConfig.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -class HgwCreditCardPaymentConfig extends HgwBasePaymentConfig implements HgwCreditCardPaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwCreditCardPaymentConfigInterface.php b/Gateway/Config/HgwCreditCardPaymentConfigInterface.php deleted file mode 100755 index 0b12dc4899a..00000000000 --- a/Gateway/Config/HgwCreditCardPaymentConfigInterface.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -interface HgwCreditCardPaymentConfigInterface extends HgwBasePaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwDebitCardPaymentConfig.php b/Gateway/Config/HgwDebitCardPaymentConfig.php deleted file mode 100755 index 4fe65129c1f..00000000000 --- a/Gateway/Config/HgwDebitCardPaymentConfig.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -class HgwDebitCardPaymentConfig extends HgwBasePaymentConfig implements HgwDebitCardPaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwDebitCardPaymentConfigInterface.php b/Gateway/Config/HgwDebitCardPaymentConfigInterface.php deleted file mode 100755 index 8b5a03ba54b..00000000000 --- a/Gateway/Config/HgwDebitCardPaymentConfigInterface.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -interface HgwDebitCardPaymentConfigInterface extends HgwBasePaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwDirectDebitPaymentConfig.php b/Gateway/Config/HgwDirectDebitPaymentConfig.php deleted file mode 100755 index d119edc0699..00000000000 --- a/Gateway/Config/HgwDirectDebitPaymentConfig.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -class HgwDirectDebitPaymentConfig extends HgwBasePaymentConfig implements HgwDirectDebitPaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwDirectDebitPaymentConfigInterface.php b/Gateway/Config/HgwDirectDebitPaymentConfigInterface.php deleted file mode 100755 index 28e6a60a1b8..00000000000 --- a/Gateway/Config/HgwDirectDebitPaymentConfigInterface.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -interface HgwDirectDebitPaymentConfigInterface extends HgwBasePaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwDirectDebitSecPaymentConfig.php b/Gateway/Config/HgwDirectDebitSecPaymentConfig.php deleted file mode 100755 index f2081a2e791..00000000000 --- a/Gateway/Config/HgwDirectDebitSecPaymentConfig.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -class HgwDirectDebitSecPaymentConfig extends HgwBasePaymentConfig implements HgwDirectDebitSecPaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwDirectDebitSecPaymentConfigInterface.php b/Gateway/Config/HgwDirectDebitSecPaymentConfigInterface.php deleted file mode 100755 index b91f479af32..00000000000 --- a/Gateway/Config/HgwDirectDebitSecPaymentConfigInterface.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -interface HgwDirectDebitSecPaymentConfigInterface extends HgwBasePaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwGiropayPaymentConfig.php b/Gateway/Config/HgwGiropayPaymentConfig.php deleted file mode 100755 index 564e7b50f45..00000000000 --- a/Gateway/Config/HgwGiropayPaymentConfig.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -class HgwGiropayPaymentConfig extends HgwBasePaymentConfig implements HgwGiropayPaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwGiropayPaymentConfigInterface.php b/Gateway/Config/HgwGiropayPaymentConfigInterface.php deleted file mode 100755 index b8b64be8bd8..00000000000 --- a/Gateway/Config/HgwGiropayPaymentConfigInterface.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -interface HgwGiropayPaymentConfigInterface extends HgwBasePaymentConfigInterface -{ -} \ No newline at end of file diff --git a/Gateway/Config/HgwIDealPaymentConfig.php b/Gateway/Config/HgwIDealPaymentConfig.php deleted file mode 100644 index bea0a70dc84..00000000000 --- a/Gateway/Config/HgwIDealPaymentConfig.php +++ /dev/null @@ -1,19 +0,0 @@ - - * - * @package heidelpay/magento2 - */ - -namespace Heidelpay\Gateway\Gateway\Config; - -class HgwIDealPaymentConfig extends HgwBasePaymentConfig implements HgwIDealPaymentConfigInterface -{ -} \ No newline at end of file diff --git a/Gateway/Config/HgwIDealPaymentConfigInterface.php b/Gateway/Config/HgwIDealPaymentConfigInterface.php deleted file mode 100644 index 189a2fccccd..00000000000 --- a/Gateway/Config/HgwIDealPaymentConfigInterface.php +++ /dev/null @@ -1,19 +0,0 @@ - - * - * @package heidelpay/magento2 - */ - -namespace Heidelpay\Gateway\Gateway\Config; - -interface HgwIDealPaymentConfigInterface extends HgwBasePaymentConfigInterface -{ -} \ No newline at end of file diff --git a/Gateway/Config/HgwInvoicePaymentConfig.php b/Gateway/Config/HgwInvoicePaymentConfig.php deleted file mode 100755 index 432070f37b2..00000000000 --- a/Gateway/Config/HgwInvoicePaymentConfig.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -class HgwInvoicePaymentConfig extends HgwBasePaymentConfig implements HgwInvoicePaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwInvoicePaymentConfigInterface.php b/Gateway/Config/HgwInvoicePaymentConfigInterface.php deleted file mode 100755 index b78d2eb2b92..00000000000 --- a/Gateway/Config/HgwInvoicePaymentConfigInterface.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -interface HgwInvoicePaymentConfigInterface extends HgwBasePaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwInvoiceSecuredPaymentConfig.php b/Gateway/Config/HgwInvoiceSecuredPaymentConfig.php deleted file mode 100755 index 7a6297ffb31..00000000000 --- a/Gateway/Config/HgwInvoiceSecuredPaymentConfig.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -class HgwInvoiceSecuredPaymentConfig extends HgwBasePaymentConfig implements HgwInvoiceSecuredPaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwInvoiceSecuredPaymentConfigInterface.php b/Gateway/Config/HgwInvoiceSecuredPaymentConfigInterface.php deleted file mode 100755 index 1ec8b8e67c4..00000000000 --- a/Gateway/Config/HgwInvoiceSecuredPaymentConfigInterface.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -interface HgwInvoiceSecuredPaymentConfigInterface extends HgwBasePaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwPayPalPaymentConfig.php b/Gateway/Config/HgwPayPalPaymentConfig.php deleted file mode 100755 index 07ce3810066..00000000000 --- a/Gateway/Config/HgwPayPalPaymentConfig.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -class HgwPayPalPaymentConfig extends HgwBasePaymentConfig implements HgwPayPalPaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwPayPalPaymentConfigInterface.php b/Gateway/Config/HgwPayPalPaymentConfigInterface.php deleted file mode 100755 index 9495807aaaf..00000000000 --- a/Gateway/Config/HgwPayPalPaymentConfigInterface.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -interface HgwPayPalPaymentConfigInterface extends HgwBasePaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwPrepaymentPaymentConfig.php b/Gateway/Config/HgwPrepaymentPaymentConfig.php deleted file mode 100755 index 29f6e2c4720..00000000000 --- a/Gateway/Config/HgwPrepaymentPaymentConfig.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -class HgwPrepaymentPaymentConfig extends HgwBasePaymentConfig implements HgwPrepaymentPaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwPrepaymentPaymentConfigInterface.php b/Gateway/Config/HgwPrepaymentPaymentConfigInterface.php deleted file mode 100755 index f9b93c7f815..00000000000 --- a/Gateway/Config/HgwPrepaymentPaymentConfigInterface.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -interface HgwPrepaymentPaymentConfigInterface extends HgwBasePaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwSofortPaymentConfig.php b/Gateway/Config/HgwSofortPaymentConfig.php deleted file mode 100755 index 424fd027c2c..00000000000 --- a/Gateway/Config/HgwSofortPaymentConfig.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -class HgwSofortPaymentConfig extends HgwBasePaymentConfig implements HgwSofortPaymentConfigInterface -{ -} diff --git a/Gateway/Config/HgwSofortPaymentConfigInterface.php b/Gateway/Config/HgwSofortPaymentConfigInterface.php deleted file mode 100755 index 1804f6e6251..00000000000 --- a/Gateway/Config/HgwSofortPaymentConfigInterface.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * @package heidelpay/magento2 - */ -namespace Heidelpay\Gateway\Gateway\Config; - -interface HgwSofortPaymentConfigInterface extends HgwBasePaymentConfigInterface -{ -} diff --git a/PaymentMethods/HeidelpayCreditCardPaymentMethod.php b/PaymentMethods/HeidelpayCreditCardPaymentMethod.php index 46d3953654c..3a076b6dfc0 100755 --- a/PaymentMethods/HeidelpayCreditCardPaymentMethod.php +++ b/PaymentMethods/HeidelpayCreditCardPaymentMethod.php @@ -2,7 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwCreditCardPaymentConfigInterface; +use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; use Heidelpay\Gateway\Model\Config\Source\BookingMode; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; @@ -84,7 +84,7 @@ class HeidelpayCreditCardPaymentMethod extends HeidelpayAbstractPaymentMethod * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwCreditCardPaymentConfigInterface $paymentConfig + * @param HgwBasePaymentConfigInterface $paymentConfig * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper * @param \Magento\Sales\Helper\Data $salesHelper @@ -110,7 +110,7 @@ public function __construct( \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\App\ProductMetadataInterface $productMetadata, \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwCreditCardPaymentConfigInterface $paymentConfig, + HgwBasePaymentConfigInterface $paymentConfig, \Heidelpay\Gateway\Helper\Payment $paymentHelper, \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, \Magento\Sales\Helper\Data $salesHelper, diff --git a/PaymentMethods/HeidelpayDebitCardPaymentMethod.php b/PaymentMethods/HeidelpayDebitCardPaymentMethod.php index b16db95bc90..f7675f30373 100755 --- a/PaymentMethods/HeidelpayDebitCardPaymentMethod.php +++ b/PaymentMethods/HeidelpayDebitCardPaymentMethod.php @@ -2,7 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwDebitCardPaymentConfigInterface; +use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; use Heidelpay\Gateway\Model\Config\Source\BookingMode; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; @@ -84,7 +84,7 @@ class HeidelpayDebitCardPaymentMethod extends HeidelpayAbstractPaymentMethod * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwDebitCardPaymentConfigInterface $paymentConfig + * @param HgwBasePaymentConfigInterface $paymentConfig * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper * @param \Magento\Sales\Helper\Data $salesHelper @@ -110,7 +110,7 @@ public function __construct( \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\App\ProductMetadataInterface $productMetadata, \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwDebitCardPaymentConfigInterface $paymentConfig, + HgwBasePaymentConfigInterface $paymentConfig, \Heidelpay\Gateway\Helper\Payment $paymentHelper, \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, \Magento\Sales\Helper\Data $salesHelper, diff --git a/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php b/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php index de87986b280..115251ded45 100755 --- a/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php +++ b/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php @@ -2,7 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwDirectDebitPaymentConfigInterface; +use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; @@ -66,7 +66,7 @@ class HeidelpayDirectDebitPaymentMethod extends HeidelpayAbstractPaymentMethod * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwDirectDebitPaymentConfigInterface $paymentConfig + * @param HgwBasePaymentConfigInterface $paymentConfig * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper * @param \Magento\Sales\Helper\Data $salesHelper @@ -92,7 +92,7 @@ public function __construct( \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\App\ProductMetadataInterface $productMetadata, \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwDirectDebitPaymentConfigInterface $paymentConfig, + HgwBasePaymentConfigInterface $paymentConfig, \Heidelpay\Gateway\Helper\Payment $paymentHelper, \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, \Magento\Sales\Helper\Data $salesHelper, diff --git a/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php b/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php index 331f5181663..ca1cb974b83 100755 --- a/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php @@ -2,7 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwDirectDebitSecPaymentConfigInterface; +use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; @@ -66,7 +66,7 @@ class HeidelpayDirectDebitSecuredPaymentMethod extends HeidelpayAbstractPaymentM * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwDirectDebitSecPaymentConfigInterface $paymentConfig + * @param HgwBasePaymentConfigInterface $paymentConfig * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper * @param \Magento\Sales\Helper\Data $salesHelper @@ -92,7 +92,7 @@ public function __construct( \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\App\ProductMetadataInterface $productMetadata, \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwDirectDebitSecPaymentConfigInterface $paymentConfig, + HgwBasePaymentConfigInterface $paymentConfig, \Heidelpay\Gateway\Helper\Payment $paymentHelper, \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, \Magento\Sales\Helper\Data $salesHelper, diff --git a/PaymentMethods/HeidelpayGiropayPaymentMethod.php b/PaymentMethods/HeidelpayGiropayPaymentMethod.php index 49a90563494..dc7e568c3d9 100755 --- a/PaymentMethods/HeidelpayGiropayPaymentMethod.php +++ b/PaymentMethods/HeidelpayGiropayPaymentMethod.php @@ -2,7 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwGiropayPaymentConfigInterface; +use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; @@ -63,7 +63,7 @@ class HeidelpayGiropayPaymentMethod extends HeidelpayAbstractPaymentMethod * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwGiropayPaymentConfigInterface $paymentConfig + * @param HgwBasePaymentConfigInterface $paymentConfig * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper * @param \Magento\Sales\Helper\Data $salesHelper @@ -89,7 +89,7 @@ public function __construct( \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\App\ProductMetadataInterface $productMetadata, \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwGiropayPaymentConfigInterface $paymentConfig, + HgwBasePaymentConfigInterface $paymentConfig, \Heidelpay\Gateway\Helper\Payment $paymentHelper, \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, \Magento\Sales\Helper\Data $salesHelper, diff --git a/PaymentMethods/HeidelpayIDealPaymentMethod.php b/PaymentMethods/HeidelpayIDealPaymentMethod.php index 1ac63533dce..1b4b2359bba 100644 --- a/PaymentMethods/HeidelpayIDealPaymentMethod.php +++ b/PaymentMethods/HeidelpayIDealPaymentMethod.php @@ -2,7 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwIDealPaymentConfigInterface; +use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; @@ -47,7 +47,7 @@ public function __construct( \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\App\ProductMetadataInterface $productMetadata, \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwIDealPaymentConfigInterface $paymentConfig, + HgwBasePaymentConfigInterface $paymentConfig, \Heidelpay\Gateway\Helper\Payment $paymentHelper, \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, \Magento\Sales\Helper\Data $salesHelper, diff --git a/PaymentMethods/HeidelpayInvoicePaymentMethod.php b/PaymentMethods/HeidelpayInvoicePaymentMethod.php index 3e21821633c..ebcdf023982 100755 --- a/PaymentMethods/HeidelpayInvoicePaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoicePaymentMethod.php @@ -2,7 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwInvoicePaymentConfigInterface; +use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; @@ -79,7 +79,7 @@ class HeidelpayInvoicePaymentMethod extends HeidelpayAbstractPaymentMethod * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwInvoicePaymentConfigInterface $paymentConfig + * @param HgwBasePaymentConfigInterface $paymentConfig * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper * @param \Magento\Sales\Helper\Data $salesHelper @@ -105,7 +105,7 @@ public function __construct( \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\App\ProductMetadataInterface $productMetadata, \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwInvoicePaymentConfigInterface $paymentConfig, + HgwBasePaymentConfigInterface $paymentConfig, \Heidelpay\Gateway\Helper\Payment $paymentHelper, \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, \Magento\Sales\Helper\Data $salesHelper, diff --git a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php index 0e3033d5edd..eeeb6747d1a 100755 --- a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php @@ -2,7 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwInvoiceSecuredPaymentConfigInterface; +use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; @@ -79,7 +79,7 @@ class HeidelpayInvoiceSecuredPaymentMethod extends HeidelpayAbstractPaymentMetho * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwInvoiceSecuredPaymentConfigInterface $paymentConfig + * @param HgwBasePaymentConfigInterface $paymentConfig * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper * @param \Magento\Sales\Helper\Data $salesHelper @@ -105,7 +105,7 @@ public function __construct( \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\App\ProductMetadataInterface $productMetadata, \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwInvoiceSecuredPaymentConfigInterface $paymentConfig, + HgwBasePaymentConfigInterface $paymentConfig, \Heidelpay\Gateway\Helper\Payment $paymentHelper, \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, \Magento\Sales\Helper\Data $salesHelper, diff --git a/PaymentMethods/HeidelpayPayPalPaymentMethod.php b/PaymentMethods/HeidelpayPayPalPaymentMethod.php index 27cc91b16f3..c7e977d0f1c 100755 --- a/PaymentMethods/HeidelpayPayPalPaymentMethod.php +++ b/PaymentMethods/HeidelpayPayPalPaymentMethod.php @@ -2,8 +2,8 @@ namespace Heidelpay\Gateway\PaymentMethods; +use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwPayPalPaymentConfigInterface; 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; @@ -84,7 +84,7 @@ class HeidelpayPayPalPaymentMethod extends HeidelpayAbstractPaymentMethod * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwPayPalPaymentConfigInterface $paymentConfig + * @param HgwBasePaymentConfigInterface $paymentConfig * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper * @param \Magento\Sales\Helper\Data $salesHelper @@ -110,7 +110,7 @@ public function __construct( \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\App\ProductMetadataInterface $productMetadata, \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwPayPalPaymentConfigInterface $paymentConfig, + HgwBasePaymentConfigInterface $paymentConfig, \Heidelpay\Gateway\Helper\Payment $paymentHelper, \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, \Magento\Sales\Helper\Data $salesHelper, diff --git a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php index 8b16d4860d1..615e72279ab 100755 --- a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php +++ b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php @@ -3,7 +3,7 @@ namespace Heidelpay\Gateway\PaymentMethods; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwPrepaymentPaymentConfigInterface; +use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; @@ -79,7 +79,7 @@ class HeidelpayPrepaymentPaymentMethod extends HeidelpayAbstractPaymentMethod * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwPrepaymentPaymentConfigInterface $paymentConfig + * @param HgwBasePaymentConfigInterface $paymentConfig * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper * @param \Magento\Sales\Helper\Data $salesHelper @@ -105,7 +105,7 @@ public function __construct( \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\App\ProductMetadataInterface $productMetadata, \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwPrepaymentPaymentConfigInterface $paymentConfig, + HgwBasePaymentConfigInterface $paymentConfig, \Heidelpay\Gateway\Helper\Payment $paymentHelper, \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, \Magento\Sales\Helper\Data $salesHelper, diff --git a/PaymentMethods/HeidelpaySofortPaymentMethod.php b/PaymentMethods/HeidelpaySofortPaymentMethod.php index 891211b3f4d..cdfb586cf09 100755 --- a/PaymentMethods/HeidelpaySofortPaymentMethod.php +++ b/PaymentMethods/HeidelpaySofortPaymentMethod.php @@ -3,7 +3,7 @@ namespace Heidelpay\Gateway\PaymentMethods; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwSofortPaymentConfigInterface; +use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; @@ -73,7 +73,7 @@ class HeidelpaySofortPaymentMethod extends HeidelpayAbstractPaymentMethod * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwSofortPaymentConfigInterface $paymentConfig + * @param HgwBasePaymentConfigInterface $paymentConfig * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper * @param \Magento\Sales\Helper\Data $salesHelper @@ -99,7 +99,7 @@ public function __construct( \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\App\ProductMetadataInterface $productMetadata, \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwSofortPaymentConfigInterface $paymentConfig, + HgwBasePaymentConfigInterface $paymentConfig, \Heidelpay\Gateway\Helper\Payment $paymentHelper, \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, \Magento\Sales\Helper\Data $salesHelper, diff --git a/etc/di.xml b/etc/di.xml index 904e6db6169..f4dfc03724f 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -13,58 +13,115 @@ + + + + HgwCreditCardConfig + + + + + HgwDebitCardConfig + + + + + HgwDirectDebitConfig + + + + + HgwDirectDebitSecuredConfig + + + + + HgwGiropayConfig + + + + + HgwIDealConfig + + + + + HgwInvoiceConfig + + + + + HgwInvoiceSecuredConfig + + + + + HgwPayPalConfig + + + + + HgwPrepaymentConfig + + + + + HgwSofortConfig + + + - + Heidelpay\Gateway\PaymentMethods\HeidelpayInvoiceSecuredPaymentMethod::CODE - + Heidelpay\Gateway\PaymentMethods\HeidelpayCreditCardPaymentMethod::CODE - + Heidelpay\Gateway\PaymentMethods\HeidelpayDebitCardPaymentMethod::CODE - + Heidelpay\Gateway\PaymentMethods\HeidelpayGiropayPaymentMethod::CODE - + Heidelpay\Gateway\PaymentMethods\HeidelpayPrepaymentPaymentMethod::CODE - + Heidelpay\Gateway\PaymentMethods\HeidelpaySofortPaymentMethod::CODE - + Heidelpay\Gateway\PaymentMethods\HeidelpayDirectDebitPaymentMethod::CODE - + Heidelpay\Gateway\PaymentMethods\HeidelpayDirectDebitSecuredPaymentMethod::CODE - + Heidelpay\Gateway\PaymentMethods\HeidelpayInvoicePaymentMethod::CODE - + Heidelpay\Gateway\PaymentMethods\HeidelpayPayPalPaymentMethod::CODE - + Heidelpay\Gateway\PaymentMethods\HeidelpayIDealPaymentMethod::CODE @@ -74,16 +131,4 @@ - - - - - - - - - - - - \ No newline at end of file From 147010722d4e03610883346608ab61d08bd723f1 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 23 May 2019 15:10:28 +0200 Subject: [PATCH 016/114] [feature] (MAGE2-175) Santander Hire Purchase: Fix config. --- Gateway/Config/HgwSantanderHirePurchasePaymentConfig.php | 2 +- etc/di.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gateway/Config/HgwSantanderHirePurchasePaymentConfig.php b/Gateway/Config/HgwSantanderHirePurchasePaymentConfig.php index d1be26237ed..0790ead230c 100755 --- a/Gateway/Config/HgwSantanderHirePurchasePaymentConfig.php +++ b/Gateway/Config/HgwSantanderHirePurchasePaymentConfig.php @@ -13,6 +13,6 @@ */ namespace Heidelpay\Gateway\Gateway\Config; -class HgwSantanderHirePurchasePaymentConfig extends HgwBasePaymentConfig implements HgwSofortPaymentConfigInterface +class HgwSantanderHirePurchasePaymentConfig extends HgwBasePaymentConfig implements HgwSantanderHirePurchasePaymentConfigInterface { } diff --git a/etc/di.xml b/etc/di.xml index 0e1dd5960e4..4b851f17dcb 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -69,7 +69,7 @@ Heidelpay\Gateway\PaymentMethods\HeidelpayIDealPaymentMethod::CODE - + Heidelpay\Gateway\PaymentMethods\HeidelpaySantanderHirePurchasePaymentMethod::CODE From 38c2cd7fc607ffd66e1cccd937721d605536c843 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 23 May 2019 16:53:23 +0200 Subject: [PATCH 017/114] [feature] (MAGE2-175) Santander Hire Purchase: Move comment to the top of the file. --- ...lpaySantanderHirePurchasePaymentMethod.php | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php index c8ff6be7205..a78527832b2 100755 --- a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php +++ b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php @@ -1,5 +1,18 @@ Date: Thu, 23 May 2019 17:23:06 +0200 Subject: [PATCH 018/114] [feature] (MAGE2-175) Santander Hire Purchase: Fix config interface. --- .../HeidelpaySantanderHirePurchasePaymentMethod.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php index a78527832b2..c5df4a64417 100755 --- a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php +++ b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php @@ -15,8 +15,8 @@ */ namespace Heidelpay\Gateway\PaymentMethods; +use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwSantanderHirePurchasePaymentConfigInterface; use Heidelpay\Gateway\Helper\BasketHelper; use Heidelpay\Gateway\Helper\Payment; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; @@ -72,7 +72,7 @@ class HeidelpaySantanderHirePurchasePaymentMethod extends HeidelpayAbstractPayme * @param ResolverInterface $localeResolver * @param ProductMetadataInterface $productMetadata * @param ResourceInterface $moduleResource - * @param HgwSantanderHirePurchasePaymentConfigInterface $paymentConfig + * @param HgwBasePaymentConfigInterface $paymentConfig * @param Payment $paymentHelper * @param BasketHelper $basketHelper * @param \Magento\Sales\Helper\Data $salesHelper @@ -98,7 +98,7 @@ public function __construct( ResolverInterface $localeResolver, ProductMetadataInterface $productMetadata, ResourceInterface $moduleResource, - HgwSantanderHirePurchasePaymentConfigInterface $paymentConfig, + HgwBasePaymentConfigInterface $paymentConfig, Payment $paymentHelper, BasketHelper $basketHelper, \Magento\Sales\Helper\Data $salesHelper, From 3ae6c3e5ed2174a3004e02d18707cec2f0882e54 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 24 May 2019 08:52:10 +0200 Subject: [PATCH 019/114] [cleanup] Apply micro optimizations. --- .../HeidelpayAbstractPaymentMethod.php | 196 ++++++++++-------- 1 file changed, 111 insertions(+), 85 deletions(-) diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index d1e01275bdc..f88ecbf6108 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -2,17 +2,43 @@ namespace Heidelpay\Gateway\PaymentMethods; +use Exception; use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; +use Heidelpay\Gateway\Helper\BasketHelper; +use Heidelpay\Gateway\Helper\Payment; 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\Gateway\Model\Transaction; +use Heidelpay\Gateway\Model\TransactionFactory; +use Heidelpay\PhpBasketApi\Exception\InvalidBasketitemPositionException; use Heidelpay\PhpPaymentApi\ParameterGroups\BasketParameterGroup; -use Heidelpay\PhpPaymentApi\PaymentMethods\AbstractPaymentMethod; use Heidelpay\PhpPaymentApi\Response; +use Magento\Framework\Api\AttributeValueFactory; +use Magento\Framework\Api\ExtensionAttributesFactory; +use Magento\Framework\App\ProductMetadataInterface; +use Magento\Framework\App\RequestInterface; +use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Encryption\Encryptor; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Locale\ResolverInterface; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Module\ResourceInterface; +use Magento\Framework\Phrase; +use Magento\Framework\Registry; +use Magento\Framework\UrlInterface; +use Magento\Payment\Model\InfoInterface; +use Magento\Payment\Model\Method\AbstractMethod; +use Magento\Payment\Model\Method\Logger; +use Magento\Quote\Api\Data\CartInterface; +use Magento\Quote\Model\Quote; use Magento\Sales\Api\Data\TransactionInterface; +use Magento\Sales\Helper\Data; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; +use Magento\Sales\Model\Order\Payment\Interceptor; use Magento\Store\Model\ScopeInterface as StoreScopeInterface; use Heidelpay\Gateway\Block\Payment\HgwAbstract; use Heidelpay\PhpPaymentApi\PaymentMethods\PaymentMethodInterface; @@ -32,7 +58,7 @@ * @subpackage magento2 * @category magento2 */ -class HeidelpayAbstractPaymentMethod extends \Magento\Payment\Model\Method\AbstractMethod +class HeidelpayAbstractPaymentMethod extends AbstractMethod { /** * PaymentCode @@ -89,27 +115,27 @@ class HeidelpayAbstractPaymentMethod extends \Magento\Payment\Model\Method\Abstr protected $_formBlockType = HgwAbstract::class; /** - * @var \Magento\Framework\UrlInterface + * @var UrlInterface */ protected $urlBuilder; /** - * @var \Magento\Framework\App\RequestInterface + * @var RequestInterface */ protected $_requestHttp; /** - * @var \Heidelpay\Gateway\Helper\Payment + * @var Payment */ protected $_paymentHelper; /** - * @var \Heidelpay\Gateway\Helper\BasketHelper + * @var BasketHelper */ protected $basketHelper; /** - * @var \Magento\Framework\Locale\ResolverInterface + * @var ResolverInterface */ protected $_localResolver; @@ -121,43 +147,43 @@ class HeidelpayAbstractPaymentMethod extends \Magento\Payment\Model\Method\Abstr protected $_heidelpayPaymentMethod; /** - * @var \Magento\Payment\Model\Method\Logger + * @var Logger */ protected $logger; /** * Encryption & Hashing * - * @var \Magento\Framework\Encryption\Encryptor + * @var Encryptor */ protected $_encryptor; /** * Product Metadata to receive Magento information * - * @var \Magento\Framework\App\ProductMetadataInterface + * @var ProductMetadataInterface */ protected $productMetadata; - /** @var \Magento\Sales\Helper\Data */ + /** @var Data */ protected $salesHelper; /** * Resource information about modules * - * @var \Magento\Framework\Module\ResourceInterface + * @var ResourceInterface */ protected $moduleResource; /** * Factory for heidelpay payment information * - * @var \Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory + * @var PaymentInformationCollectionFactory */ protected $paymentInformationCollectionFactory; /** - * @var \Heidelpay\Gateway\Model\TransactionFactory + * @var TransactionFactory */ protected $transactionFactory; @@ -179,52 +205,52 @@ class HeidelpayAbstractPaymentMethod extends \Magento\Payment\Model\Method\Abstr /** * heidelpay Abstract Payment method constructor * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory - * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory + * @param Context $context + * @param Registry $registry + * @param ExtensionAttributesFactory $extensionFactory + * @param AttributeValueFactory $customAttributeFactory * @param \Magento\Payment\Helper\Data $paymentData * @param HgwMainConfigInterface $mainConfig - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\UrlInterface $urlinterface - * @param \Magento\Framework\Encryption\Encryptor $encryptor - * @param \Magento\Payment\Model\Method\Logger $logger - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver - * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata - * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper - * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper - * @param \Magento\Sales\Helper\Data $salesHelper + * @param RequestInterface $request + * @param UrlInterface $urlinterface + * @param Encryptor $encryptor + * @param Logger $logger + * @param ResolverInterface $localeResolver + * @param ProductMetadataInterface $productMetadata + * @param ResourceInterface $moduleResource + * @param Payment $paymentHelper + * @param BasketHelper $basketHelper + * @param Data $salesHelper * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory - * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory + * @param TransactionFactory $transactionFactory * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param AbstractResource $resource + * @param AbstractDb $resourceCollection * @param HgwBasePaymentConfigInterface $paymentConfig * @param array $data */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, - \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, + Context $context, + Registry $registry, + ExtensionAttributesFactory $extensionFactory, + AttributeValueFactory $customAttributeFactory, \Magento\Payment\Helper\Data $paymentData, HgwMainConfigInterface $mainConfig, - \Magento\Framework\App\RequestInterface $request, - \Magento\Framework\UrlInterface $urlinterface, - \Magento\Framework\Encryption\Encryptor $encryptor, - \Magento\Payment\Model\Method\Logger $logger, - \Magento\Framework\Locale\ResolverInterface $localeResolver, - \Magento\Framework\App\ProductMetadataInterface $productMetadata, - \Magento\Framework\Module\ResourceInterface $moduleResource, - \Heidelpay\Gateway\Helper\Payment $paymentHelper, - \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, - \Magento\Sales\Helper\Data $salesHelper, + RequestInterface $request, + UrlInterface $urlinterface, + Encryptor $encryptor, + Logger $logger, + ResolverInterface $localeResolver, + ProductMetadataInterface $productMetadata, + ResourceInterface $moduleResource, + Payment $paymentHelper, + BasketHelper $basketHelper, + Data $salesHelper, PaymentInformationCollectionFactory $paymentInformationCollectionFactory, - \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory, + TransactionFactory $transactionFactory, HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, $paymentConfig = null /* do not add Type or this wont work */, array $data = [] ) { @@ -280,7 +306,7 @@ public function activeRedirect() * @param integer $storeId * * @return string config value - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function getConfigData($field, $storeId = null) { @@ -298,13 +324,13 @@ public function getConfigData($field, $storeId = null) /** * @inheritdoc * - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ - public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount) + public function capture(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.')); + throw new LocalizedException(__('The capture action is not available.')); } // skip the bottom part, if the booking mode is not authorization. @@ -312,25 +338,25 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount) return $this; } - // create the transactioncollection factory to get the parent authorization. + // create the transaction collection factory to get the parent authorization. $factory = $this->transactionCollectionFactory->create(); - /** @var \Heidelpay\Gateway\Model\Transaction $transactionInfo */ + /** @var 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')); + throw new 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( + throw new LocalizedException( __('heidelpay - Cannot capture this transaction.') ); } - // set authentification data + // set authentication data $this->performAuthentication(); // set basket data @@ -350,7 +376,7 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount) // 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( + throw new LocalizedException( __('heidelpay - ' . $this->_heidelpayPaymentMethod->getResponse()->getProcessing()->getReturn()) ); } @@ -384,28 +410,28 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount) /** * @inheritdoc */ - public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount) + public function refund(InfoInterface $payment, $amount) { - /** @var \Magento\Sales\Model\Order\Payment\Interceptor $payment */ + /** @var Interceptor $payment */ if (!$this->canRefund()) { - throw new \Magento\Framework\Exception\LocalizedException(__('The refund action is not available.')); + throw new LocalizedException(__('The refund action is not available.')); } - // create the transactioncollection to get the parent authorization. + // create the transaction collection to get the parent authorization. $collection = $this->transactionCollectionFactory->create(); - /** @var \Heidelpay\Gateway\Model\Transaction $transactionInfo */ + /** @var Transaction $transactionInfo */ $transactionInfo = $collection->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')); + throw new 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( + throw new LocalizedException( __('heidelpay - Cannot refund this transaction.') ); } @@ -430,7 +456,7 @@ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount) // 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( + throw new LocalizedException( __('heidelpay - ' . $this->_heidelpayPaymentMethod->getResponse()->getProcessing()->getReturn()) ); } @@ -462,10 +488,10 @@ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount) } /** - * @param \Magento\Quote\Model\Quote $quote - * @throws \Heidelpay\PhpBasketApi\Exception\InvalidBasketitemPositionException - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Exception + * @param Quote $quote + * @throws InvalidBasketitemPositionException + * @throws LocalizedException + * @throws Exception */ public function getHeidelpayUrl($quote) { @@ -526,7 +552,7 @@ public function getHeidelpayUrl($quote) $basketId = $this->basketHelper->submitQuoteToBasketApi($quote); if ($basketId === null) { - throw new \Magento\Framework\Exception\LocalizedException(__('Error!')); + throw new LocalizedException(__('Error!')); } $this->_logger->debug('Heidelpay: New basket id is ' . $basketId); @@ -563,9 +589,9 @@ public function saveHeidelpayTransaction(Response $response, $paymentMethod, $pa } /** - * Returns the heidelpay PhpPaymentApi Paymentmethod Instance. + * Returns the heidelpay PhpPaymentApi payment method instance. * - * @return AbstractPaymentMethod|PaymentMethodInterface + * @return PaymentMethodInterface */ public function getHeidelpayPaymentMethodInstance() { @@ -595,7 +621,7 @@ public function getFrontend() /** * extract customer information from magento order object * - * @param \Magento\Quote\Api\Data\CartInterface $order object + * @param CartInterface $order object * * @return array customer information */ @@ -627,7 +653,7 @@ public function getUser($order) /** * - * @param \Magento\Sales\Model\Order $order + * @param Order $order * @param string|null $message */ public function cancelledTransactionProcessing(&$order, $message = null) @@ -643,7 +669,7 @@ public function cancelledTransactionProcessing(&$order, $message = null) /** * * @param array $data - * @param \Magento\Sales\Model\Order $order + * @param Order $order * @param string|null $message */ public function pendingTransactionProcessing($data, &$order, $message = null) @@ -659,8 +685,8 @@ public function pendingTransactionProcessing($data, &$order, $message = null) /** * @param array $data - * @param \Magento\Sales\Model\Order $order - * @throws \Magento\Framework\Exception\LocalizedException + * @param Order $order + * @throws LocalizedException */ public function processingTransactionProcessing($data, &$order) { @@ -679,9 +705,9 @@ public function processingTransactionProcessing($data, &$order) ->addStatusHistoryComment('heidelpay - ' . $message, Order::STATE_PROCESSING) ->setIsCustomerNotified(true); } else { - // in case rc is ack and amount is to low/heigh or curreny missmatch + // In case receipt is successful (ACK) and amount is to low/high or currency mismatch. $message = __( - 'Amount or currency missmatch : %1', + 'Amount or currency mismatch : %1', $data['PRESENTATION_AMOUNT'] . ' ' . $data['PRESENTATION_CURRENCY'] ); @@ -712,7 +738,7 @@ public function processingTransactionProcessing($data, &$order) * @param int $storeId * * @return string|null - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function getBookingMode($storeId = null) { @@ -733,7 +759,7 @@ public function getBookingMode($storeId = null) * * @param array $response * - * @return \Magento\Framework\Phrase|null + * @return Phrase|null */ public function additionalPaymentInformation($response) { @@ -782,7 +808,7 @@ public function prepareAdditionalFormData(Response $response) } /* - * Setup initialreques without customer data. + * Setup initial request without customer data. */ public function setupInitialRequest() { @@ -811,7 +837,7 @@ public function getConfig() } /** - * Set the parameter for async modus. + * Set the parameter for async mode. */ public function setAsync() { @@ -831,7 +857,7 @@ public function heidelpayTransactionExists($transactionID) { $collection = $this->transactionCollectionFactory->create(); - /** @var \Heidelpay\Gateway\Model\Transaction $heidelpayTransaction */ + /** @var Transaction $heidelpayTransaction */ $heidelpayTransaction = $collection->loadByTransactionId($transactionID); return !$heidelpayTransaction === null && !$heidelpayTransaction->isEmpty(); From b808faa574b624771a008ff17a666ead2974bf5b Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 24 May 2019 09:10:00 +0200 Subject: [PATCH 020/114] [refactor] Apply micro optimizations and replaced deprecated constructs. --- PaymentMethods/HeidelpayAbstractPaymentMethod.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index f88ecbf6108..d0526b981d4 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -38,7 +38,6 @@ use Magento\Sales\Helper\Data; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; -use Magento\Sales\Model\Order\Payment\Interceptor; use Magento\Store\Model\ScopeInterface as StoreScopeInterface; use Heidelpay\Gateway\Block\Payment\HgwAbstract; use Heidelpay\PhpPaymentApi\PaymentMethods\PaymentMethodInterface; @@ -412,7 +411,6 @@ public function capture(InfoInterface $payment, $amount) */ public function refund(InfoInterface $payment, $amount) { - /** @var Interceptor $payment */ if (!$this->canRefund()) { throw new LocalizedException(__('The refund action is not available.')); } @@ -572,7 +570,6 @@ public function getHeidelpayUrl($quote) */ public function saveHeidelpayTransaction(Response $response, $paymentMethod, $paymentType, $source, array $data) { - $transaction = $this->transactionFactory->create(); $transaction->setPaymentMethod($paymentMethod) ->setPaymentType($paymentType) @@ -637,7 +634,7 @@ public function getUser($order) $billingStreet .= $street . ' '; } - $user['CRITERION.GUEST'] = $order->getCustomer()->getId() == 0 ? 'true' : 'false'; + $user['CRITERION.GUEST'] = $order->getCustomer()->getId() === 0; $user['NAME.COMPANY'] = ($billing->getCompany() === false) ? null : trim($billing->getCompany()); $user['NAME.GIVEN'] = trim($billing->getFirstname()); @@ -661,7 +658,7 @@ public function cancelledTransactionProcessing(&$order, $message = null) if ($order->canCancel()) { $order->cancel() ->setState(Order::STATE_CANCELED) - ->addStatusHistoryComment('heidelpay - ' . $message, Order::STATE_CANCELED) + ->addCommentToStatusHistory('heidelpay - ' . $message, Order::STATE_CANCELED) ->setIsCustomerNotified(false); } } @@ -679,7 +676,7 @@ public function pendingTransactionProcessing($data, &$order, $message = null) $order->getPayment()->addTransaction(TransactionInterface::TYPE_AUTH, null, true); $order->setState(Order::STATE_PENDING_PAYMENT) - ->addStatusHistoryComment('heidelpay - ' . $message, Order::STATE_PENDING_PAYMENT) + ->addCommentToStatusHistory('heidelpay - ' . $message, Order::STATE_PENDING_PAYMENT) ->setIsCustomerNotified(true); } @@ -702,7 +699,7 @@ public function processingTransactionProcessing($data, &$order) && $this->_paymentHelper->isMatchingCurrency($order, $data) ) { $order->setState(Order::STATE_PROCESSING) - ->addStatusHistoryComment('heidelpay - ' . $message, Order::STATE_PROCESSING) + ->addCommentToStatusHistory('heidelpay - ' . $message, Order::STATE_PROCESSING) ->setIsCustomerNotified(true); } else { // In case receipt is successful (ACK) and amount is to low/high or currency mismatch. @@ -712,7 +709,7 @@ public function processingTransactionProcessing($data, &$order) ); $order->setState(Order::STATE_PAYMENT_REVIEW) - ->addStatusHistoryComment('heidelpay - ' . $message, Order::STATE_PAYMENT_REVIEW) + ->addCommentToStatusHistory('heidelpay - ' . $message, Order::STATE_PAYMENT_REVIEW) ->setIsCustomerNotified(true); } From 5bcbd714cd61cb4b73c63a5587357935dc7df414 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Fri, 24 May 2019 09:26:59 +0200 Subject: [PATCH 021/114] (MAGE2-191) Simplify payment Classes: Pass the heidelpayPaymentMethod parameter to payment methods as an argument in di.xml --- CHANGELOG.md | 5 +- .../HeidelpayAbstractPaymentMethod.php | 11 +- .../HeidelpayCreditCardPaymentMethod.php | 106 ++---------------- .../HeidelpayDebitCardPaymentMethod.php | 105 ++--------------- .../HeidelpayDirectDebitPaymentMethod.php | 106 ++---------------- ...idelpayDirectDebitSecuredPaymentMethod.php | 106 ++---------------- .../HeidelpayGiropayPaymentMethod.php | 97 +--------------- .../HeidelpayIDealPaymentMethod.php | 65 +---------- .../HeidelpayInvoicePaymentMethod.php | 98 +--------------- .../HeidelpayInvoiceSecuredPaymentMethod.php | 106 +++--------------- .../HeidelpayPayPalPaymentMethod.php | 105 ++--------------- .../HeidelpayPrepaymentPaymentMethod.php | 97 +--------------- .../HeidelpaySofortPaymentMethod.php | 97 +--------------- etc/di.xml | 11 ++ 14 files changed, 99 insertions(+), 1016 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c22605487a5..8bd96131e21 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,10 @@ This project does not follow a versioning standard. Versions are crafted after t ## X.X.X ### Fixed - A problem where a transaction was processed a second time via push when using "sofort". That caused the paid amount to be displayed -incorrectly. +incorrectly. + +### Changed +- Refactored paymentMethods. Simplify configuration and reduce duplicate code in payment methods. ## 19.5.8 ### Fixed diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index d1e01275bdc..0f29da6b890 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -201,6 +201,7 @@ class HeidelpayAbstractPaymentMethod extends \Magento\Payment\Model\Method\Abstr * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param HgwBasePaymentConfigInterface $paymentConfig + * @param PaymentMethodInterface $paymentMethod * @param array $data */ public function __construct( @@ -225,7 +226,8 @@ public function __construct( HeidelpayTransactionCollectionFactory $transactionCollectionFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - $paymentConfig = null /* do not add Type or this wont work */, + HgwBasePaymentConfigInterface $paymentConfig = null, + PaymentMethodInterface $paymentMethod = null, array $data = [] ) { parent::__construct( @@ -258,6 +260,9 @@ public function __construct( $this->transactionCollectionFactory = $transactionCollectionFactory; $this->mainConfig = $mainConfig; $this->paymentConfig = $paymentConfig; + + $this->_heidelpayPaymentMethod = $paymentMethod; + $this->setup(); } /** @@ -836,4 +841,8 @@ public function heidelpayTransactionExists($transactionID) return !$heidelpayTransaction === null && !$heidelpayTransaction->isEmpty(); } + + /** Override to perform additional tasks in constructor. */ + protected function setup() + {} } diff --git a/PaymentMethods/HeidelpayCreditCardPaymentMethod.php b/PaymentMethods/HeidelpayCreditCardPaymentMethod.php index 3a076b6dfc0..6969170bab3 100755 --- a/PaymentMethods/HeidelpayCreditCardPaymentMethod.php +++ b/PaymentMethods/HeidelpayCreditCardPaymentMethod.php @@ -2,11 +2,9 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; +use Heidelpay\PhpPaymentApi\PaymentMethods\CreditCardPaymentMethod; 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 @@ -48,108 +46,20 @@ class HeidelpayCreditCardPaymentMethod extends HeidelpayAbstractPaymentMethod */ protected $_canAuthorize = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canCapture = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canCapturePartial = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefund = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefundInvoicePartial = true; - /** - * HeidelpayCreditCardPaymentMethod constructor. - * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory - * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory - * @param \Magento\Payment\Helper\Data $paymentData - * @param HgwMainConfigInterface $mainConfig - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\UrlInterface $urlinterface - * @param \Magento\Framework\Encryption\Encryptor $encryptor - * @param \Magento\Payment\Model\Method\Logger $logger - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver - * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata - * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwBasePaymentConfigInterface $paymentConfig - * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper - * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper - * @param \Magento\Sales\Helper\Data $salesHelper - * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory - * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory - * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory - * @param \Heidelpay\PhpPaymentApi\PaymentMethods\CreditCardPaymentMethod $creditCardPaymentMethod - * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource - * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection - * @param array $data - */ - public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, - \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, - \Magento\Payment\Helper\Data $paymentData, - HgwMainConfigInterface $mainConfig, - \Magento\Framework\App\RequestInterface $request, - \Magento\Framework\UrlInterface $urlinterface, - \Magento\Framework\Encryption\Encryptor $encryptor, - \Magento\Payment\Model\Method\Logger $logger, - \Magento\Framework\Locale\ResolverInterface $localeResolver, - \Magento\Framework\App\ProductMetadataInterface $productMetadata, - \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwBasePaymentConfigInterface $paymentConfig, - \Heidelpay\Gateway\Helper\Payment $paymentHelper, - \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, - \Magento\Sales\Helper\Data $salesHelper, - PaymentInformationCollectionFactory $paymentInformationCollectionFactory, - \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory, - HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - \Heidelpay\PhpPaymentApi\PaymentMethods\CreditCardPaymentMethod $creditCardPaymentMethod, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] - ) { - parent::__construct( - $context, - $registry, - $extensionFactory, - $customAttributeFactory, - $paymentData, - $mainConfig, - $request, - $urlinterface, - $encryptor, - $logger, - $localeResolver, - $productMetadata, - $moduleResource, - $paymentHelper, - $basketHelper, - $salesHelper, - $paymentInformationCollectionFactory, - $transactionFactory, - $transactionCollectionFactory, - $resource, - $resourceCollection, - $paymentConfig, - $data - ); - - $this->_heidelpayPaymentMethod = $creditCardPaymentMethod; - } + /** @var CreditCardPaymentMethod */ + protected $_heidelpayPaymentMethod; /** * Active redirect diff --git a/PaymentMethods/HeidelpayDebitCardPaymentMethod.php b/PaymentMethods/HeidelpayDebitCardPaymentMethod.php index f7675f30373..dc02456d549 100755 --- a/PaymentMethods/HeidelpayDebitCardPaymentMethod.php +++ b/PaymentMethods/HeidelpayDebitCardPaymentMethod.php @@ -2,11 +2,8 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; +use Heidelpay\PhpPaymentApi\PaymentMethods\DebitCardPaymentMethod; 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 debit card payment method @@ -48,108 +45,20 @@ class HeidelpayDebitCardPaymentMethod extends HeidelpayAbstractPaymentMethod */ protected $_canAuthorize = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canCapture = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canCapturePartial = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefund = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefundInvoicePartial = true; - /** - * HeidelpayDebitCardPaymentMethod constructor. - * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory - * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory - * @param \Magento\Payment\Helper\Data $paymentData - * @param HgwMainConfigInterface $mainConfig - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\UrlInterface $urlinterface - * @param \Magento\Framework\Encryption\Encryptor $encryptor - * @param \Magento\Payment\Model\Method\Logger $logger - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver - * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata - * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwBasePaymentConfigInterface $paymentConfig - * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper - * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper - * @param \Magento\Sales\Helper\Data $salesHelper - * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory - * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory - * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory - * @param \Heidelpay\PhpPaymentApi\PaymentMethods\DebitCardPaymentMethod $debitCardPaymentMethod - * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource - * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection - * @param array $data - */ - public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, - \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, - \Magento\Payment\Helper\Data $paymentData, - HgwMainConfigInterface $mainConfig, - \Magento\Framework\App\RequestInterface $request, - \Magento\Framework\UrlInterface $urlinterface, - \Magento\Framework\Encryption\Encryptor $encryptor, - \Magento\Payment\Model\Method\Logger $logger, - \Magento\Framework\Locale\ResolverInterface $localeResolver, - \Magento\Framework\App\ProductMetadataInterface $productMetadata, - \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwBasePaymentConfigInterface $paymentConfig, - \Heidelpay\Gateway\Helper\Payment $paymentHelper, - \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, - \Magento\Sales\Helper\Data $salesHelper, - PaymentInformationCollectionFactory $paymentInformationCollectionFactory, - \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory, - HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - \Heidelpay\PhpPaymentApi\PaymentMethods\DebitCardPaymentMethod $debitCardPaymentMethod, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] - ) { - parent::__construct( - $context, - $registry, - $extensionFactory, - $customAttributeFactory, - $paymentData, - $mainConfig, - $request, - $urlinterface, - $encryptor, - $logger, - $localeResolver, - $productMetadata, - $moduleResource, - $paymentHelper, - $basketHelper, - $salesHelper, - $paymentInformationCollectionFactory, - $transactionFactory, - $transactionCollectionFactory, - $resource, - $resourceCollection, - $paymentConfig, - $data - ); - - $this->_heidelpayPaymentMethod = $debitCardPaymentMethod; - } + /** @var DebitCardPaymentMethod */ + protected $_heidelpayPaymentMethod; /** * Active redirect diff --git a/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php b/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php index 115251ded45..0429178ca4c 100755 --- a/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php +++ b/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php @@ -2,10 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; -use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; -use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; +use Heidelpay\PhpPaymentApi\PaymentMethods\DirectDebitPaymentMethod; /** * Heidelpay Direct Debit @@ -30,109 +27,20 @@ class HeidelpayDirectDebitPaymentMethod extends HeidelpayAbstractPaymentMethod */ const CODE = 'hgwdd'; - /** - * @var string heidelpay gateway payment code - */ + /** @var string heidelpay gateway payment code */ protected $_code = self::CODE; - /** - * @var bool - */ + /** @var bool */ protected $_canAuthorize = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefund = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefundInvoicePartial = true; - /** - * HeidelpayDirectDebitPaymentMethod constructor. - * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory - * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory - * @param \Magento\Payment\Helper\Data $paymentData - * @param HgwMainConfigInterface $mainConfig - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\UrlInterface $urlinterface - * @param \Magento\Framework\Encryption\Encryptor $encryptor - * @param \Magento\Payment\Model\Method\Logger $logger - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver - * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata - * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwBasePaymentConfigInterface $paymentConfig - * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper - * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper - * @param \Magento\Sales\Helper\Data $salesHelper - * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory - * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory - * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory - * @param \Heidelpay\PhpPaymentApi\PaymentMethods\DirectDebitPaymentMethod $directDebitPaymentMethod - * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource - * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection - * @param array $data - */ - public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, - \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, - \Magento\Payment\Helper\Data $paymentData, - HgwMainConfigInterface $mainConfig, - \Magento\Framework\App\RequestInterface $request, - \Magento\Framework\UrlInterface $urlinterface, - \Magento\Framework\Encryption\Encryptor $encryptor, - \Magento\Payment\Model\Method\Logger $logger, - \Magento\Framework\Locale\ResolverInterface $localeResolver, - \Magento\Framework\App\ProductMetadataInterface $productMetadata, - \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwBasePaymentConfigInterface $paymentConfig, - \Heidelpay\Gateway\Helper\Payment $paymentHelper, - \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, - \Magento\Sales\Helper\Data $salesHelper, - PaymentInformationCollectionFactory $paymentInformationCollectionFactory, - \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory, - HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - \Heidelpay\PhpPaymentApi\PaymentMethods\DirectDebitPaymentMethod $directDebitPaymentMethod, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] - ) { - parent::__construct( - $context, - $registry, - $extensionFactory, - $customAttributeFactory, - $paymentData, - $mainConfig, - $request, - $urlinterface, - $encryptor, - $logger, - $localeResolver, - $productMetadata, - $moduleResource, - $paymentHelper, - $basketHelper, - $salesHelper, - $paymentInformationCollectionFactory, - $transactionFactory, - $transactionCollectionFactory, - $resource, - $resourceCollection, - $paymentConfig, - $data - ); - - // initialize the Direct Debit payment method - $this->_heidelpayPaymentMethod = $directDebitPaymentMethod; - } + /** @var DirectDebitPaymentMethod */ + protected $_heidelpayPaymentMethod; /** * Fires the initial request to the heidelpay payment provider. diff --git a/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php b/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php index ca1cb974b83..555762f1de0 100755 --- a/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php @@ -2,10 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; -use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; -use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; +use Heidelpay\PhpPaymentApi\PaymentMethods\DirectDebitB2CSecuredPaymentMethod; /** * Heidelpay Direct Debit @@ -30,109 +27,20 @@ class HeidelpayDirectDebitSecuredPaymentMethod extends HeidelpayAbstractPaymentM */ const CODE = 'hgwdds'; - /** - * @var string heidelpay gateway payment code - */ + /** @var string heidelpay gateway payment code */ protected $_code = self::CODE; - /** - * @var bool - */ + /** @var bool */ protected $_canAuthorize = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefund = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefundInvoicePartial = true; - /** - * HeidelpayDirectDebitSecurePaymentMethod constructor. - * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory - * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory - * @param \Magento\Payment\Helper\Data $paymentData - * @param HgwMainConfigInterface $mainConfig - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\UrlInterface $urlinterface - * @param \Magento\Framework\Encryption\Encryptor $encryptor - * @param \Magento\Payment\Model\Method\Logger $logger - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver - * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata - * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwBasePaymentConfigInterface $paymentConfig - * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper - * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper - * @param \Magento\Sales\Helper\Data $salesHelper - * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory - * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory - * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory - * @param \Heidelpay\PhpPaymentApi\PaymentMethods\DirectDebitB2CSecuredPaymentMethod $directDebitB2CSecuredPaymentMethod - * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource - * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection - * @param array $data - */ - public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, - \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, - \Magento\Payment\Helper\Data $paymentData, - HgwMainConfigInterface $mainConfig, - \Magento\Framework\App\RequestInterface $request, - \Magento\Framework\UrlInterface $urlinterface, - \Magento\Framework\Encryption\Encryptor $encryptor, - \Magento\Payment\Model\Method\Logger $logger, - \Magento\Framework\Locale\ResolverInterface $localeResolver, - \Magento\Framework\App\ProductMetadataInterface $productMetadata, - \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwBasePaymentConfigInterface $paymentConfig, - \Heidelpay\Gateway\Helper\Payment $paymentHelper, - \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, - \Magento\Sales\Helper\Data $salesHelper, - PaymentInformationCollectionFactory $paymentInformationCollectionFactory, - \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory, - HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - \Heidelpay\PhpPaymentApi\PaymentMethods\DirectDebitB2CSecuredPaymentMethod $directDebitB2CSecuredPaymentMethod, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] - ) { - parent::__construct( - $context, - $registry, - $extensionFactory, - $customAttributeFactory, - $paymentData, - $mainConfig, - $request, - $urlinterface, - $encryptor, - $logger, - $localeResolver, - $productMetadata, - $moduleResource, - $paymentHelper, - $basketHelper, - $salesHelper, - $paymentInformationCollectionFactory, - $transactionFactory, - $transactionCollectionFactory, - $resource, - $resourceCollection, - $paymentConfig, - $data - ); - - // initialize the Direct Debit Secured payment method - $this->_heidelpayPaymentMethod = $directDebitB2CSecuredPaymentMethod; - } + /** @var DirectDebitB2CSecuredPaymentMethod */ + protected $_heidelpayPaymentMethod; /** * @inheritdoc diff --git a/PaymentMethods/HeidelpayGiropayPaymentMethod.php b/PaymentMethods/HeidelpayGiropayPaymentMethod.php index dc7e568c3d9..6ef89f81b26 100755 --- a/PaymentMethods/HeidelpayGiropayPaymentMethod.php +++ b/PaymentMethods/HeidelpayGiropayPaymentMethod.php @@ -2,10 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; -use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; -use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; +use Heidelpay\PhpPaymentApi\PaymentMethods\GiropayPaymentMethod; /** * heidelpay giropay Payment Method @@ -37,98 +34,14 @@ class HeidelpayGiropayPaymentMethod extends HeidelpayAbstractPaymentMethod /** @var bool */ protected $_canAuthorize = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefund = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefundInvoicePartial = true; - /** - * HeidelpayGiropayPaymentMethod constructor. - * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory - * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory - * @param \Magento\Payment\Helper\Data $paymentData - * @param HgwMainConfigInterface $mainConfig - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\UrlInterface $urlinterface - * @param \Magento\Framework\Encryption\Encryptor $encryptor - * @param \Magento\Payment\Model\Method\Logger $logger - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver - * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata - * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwBasePaymentConfigInterface $paymentConfig - * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper - * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper - * @param \Magento\Sales\Helper\Data $salesHelper - * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory - * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory - * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory - * @param \Heidelpay\PhpPaymentApi\PaymentMethods\GiropayPaymentMethod $giropayPaymentMethod - * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource - * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection - * @param array $data - */ - public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, - \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, - \Magento\Payment\Helper\Data $paymentData, - HgwMainConfigInterface $mainConfig, - \Magento\Framework\App\RequestInterface $request, - \Magento\Framework\UrlInterface $urlinterface, - \Magento\Framework\Encryption\Encryptor $encryptor, - \Magento\Payment\Model\Method\Logger $logger, - \Magento\Framework\Locale\ResolverInterface $localeResolver, - \Magento\Framework\App\ProductMetadataInterface $productMetadata, - \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwBasePaymentConfigInterface $paymentConfig, - \Heidelpay\Gateway\Helper\Payment $paymentHelper, - \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, - \Magento\Sales\Helper\Data $salesHelper, - PaymentInformationCollectionFactory $paymentInformationCollectionFactory, - \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory, - HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - \Heidelpay\PhpPaymentApi\PaymentMethods\GiropayPaymentMethod $giropayPaymentMethod, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] - ) { - parent::__construct( - $context, - $registry, - $extensionFactory, - $customAttributeFactory, - $paymentData, - $mainConfig, - $request, - $urlinterface, - $encryptor, - $logger, - $localeResolver, - $productMetadata, - $moduleResource, - $paymentHelper, - $basketHelper, - $salesHelper, - $paymentInformationCollectionFactory, - $transactionFactory, - $transactionCollectionFactory, - $resource, - $resourceCollection, - $paymentConfig, - $data - ); - - $this->_heidelpayPaymentMethod = $giropayPaymentMethod; - } + /** @var GiropayPaymentMethod */ + protected $_heidelpayPaymentMethod; /** * @inheritdoc diff --git a/PaymentMethods/HeidelpayIDealPaymentMethod.php b/PaymentMethods/HeidelpayIDealPaymentMethod.php index 1b4b2359bba..7616c07aeae 100644 --- a/PaymentMethods/HeidelpayIDealPaymentMethod.php +++ b/PaymentMethods/HeidelpayIDealPaymentMethod.php @@ -1,11 +1,8 @@ -_heidelpayPaymentMethod = $iDealPaymentMethod; - } + /** @var IDealPaymentMethod */ + protected $_heidelpayPaymentMethod; /** * @inheritdoc diff --git a/PaymentMethods/HeidelpayInvoicePaymentMethod.php b/PaymentMethods/HeidelpayInvoicePaymentMethod.php index ebcdf023982..840a70c8b85 100755 --- a/PaymentMethods/HeidelpayInvoicePaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoicePaymentMethod.php @@ -2,11 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; -use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; -use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; - +use Heidelpay\PhpPaymentApi\PaymentMethods\InvoicePaymentMethod; /** * Heidelpay prepayment payment method * @@ -53,98 +49,14 @@ class HeidelpayInvoicePaymentMethod extends HeidelpayAbstractPaymentMethod */ protected $_canAuthorize = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefund = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefundInvoicePartial = true; - /** - * HeidelpayPrepaymentPaymentMethod constructor. - * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory - * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory - * @param \Magento\Payment\Helper\Data $paymentData - * @param HgwMainConfigInterface $mainConfig - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\UrlInterface $urlinterface - * @param \Magento\Framework\Encryption\Encryptor $encryptor - * @param \Magento\Payment\Model\Method\Logger $logger - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver - * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata - * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwBasePaymentConfigInterface $paymentConfig - * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper - * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper - * @param \Magento\Sales\Helper\Data $salesHelper - * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory - * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory - * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory - * @param \Heidelpay\PhpPaymentApi\PaymentMethods\InvoicePaymentMethod $invoicePaymentMethod - * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource - * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection - * @param array $data - */ - public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, - \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, - \Magento\Payment\Helper\Data $paymentData, - HgwMainConfigInterface $mainConfig, - \Magento\Framework\App\RequestInterface $request, - \Magento\Framework\UrlInterface $urlinterface, - \Magento\Framework\Encryption\Encryptor $encryptor, - \Magento\Payment\Model\Method\Logger $logger, - \Magento\Framework\Locale\ResolverInterface $localeResolver, - \Magento\Framework\App\ProductMetadataInterface $productMetadata, - \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwBasePaymentConfigInterface $paymentConfig, - \Heidelpay\Gateway\Helper\Payment $paymentHelper, - \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, - \Magento\Sales\Helper\Data $salesHelper, - PaymentInformationCollectionFactory $paymentInformationCollectionFactory, - \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory, - HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - \Heidelpay\PhpPaymentApi\PaymentMethods\InvoicePaymentMethod $invoicePaymentMethod, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] - ) { - parent::__construct( - $context, - $registry, - $extensionFactory, - $customAttributeFactory, - $paymentData, - $mainConfig, - $request, - $urlinterface, - $encryptor, - $logger, - $localeResolver, - $productMetadata, - $moduleResource, - $paymentHelper, - $basketHelper, - $salesHelper, - $paymentInformationCollectionFactory, - $transactionFactory, - $transactionCollectionFactory, - $resource, - $resourceCollection, - $paymentConfig, - $data - ); - - $this->_heidelpayPaymentMethod = $invoicePaymentMethod; - } + /** @var InvoicePaymentMethod */ + protected $_heidelpayPaymentMethod; /** * Initial Request to heidelpay payment server to get the form / iframe url diff --git a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php index eeeb6747d1a..be2b2382c56 100755 --- a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php @@ -2,10 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; -use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; -use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; +use Heidelpay\PhpPaymentApi\PaymentMethods\InvoiceB2CSecuredPaymentMethod; /** * Heidelpay prepayment payment method @@ -58,98 +55,14 @@ class HeidelpayInvoiceSecuredPaymentMethod extends HeidelpayAbstractPaymentMetho */ protected $_canRefund = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefundInvoicePartial = true; - /** - * HeidelpayPrepaymentPaymentMethod constructor. - * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory - * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory - * @param \Magento\Payment\Helper\Data $paymentData - * @param HgwMainConfigInterface $mainConfig - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\UrlInterface $urlinterface - * @param \Magento\Framework\Encryption\Encryptor $encryptor - * @param \Magento\Payment\Model\Method\Logger $logger - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver - * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata - * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwBasePaymentConfigInterface $paymentConfig - * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper - * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper - * @param \Magento\Sales\Helper\Data $salesHelper - * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory - * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory - * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory - * @param \Heidelpay\PhpPaymentApi\PaymentMethods\InvoiceB2CSecuredPaymentMethod $invoiceB2CSecuredPaymentMethod - * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource - * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection - * @param array $data - */ - public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, - \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, - \Magento\Payment\Helper\Data $paymentData, - HgwMainConfigInterface $mainConfig, - \Magento\Framework\App\RequestInterface $request, - \Magento\Framework\UrlInterface $urlinterface, - \Magento\Framework\Encryption\Encryptor $encryptor, - \Magento\Payment\Model\Method\Logger $logger, - \Magento\Framework\Locale\ResolverInterface $localeResolver, - \Magento\Framework\App\ProductMetadataInterface $productMetadata, - \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwBasePaymentConfigInterface $paymentConfig, - \Heidelpay\Gateway\Helper\Payment $paymentHelper, - \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, - \Magento\Sales\Helper\Data $salesHelper, - PaymentInformationCollectionFactory $paymentInformationCollectionFactory, - \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory, - HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - \Heidelpay\PhpPaymentApi\PaymentMethods\InvoiceB2CSecuredPaymentMethod $invoiceB2CSecuredPaymentMethod, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] - ) { - parent::__construct( - $context, - $registry, - $extensionFactory, - $customAttributeFactory, - $paymentData, - $mainConfig, - $request, - $urlinterface, - $encryptor, - $logger, - $localeResolver, - $productMetadata, - $moduleResource, - $paymentHelper, - $basketHelper, - $salesHelper, - $paymentInformationCollectionFactory, - $transactionFactory, - $transactionCollectionFactory, - $resource, - $resourceCollection, - $paymentConfig, - $data - ); - - $this->_heidelpayPaymentMethod = $invoiceB2CSecuredPaymentMethod; - $this->setUsingBasketApi(true); - } + /** @var InvoiceB2CSecuredPaymentMethod */ + protected $_heidelpayPaymentMethod; /** - * Initial Request to heidelpay payment server to get the form / iframe url - * {@inheritDoc} + * @inheritDoc * @see \Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod::getHeidelpayUrl() */ public function getHeidelpayUrl($quote) @@ -251,4 +164,13 @@ public function pendingTransactionProcessing($data, &$order, $message = null) $this->_paymentHelper->saveTransaction($invoice); } } + + /** @inheritdoc */ + protected function setup() + { + parent::setup(); + $this->setUsingBasketApi(true); + } + + } diff --git a/PaymentMethods/HeidelpayPayPalPaymentMethod.php b/PaymentMethods/HeidelpayPayPalPaymentMethod.php index c7e977d0f1c..c95d972a8db 100755 --- a/PaymentMethods/HeidelpayPayPalPaymentMethod.php +++ b/PaymentMethods/HeidelpayPayPalPaymentMethod.php @@ -2,11 +2,8 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; +use Heidelpay\PhpPaymentApi\PaymentMethods\PayPalPaymentMethod; 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 @@ -48,108 +45,20 @@ class HeidelpayPayPalPaymentMethod extends HeidelpayAbstractPaymentMethod */ protected $_canAuthorize = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canCapture = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canCapturePartial = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefund = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefundInvoicePartial = true; - /** - * HeidelpayPayPalPaymentMethod constructor. - * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory - * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory - * @param \Magento\Payment\Helper\Data $paymentData - * @param HgwMainConfigInterface $mainConfig - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\UrlInterface $urlinterface - * @param \Magento\Framework\Encryption\Encryptor $encryptor - * @param \Magento\Payment\Model\Method\Logger $logger - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver - * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata - * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwBasePaymentConfigInterface $paymentConfig - * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper - * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper - * @param \Magento\Sales\Helper\Data $salesHelper - * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory - * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory - * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory - * @param \Heidelpay\PhpPaymentApi\PaymentMethods\PayPalPaymentMethod $payPalPaymentMethod - * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource - * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection - * @param array $data - */ - public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, - \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, - \Magento\Payment\Helper\Data $paymentData, - HgwMainConfigInterface $mainConfig, - \Magento\Framework\App\RequestInterface $request, - \Magento\Framework\UrlInterface $urlinterface, - \Magento\Framework\Encryption\Encryptor $encryptor, - \Magento\Payment\Model\Method\Logger $logger, - \Magento\Framework\Locale\ResolverInterface $localeResolver, - \Magento\Framework\App\ProductMetadataInterface $productMetadata, - \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwBasePaymentConfigInterface $paymentConfig, - \Heidelpay\Gateway\Helper\Payment $paymentHelper, - \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, - \Magento\Sales\Helper\Data $salesHelper, - PaymentInformationCollectionFactory $paymentInformationCollectionFactory, - \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory, - HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - \Heidelpay\PhpPaymentApi\PaymentMethods\PayPalPaymentMethod $payPalPaymentMethod, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] - ) { - parent::__construct( - $context, - $registry, - $extensionFactory, - $customAttributeFactory, - $paymentData, - $mainConfig, - $request, - $urlinterface, - $encryptor, - $logger, - $localeResolver, - $productMetadata, - $moduleResource, - $paymentHelper, - $basketHelper, - $salesHelper, - $paymentInformationCollectionFactory, - $transactionFactory, - $transactionCollectionFactory, - $resource, - $resourceCollection, - $paymentConfig, - $data - ); - - $this->_heidelpayPaymentMethod = $payPalPaymentMethod; - } + /** @var PayPalPaymentMethod */ + protected $_heidelpayPaymentMethod; /** * Initial Request to heidelpay payment server to get the form / iframe url diff --git a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php index 615e72279ab..4f3e2b6a051 100755 --- a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php +++ b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php @@ -2,10 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; -use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; -use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; +use Heidelpay\PhpPaymentApi\PaymentMethods\PrepaymentPaymentMethod; /** * Heidelpay prepayment payment method @@ -53,98 +50,14 @@ class HeidelpayPrepaymentPaymentMethod extends HeidelpayAbstractPaymentMethod */ protected $_canAuthorize = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefund = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefundInvoicePartial = true; - /** - * HeidelpayPrepaymentPaymentMethod constructor. - * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory - * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory - * @param \Magento\Payment\Helper\Data $paymentData - * @param HgwMainConfigInterface $mainConfig - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\UrlInterface $urlinterface - * @param \Magento\Framework\Encryption\Encryptor $encryptor - * @param \Magento\Payment\Model\Method\Logger $logger - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver - * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata - * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwBasePaymentConfigInterface $paymentConfig - * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper - * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper - * @param \Magento\Sales\Helper\Data $salesHelper - * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory - * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory - * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory - * @param \Heidelpay\PhpPaymentApi\PaymentMethods\PrepaymentPaymentMethod $prepaymentPaymentMethod - * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource - * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection - * @param array $data - */ - public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, - \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, - \Magento\Payment\Helper\Data $paymentData, - HgwMainConfigInterface $mainConfig, - \Magento\Framework\App\RequestInterface $request, - \Magento\Framework\UrlInterface $urlinterface, - \Magento\Framework\Encryption\Encryptor $encryptor, - \Magento\Payment\Model\Method\Logger $logger, - \Magento\Framework\Locale\ResolverInterface $localeResolver, - \Magento\Framework\App\ProductMetadataInterface $productMetadata, - \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwBasePaymentConfigInterface $paymentConfig, - \Heidelpay\Gateway\Helper\Payment $paymentHelper, - \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, - \Magento\Sales\Helper\Data $salesHelper, - PaymentInformationCollectionFactory $paymentInformationCollectionFactory, - \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory, - HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - \Heidelpay\PhpPaymentApi\PaymentMethods\PrepaymentPaymentMethod $prepaymentPaymentMethod, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] - ) { - parent::__construct( - $context, - $registry, - $extensionFactory, - $customAttributeFactory, - $paymentData, - $mainConfig, - $request, - $urlinterface, - $encryptor, - $logger, - $localeResolver, - $productMetadata, - $moduleResource, - $paymentHelper, - $basketHelper, - $salesHelper, - $paymentInformationCollectionFactory, - $transactionFactory, - $transactionCollectionFactory, - $resource, - $resourceCollection, - $paymentConfig, - $data - ); - - $this->_heidelpayPaymentMethod = $prepaymentPaymentMethod; - } + /** @var PrepaymentPaymentMethod */ + protected $_heidelpayPaymentMethod; /** * Initial Request to heidelpay payment server to get the form / iframe url diff --git a/PaymentMethods/HeidelpaySofortPaymentMethod.php b/PaymentMethods/HeidelpaySofortPaymentMethod.php index cdfb586cf09..e0eea649c46 100755 --- a/PaymentMethods/HeidelpaySofortPaymentMethod.php +++ b/PaymentMethods/HeidelpaySofortPaymentMethod.php @@ -2,11 +2,7 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; -use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; -use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; - +use Heidelpay\PhpPaymentApi\PaymentMethods\SofortPaymentMethod; /** * heidelpay sofort payment method * @@ -48,97 +44,14 @@ class HeidelpaySofortPaymentMethod extends HeidelpayAbstractPaymentMethod protected $_canAuthorize = true; /** - * @var boolean - */ + * @var boolean */ protected $_canRefund = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefundInvoicePartial = true; - /** - * HeidelpaySofortPaymentMethod constructor. - * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory - * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory - * @param \Magento\Payment\Helper\Data $paymentData - * @param HgwMainConfigInterface $mainConfig - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Framework\UrlInterface $urlinterface - * @param \Magento\Framework\Encryption\Encryptor $encryptor - * @param \Magento\Payment\Model\Method\Logger $logger - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver - * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata - * @param \Magento\Framework\Module\ResourceInterface $moduleResource - * @param HgwBasePaymentConfigInterface $paymentConfig - * @param \Heidelpay\Gateway\Helper\Payment $paymentHelper - * @param \Heidelpay\Gateway\Helper\BasketHelper $basketHelper - * @param \Magento\Sales\Helper\Data $salesHelper - * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory - * @param \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory - * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory - * @param \Heidelpay\PhpPaymentApi\PaymentMethods\SofortPaymentMethod $sofortPaymentMethod - * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource - * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection - * @param array $data - */ - public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, - \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, - \Magento\Payment\Helper\Data $paymentData, - HgwMainConfigInterface $mainConfig, - \Magento\Framework\App\RequestInterface $request, - \Magento\Framework\UrlInterface $urlinterface, - \Magento\Framework\Encryption\Encryptor $encryptor, - \Magento\Payment\Model\Method\Logger $logger, - \Magento\Framework\Locale\ResolverInterface $localeResolver, - \Magento\Framework\App\ProductMetadataInterface $productMetadata, - \Magento\Framework\Module\ResourceInterface $moduleResource, - HgwBasePaymentConfigInterface $paymentConfig, - \Heidelpay\Gateway\Helper\Payment $paymentHelper, - \Heidelpay\Gateway\Helper\BasketHelper $basketHelper, - \Magento\Sales\Helper\Data $salesHelper, - PaymentInformationCollectionFactory $paymentInformationCollectionFactory, - \Heidelpay\Gateway\Model\TransactionFactory $transactionFactory, - HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - \Heidelpay\PhpPaymentApi\PaymentMethods\SofortPaymentMethod $sofortPaymentMethod, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] - ) { - parent::__construct( - $context, - $registry, - $extensionFactory, - $customAttributeFactory, - $paymentData, - $mainConfig, - $request, - $urlinterface, - $encryptor, - $logger, - $localeResolver, - $productMetadata, - $moduleResource, - $paymentHelper, - $basketHelper, - $salesHelper, - $paymentInformationCollectionFactory, - $transactionFactory, - $transactionCollectionFactory, - $resource, - $resourceCollection, - $paymentConfig, - $data - ); - - $this->_heidelpayPaymentMethod = $sofortPaymentMethod; - } + /** @var SofortPaymentMethod */ + protected $_heidelpayPaymentMethod; /** * Initial Request to heidelpay payment server to get the form / iframe url diff --git a/etc/di.xml b/etc/di.xml index f4dfc03724f..1537975415f 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -17,56 +17,67 @@ HgwCreditCardConfig + Heidelpay\PhpPaymentApi\PaymentMethods\CreditCardPaymentMethod HgwDebitCardConfig + Heidelpay\PhpPaymentApi\PaymentMethods\DebitCardPaymentMethod HgwDirectDebitConfig + Heidelpay\PhpPaymentApi\PaymentMethods\DirectDebitPaymentMethod HgwDirectDebitSecuredConfig + Heidelpay\PhpPaymentApi\PaymentMethods\DirectDebitB2CSecuredPaymentMethod HgwGiropayConfig + Heidelpay\PhpPaymentApi\PaymentMethods\GiropayPaymentMethod HgwIDealConfig + Heidelpay\PhpPaymentApi\PaymentMethods\IDealPaymentMethod HgwInvoiceConfig + Heidelpay\PhpPaymentApi\PaymentMethods\InvoicePaymentMethod HgwInvoiceSecuredConfig + Heidelpay\PhpPaymentApi\PaymentMethods\InvoiceB2CSecuredPaymentMethod HgwPayPalConfig + Heidelpay\PhpPaymentApi\PaymentMethods\PayPalPaymentMethod HgwPrepaymentConfig + Heidelpay\PhpPaymentApi\PaymentMethods\PrepaymentPaymentMethod HgwSofortConfig + Heidelpay\PhpPaymentApi\PaymentMethods\SofortPaymentMethod From 5566aa155e8898bac0d582984c3e88a155d7a1ca Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 24 May 2019 13:03:47 +0200 Subject: [PATCH 022/114] [refactor] (MAGE2-175) Santander Hire Purchase: Simplify payment methods. --- .../HeidelpayAbstractPaymentMethod.php | 208 ++++++++---------- .../HeidelpayCreditCardPaymentMethod.php | 39 +--- .../HeidelpayDebitCardPaymentMethod.php | 38 +--- .../HeidelpayDirectDebitPaymentMethod.php | 39 ++-- ...idelpayDirectDebitSecuredPaymentMethod.php | 25 +-- .../HeidelpayGiropayPaymentMethod.php | 20 +- .../HeidelpayIDealPaymentMethod.php | 32 ++- .../HeidelpayInvoicePaymentMethod.php | 49 ++--- .../HeidelpayInvoiceSecuredPaymentMethod.php | 60 +++-- .../HeidelpayPayPalPaymentMethod.php | 40 ++-- .../HeidelpayPrepaymentPaymentMethod.php | 50 ++--- ...lpaySantanderHirePurchasePaymentMethod.php | 116 ++-------- .../HeidelpaySofortPaymentMethod.php | 33 +-- composer.json | 3 +- etc/di.xml | 6 + 15 files changed, 278 insertions(+), 480 deletions(-) diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 57b2bd4eae4..32b97252be2 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -6,9 +6,10 @@ use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; use Heidelpay\Gateway\Helper\BasketHelper; -use Heidelpay\Gateway\Helper\Payment; +use Heidelpay\Gateway\Helper\Payment as PaymentHelper; use Heidelpay\Gateway\Model\Config\Source\BookingMode; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; +use Heidelpay\Gateway\Model\ResourceModel\Transaction\Collection as TransactionCollection; use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; use Heidelpay\Gateway\Model\Transaction; use Heidelpay\Gateway\Model\TransactionFactory; @@ -29,19 +30,26 @@ use Magento\Framework\Phrase; use Magento\Framework\Registry; use Magento\Framework\UrlInterface; +use Magento\Payment\Helper\Data as DataHelper; use Magento\Payment\Model\InfoInterface; use Magento\Payment\Model\Method\AbstractMethod; use Magento\Payment\Model\Method\Logger; +use Magento\Quote\Api\Data\AddressInterface; use Magento\Quote\Api\Data\CartInterface; use Magento\Quote\Model\Quote; +use Magento\Sales\Api\Data\OrderPaymentInterface; use Magento\Sales\Api\Data\TransactionInterface; use Magento\Sales\Helper\Data; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; +use Magento\Sales\Model\Order\Payment; +use Magento\Sales\Model\Spi\OrderPaymentResourceInterface; +use Magento\Sales\Model\Spi\TransactionResourceInterface; use Magento\Store\Model\ScopeInterface as StoreScopeInterface; use Heidelpay\Gateway\Block\Payment\HgwAbstract; use Heidelpay\PhpPaymentApi\PaymentMethods\PaymentMethodInterface; use Magento\Store\Model\ScopeInterface; +use RuntimeException; /** * Heidelpay abstract payment method @@ -59,147 +67,95 @@ */ class HeidelpayAbstractPaymentMethod extends AbstractMethod { - /** - * PaymentCode - * - * @var string - */ + /** @var string PaymentCode */ const CODE = 'hgwabstract'; - /** - * PaymentCode - * - * @var string - */ + /** @var string PaymentCode */ protected $_code = self::CODE; - /** - * @var boolean - */ + /** @var boolean */ protected $_isGateway = true; - /** - * @var boolean - */ + /** @var boolean */ protected $_canCapture = false; - /** - * @var boolean - */ + /** @var boolean */ protected $_canCapturePartial = false; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefund = false; - /** - * @var boolean - */ + /** @var boolean */ protected $_canRefundInvoicePartial = false; - /** - * @var boolean - */ + /** @var boolean */ protected $_canUseInternal = false; - /** - * @var boolean - */ + /** @var boolean */ private $usingBasketApi = false; - /** - * @var string - */ + /** @var string */ protected $_formBlockType = HgwAbstract::class; - /** - * @var UrlInterface - */ + /** @var UrlInterface */ protected $urlBuilder; - /** - * @var RequestInterface - */ + /** @var RequestInterface */ protected $_requestHttp; - /** - * @var Payment - */ + /** @var PaymentHelper */ protected $_paymentHelper; - /** - * @var BasketHelper - */ + /** @var BasketHelper */ protected $basketHelper; - /** - * @var ResolverInterface - */ + /** @var ResolverInterface */ protected $_localResolver; - /** - * The used heidelpay payment method - * - * @var PaymentMethodInterface $_heidelpayPaymentMethod - */ + /** @var PaymentMethodInterface $_heidelpayPaymentMethod The used heidelpay payment method */ protected $_heidelpayPaymentMethod; - /** - * @var Logger - */ + /** @var Logger */ protected $logger; - /** - * Encryption & Hashing - * - * @var Encryptor - */ + /** @var Encryptor $_encryptor Encryption & Hashing */ protected $_encryptor; - /** - * Product Metadata to receive Magento information - * - * @var ProductMetadataInterface - */ + /** @var ProductMetadataInterface $productMetadata Product Metadata to receive Magento information */ protected $productMetadata; /** @var Data */ protected $salesHelper; - /** - * Resource information about modules - * - * @var ResourceInterface - */ + /** @var ResourceInterface $moduleResource Resource information about modules */ protected $moduleResource; /** * Factory for heidelpay payment information * - * @var PaymentInformationCollectionFactory + * @var PaymentInformationCollectionFactory $paymentInformationCollectionFactory */ protected $paymentInformationCollectionFactory; - /** - * @var TransactionFactory - */ + /** @var TransactionFactory */ protected $transactionFactory; - /** - * @var HeidelpayTransactionCollectionFactory - */ + /** @var HeidelpayTransactionCollectionFactory */ protected $transactionCollectionFactory; - /** - * @var HgwMainConfigInterface - */ + /** @var HgwMainConfigInterface */ protected $mainConfig; + /** @var HgwBasePaymentConfigInterface */ + private $paymentConfig; /** - * @var HgwBasePaymentConfigInterface + * @var OrderPaymentResourceInterface */ - private $paymentConfig; + private $paymentResource; + /** + * @var TransactionResourceInterface + */ + private $transactionResource; /** * heidelpay Abstract Payment method constructor @@ -208,7 +164,7 @@ class HeidelpayAbstractPaymentMethod extends AbstractMethod * @param Registry $registry * @param ExtensionAttributesFactory $extensionFactory * @param AttributeValueFactory $customAttributeFactory - * @param \Magento\Payment\Helper\Data $paymentData + * @param DataHelper $paymentData * @param HgwMainConfigInterface $mainConfig * @param RequestInterface $request * @param UrlInterface $urlinterface @@ -217,12 +173,14 @@ class HeidelpayAbstractPaymentMethod extends AbstractMethod * @param ResolverInterface $localeResolver * @param ProductMetadataInterface $productMetadata * @param ResourceInterface $moduleResource - * @param Payment $paymentHelper + * @param PaymentHelper $paymentHelper * @param BasketHelper $basketHelper * @param Data $salesHelper * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory * @param TransactionFactory $transactionFactory * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory + * @param OrderPaymentResourceInterface $paymentResource + * @param TransactionResourceInterface $transactionResource * @param AbstractResource $resource * @param AbstractDb $resourceCollection * @param HgwBasePaymentConfigInterface $paymentConfig @@ -234,7 +192,7 @@ public function __construct( Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, - \Magento\Payment\Helper\Data $paymentData, + DataHelper $paymentData, HgwMainConfigInterface $mainConfig, RequestInterface $request, UrlInterface $urlinterface, @@ -243,14 +201,16 @@ public function __construct( ResolverInterface $localeResolver, ProductMetadataInterface $productMetadata, ResourceInterface $moduleResource, - Payment $paymentHelper, + PaymentHelper $paymentHelper, BasketHelper $basketHelper, Data $salesHelper, PaymentInformationCollectionFactory $paymentInformationCollectionFactory, TransactionFactory $transactionFactory, HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + OrderPaymentResourceInterface $paymentResource, + TransactionResourceInterface $transactionResource, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, HgwBasePaymentConfigInterface $paymentConfig = null, PaymentMethodInterface $paymentMethod = null, array $data = [] @@ -279,6 +239,8 @@ public function __construct( $this->_localResolver = $localeResolver; $this->productMetadata = $productMetadata; $this->moduleResource = $moduleResource; + $this->paymentResource = $paymentResource; + $this->transactionResource = $transactionResource; $this->paymentInformationCollectionFactory = $paymentInformationCollectionFactory; $this->transactionFactory = $transactionFactory; @@ -332,7 +294,7 @@ public function getConfigData($field, $storeId = null) */ public function capture(InfoInterface $payment, $amount) { - /** @var \Magento\Sales\Model\Order\Payment $payment */ + /** @var Payment $payment */ if (!$this->canCapture()) { throw new LocalizedException(__('The capture action is not available.')); } @@ -406,7 +368,7 @@ public function capture(InfoInterface $payment, $amount) // set the last transaction id to the Pre-Authorization. $payment->setLastTransId($this->_heidelpayPaymentMethod->getResponse()->getPaymentReferenceId()); - $payment->save(); + $this->paymentResource->save($payment); return $this; } @@ -416,6 +378,7 @@ public function capture(InfoInterface $payment, $amount) */ public function refund(InfoInterface $payment, $amount) { + /** @var Payment $payment */ if (!$this->canRefund()) { throw new LocalizedException(__('The refund action is not available.')); } @@ -485,7 +448,7 @@ public function refund(InfoInterface $payment, $amount) // set the last transaction id to the Pre-Authorization. $payment->setLastTransId($this->_heidelpayPaymentMethod->getResponse()->getPaymentReferenceId()); - $payment->save(); + $this->paymentResource->save($payment); return $this; } @@ -572,9 +535,11 @@ public function getHeidelpayUrl($quote) * @param $paymentType * @param string $source * @param array $data + * @throws Exception */ public function saveHeidelpayTransaction(Response $response, $paymentMethod, $paymentType, $source, array $data) { + /** @var Transaction $transaction */ $transaction = $this->transactionFactory->create(); $transaction->setPaymentMethod($paymentMethod) ->setPaymentType($paymentType) @@ -586,8 +551,9 @@ public function saveHeidelpayTransaction(Response $response, $paymentMethod, $pa ->setReturnMessage($response->getProcessing()->getReturn()) ->setReturnCode($response->getProcessing()->getReturnCode()) ->setJsonResponse(json_encode($data)) - ->setSource($source) - ->save(); + ->setSource($source); + + $this->transactionResource->save($transaction); } /** @@ -631,30 +597,30 @@ public function getUser($order) { $user = []; $billing = $order->getBillingAddress(); - $email = $order->getBillingAddress()->getEmail(); + if (!$billing instanceof AddressInterface) { + throw new RuntimeException('heidelpay - Error billing address is not set!'); + } $billingStreet = ''; - foreach ($billing->getStreet() as $street) { $billingStreet .= $street . ' '; } $user['CRITERION.GUEST'] = $order->getCustomer()->getId() === 0; - $user['NAME.COMPANY'] = ($billing->getCompany() === false) ? null : trim($billing->getCompany()); - $user['NAME.GIVEN'] = trim($billing->getFirstname()); - $user['NAME.FAMILY'] = trim($billing->getLastname()); - $user['ADDRESS.STREET'] = trim($billingStreet); - $user['ADDRESS.ZIP'] = trim($billing->getPostcode()); - $user['ADDRESS.CITY'] = trim($billing->getCity()); + $user['NAME.COMPANY'] = ($billing->getCompany() === false) ? null : trim($billing->getCompany()); + $user['NAME.GIVEN'] = trim($billing->getFirstname()); + $user['NAME.FAMILY'] = trim($billing->getLastname()); + $user['ADDRESS.STREET'] = trim($billingStreet); + $user['ADDRESS.ZIP'] = trim($billing->getPostcode()); + $user['ADDRESS.CITY'] = trim($billing->getCity()); $user['ADDRESS.COUNTRY'] = trim($billing->getCountryId()); - $user['CONTACT.EMAIL'] = trim($email); + $user['CONTACT.EMAIL'] = trim($billing->getEmail()); return $user; } /** - * * @param Order $order * @param string|null $message */ @@ -670,15 +636,20 @@ public function cancelledTransactionProcessing(&$order, $message = null) /** * - * @param array $data - * @param Order $order - * @param string|null $message + * @param array $data + * @param Order $order + * @param string|null $message */ public function pendingTransactionProcessing($data, &$order, $message = null) { - $order->getPayment()->setTransactionId($data['IDENTIFICATION_UNIQUEID']); - $order->getPayment()->setIsTransactionClosed(false); - $order->getPayment()->addTransaction(TransactionInterface::TYPE_AUTH, null, true); + $orderPayment = $order->getPayment(); + if (!$orderPayment instanceof OrderPaymentInterface) { + throw new RuntimeException('heidelpay - Error: Payment is not set.'); + } + + $orderPayment->setTransactionId($data['IDENTIFICATION_UNIQUEID']); + $orderPayment->setIsTransactionClosed(false); + $orderPayment->addTransaction(TransactionInterface::TYPE_AUTH, null, true); $order->setState(Order::STATE_PENDING_PAYMENT) ->addCommentToStatusHistory('heidelpay - ' . $message, Order::STATE_PENDING_PAYMENT) @@ -694,10 +665,10 @@ public function processingTransactionProcessing($data, &$order) { $message = __('ShortId : %1', $data['IDENTIFICATION_SHORTID']); - $order->getPayment() - ->setTransactionId($data['IDENTIFICATION_UNIQUEID']) - ->setParentTransactionId($order->getPayment()->getLastTransId()) - ->setIsTransactionClosed(true); + $payment = $order->getPayment(); + $payment->setTransactionId($data['IDENTIFICATION_UNIQUEID']) + ->setParentTransactionId($payment->getLastTransId()) + ->setIsTransactionClosed(true); // if the total sum of the order matches the presentation amount of the heidelpay response... if ($this->_paymentHelper->isMatchingAmount($order, $data) @@ -730,7 +701,7 @@ public function processingTransactionProcessing($data, &$order) $this->_paymentHelper->saveTransaction($invoice); } - $order->getPayment()->addTransaction(TransactionInterface::TYPE_CAPTURE, null, true); + $payment->addTransaction(TransactionInterface::TYPE_CAPTURE, null, true); } /** @@ -754,8 +725,6 @@ public function getBookingMode($storeId = null) } /** - * Additional payment information - * * This function will return a text message used to show payment information * to your customer on the checkout success page * @@ -857,6 +826,7 @@ public function setAsync() */ public function heidelpayTransactionExists($transactionID) { + /** @var TransactionCollection $collection */ $collection = $this->transactionCollectionFactory->create(); /** @var Transaction $heidelpayTransaction */ diff --git a/PaymentMethods/HeidelpayCreditCardPaymentMethod.php b/PaymentMethods/HeidelpayCreditCardPaymentMethod.php index f04e14934cc..a40bd051fce 100755 --- a/PaymentMethods/HeidelpayCreditCardPaymentMethod.php +++ b/PaymentMethods/HeidelpayCreditCardPaymentMethod.php @@ -1,14 +1,5 @@ mainConfig->getDefaultCss(); + $bookingMode = $this->getBookingMode(); // make an authorize request, if set... - if ($this->getBookingMode() === BookingMode::AUTHORIZATION) { + if ($bookingMode === 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) { + if ($bookingMode === null || $bookingMode === BookingMode::DEBIT) { $this->_heidelpayPaymentMethod->debit($paymentFrameOrigin, $preventAsyncRedirect, $cssPath); } diff --git a/PaymentMethods/HeidelpayDebitCardPaymentMethod.php b/PaymentMethods/HeidelpayDebitCardPaymentMethod.php index 489724bfb67..a4cadc47485 100755 --- a/PaymentMethods/HeidelpayDebitCardPaymentMethod.php +++ b/PaymentMethods/HeidelpayDebitCardPaymentMethod.php @@ -1,13 +1,5 @@ mainConfig->getDefaultCss(); + $bookingMode = $this->getBookingMode(); // make an authorize request, if set... - if ($this->getBookingMode() === BookingMode::AUTHORIZATION) { + if ($bookingMode === 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) { + if ($bookingMode === null || $bookingMode === BookingMode::DEBIT) { $this->_heidelpayPaymentMethod->debit($paymentFrameOrigin, $preventAsyncRedirect, $cssPath); } diff --git a/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php b/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php index e88c317e7a6..d6c2ca7a2da 100755 --- a/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php +++ b/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php @@ -1,12 +1,5 @@ paymentInformationCollectionFactory->create(); // load the payment information by store id, customer email address and payment method - /** @var \Heidelpay\Gateway\Model\PaymentInformation $paymentInfo */ + /** @var PaymentInformation $paymentInfo */ $paymentInfo = $paymentInfoCollection->loadByCustomerInformation( $quote->getStoreId(), $quote->getBillingAddress()->getEmail(), diff --git a/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php b/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php index b6e08c371be..a570b9dad68 100755 --- a/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php @@ -1,12 +1,5 @@ paymentInformationCollectionFactory->create(); // load the payment information by store id, customer email address and payment method - /** @var \Heidelpay\Gateway\Model\PaymentInformation $paymentInfo */ + /** @var PaymentInformation $paymentInfo */ $paymentInfo = $paymentInfoCollection->loadByCustomerInformation( $quote->getStoreId(), $quote->getBillingAddress()->getEmail(), @@ -72,7 +67,7 @@ public function getHeidelpayUrl($quote) ->set('holder', $paymentInfo->getAdditionalData()->hgw_holder); } - // add salutation and birthdate to the request + // add salutation and date of birth to the request if (isset($paymentInfo->getAdditionalData()->hgw_salutation)) { $this->_heidelpayPaymentMethod->getRequest()->getName() ->set('salutation', $paymentInfo->getAdditionalData()->hgw_salutation); @@ -115,7 +110,7 @@ public function additionalPaymentInformation($response) * * @inheritdoc */ - public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) + public function isAvailable(CartInterface $quote = null) { // in B2C payment methods, we don't want companies to be involved. // so, if the address contains a company, return false. diff --git a/PaymentMethods/HeidelpayGiropayPaymentMethod.php b/PaymentMethods/HeidelpayGiropayPaymentMethod.php index 1128b9acc63..fb239e928fa 100755 --- a/PaymentMethods/HeidelpayGiropayPaymentMethod.php +++ b/PaymentMethods/HeidelpayGiropayPaymentMethod.php @@ -1,12 +1,5 @@ paymentInformationCollectionFactory->create(); // load the payment information by store id, customer email address and payment method - /** @var \Heidelpay\Gateway\Model\PaymentInformation $paymentInfo */ + /** @var PaymentInformation $paymentInfo */ $paymentInfo = $paymentInfoCollection->loadByCustomerInformation( $quote->getStoreId(), $quote->getBillingAddress()->getEmail(), @@ -96,13 +95,12 @@ public function getHeidelpayUrl($quote) return $this->_heidelpayPaymentMethod->getResponse(); } - public function activeRedirect() - { - return true; - } - - /* + /** * Send an authorize request to get a response which contains list of available banks. + * + * @return Response + * + * @throws UndefinedTransactionModeException */ public function initMethod() { diff --git a/PaymentMethods/HeidelpayInvoicePaymentMethod.php b/PaymentMethods/HeidelpayInvoicePaymentMethod.php index 840a70c8b85..17f8df4e5d9 100755 --- a/PaymentMethods/HeidelpayInvoicePaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoicePaymentMethod.php @@ -1,11 +1,5 @@ getPayment()->setTransactionId($data['IDENTIFICATION_UNIQUEID']); - $order->getPayment()->setIsTransactionClosed(false); - $order->getPayment()->addTransaction(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_AUTH, null, true); + $payment = $order->getPayment(); + $payment->setTransactionId($data['IDENTIFICATION_UNIQUEID']); + $payment->setIsTransactionClosed(false); + $payment->addTransaction(Transaction::TYPE_AUTH, null, true); - $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING) - ->addStatusHistoryComment($message, \Magento\Sales\Model\Order::STATE_PROCESSING) + $order->setState(Order::STATE_PROCESSING) + ->addCommentToStatusHistory($message, Order::STATE_PROCESSING) ->setIsCustomerNotified(true); // payment is pending at the beginning, so we set the total paid sum to 0. @@ -112,7 +103,7 @@ public function pendingTransactionProcessing($data, &$order, $message = null) // 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) + $invoice->setRequestedCaptureCase(Invoice::CAPTURE_ONLINE) ->setTransactionId($data['IDENTIFICATION_UNIQUEID']) ->setIsPaid(false) ->register(); diff --git a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php index be2b2382c56..3cfbebcd11a 100755 --- a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php @@ -1,12 +1,5 @@ paymentInformationCollectionFactory->create(); // load the payment information by store id, customer email address and payment method - /** @var \Heidelpay\Gateway\Model\PaymentInformation $paymentInfo */ + /** @var PaymentInformation $paymentInfo */ $paymentInfo = $paymentInfoCollection->loadByCustomerInformation( $quote->getStoreId(), $quote->getBillingAddress()->getEmail(), @@ -125,7 +114,7 @@ public function additionalPaymentInformation($response) * * @inheritdoc */ - public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) + public function isAvailable(CartInterface $quote = null) { // in B2C payment methods, we don't want companies to be involved. // so, if the address contains a company, return false. @@ -142,12 +131,13 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) */ 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); + $payment = $order->getPayment(); + $payment->setTransactionId($data['IDENTIFICATION_UNIQUEID']); + $payment->setIsTransactionClosed(false); + $payment->addTransaction(Transaction::TYPE_AUTH, null, true); - $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING) - ->addStatusHistoryComment($message, \Magento\Sales\Model\Order::STATE_PROCESSING) + $order->setState(Order::STATE_PROCESSING) + ->addCommentToStatusHistory($message, Order::STATE_PROCESSING) ->setIsCustomerNotified(true); // payment is pending at the beginning, so we set the total paid sum to 0. @@ -156,7 +146,7 @@ public function pendingTransactionProcessing($data, &$order, $message = null) // 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) + $invoice->setRequestedCaptureCase(Invoice::CAPTURE_ONLINE) ->setTransactionId($data['IDENTIFICATION_UNIQUEID']) ->setIsPaid(false) ->register(); diff --git a/PaymentMethods/HeidelpayPayPalPaymentMethod.php b/PaymentMethods/HeidelpayPayPalPaymentMethod.php index f6afe2a4f59..f1f4d076bc1 100755 --- a/PaymentMethods/HeidelpayPayPalPaymentMethod.php +++ b/PaymentMethods/HeidelpayPayPalPaymentMethod.php @@ -1,14 +1,6 @@ getBookingMode(); // make an authorize request, if set... - if ($this->getBookingMode() === BookingMode::AUTHORIZATION) { + if ($bookingMode === 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) { + if ($bookingMode === null || $bookingMode === BookingMode::DEBIT) { $this->_heidelpayPaymentMethod->debit(); } diff --git a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php index 72d673c6f94..4c5a02a5a95 100755 --- a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php +++ b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php @@ -1,12 +1,5 @@ getPayment()->setTransactionId($data['IDENTIFICATION_UNIQUEID']); - $order->getPayment()->setIsTransactionClosed(false); - $order->getPayment()->addTransaction(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_AUTH, null, true); + $payment = $order->getPayment(); + $payment->setTransactionId($data['IDENTIFICATION_UNIQUEID']); + $payment->setIsTransactionClosed(false); + $payment->addTransaction(Transaction::TYPE_AUTH, null, true); - $order->setState(\Magento\Sales\Model\Order::STATE_PENDING_PAYMENT) - ->addStatusHistoryComment($message, \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT) + $order->setState(Order::STATE_PENDING_PAYMENT) + ->addCommentToStatusHistory($message, Order::STATE_PENDING_PAYMENT) ->setIsCustomerNotified(true); // payment is pending at the beginning, so we set the total paid sum to 0. @@ -111,7 +101,7 @@ public function pendingTransactionProcessing($data, &$order, $message = null) // 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) + $invoice->setRequestedCaptureCase(Invoice::CAPTURE_ONLINE) ->setTransactionId($data['IDENTIFICATION_UNIQUEID']) ->setIsPaid(false) ->register(); diff --git a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php index c5df4a64417..f63e33be617 100755 --- a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php +++ b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php @@ -15,28 +15,8 @@ */ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; -use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; -use Heidelpay\Gateway\Helper\BasketHelper; -use Heidelpay\Gateway\Helper\Payment; -use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; -use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; -use Heidelpay\Gateway\Model\TransactionFactory; use Heidelpay\PhpPaymentApi\PaymentMethods\SantanderHirePurchasePaymentMethod; -use Magento\Framework\Api\AttributeValueFactory; -use Magento\Framework\Api\ExtensionAttributesFactory; -use Magento\Framework\App\ProductMetadataInterface; -use Magento\Framework\App\RequestInterface; -use Magento\Framework\Data\Collection\AbstractDb; -use Magento\Framework\Encryption\Encryptor; -use Magento\Framework\Locale\ResolverInterface; -use Magento\Framework\Model\Context; -use Magento\Framework\Model\ResourceModel\AbstractResource; -use Magento\Framework\Module\ResourceInterface; -use Magento\Framework\Registry; -use Magento\Framework\UrlInterface; -use Magento\Payment\Helper\Data; -use Magento\Payment\Model\Method\Logger; +use Magento\Quote\Api\Data\CartInterface; class HeidelpaySantanderHirePurchasePaymentMethod extends HeidelpayAbstractPaymentMethod { @@ -58,85 +38,27 @@ class HeidelpaySantanderHirePurchasePaymentMethod extends HeidelpayAbstractPayme /** @var boolean $_canRefundInvoicePartial */ protected $_canRefundInvoicePartial = true; + /** @var SantanderHirePurchasePaymentMethod */ + protected $_heidelpayPaymentMethod; + /** - * @param Context $context - * @param Registry $registry - * @param ExtensionAttributesFactory $extensionFactory - * @param AttributeValueFactory $customAttributeFactory - * @param Data $paymentData - * @param HgwMainConfigInterface $mainConfig - * @param RequestInterface $request - * @param UrlInterface $urlinterface - * @param Encryptor $encryptor - * @param Logger $logger - * @param ResolverInterface $localeResolver - * @param ProductMetadataInterface $productMetadata - * @param ResourceInterface $moduleResource - * @param HgwBasePaymentConfigInterface $paymentConfig - * @param Payment $paymentHelper - * @param BasketHelper $basketHelper - * @param \Magento\Sales\Helper\Data $salesHelper - * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory - * @param TransactionFactory $transactionFactory - * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory - * @param SantanderHirePurchasePaymentMethod $paymentMethod - * @param AbstractResource|null $resource - * @param AbstractDb|null $resourceCollection - * @param array $data + * Determines if the payment method will be displayed at the checkout. + * For B2C methods, the payment method should not be displayed. + * + * Else, refer to the parent isActive method. + * + * @inheritdoc */ - public function __construct( - Context $context, - Registry $registry, - ExtensionAttributesFactory $extensionFactory, - AttributeValueFactory $customAttributeFactory, - Data $paymentData, - HgwMainConfigInterface $mainConfig, - RequestInterface $request, - UrlInterface $urlinterface, - Encryptor $encryptor, - Logger $logger, - ResolverInterface $localeResolver, - ProductMetadataInterface $productMetadata, - ResourceInterface $moduleResource, - HgwBasePaymentConfigInterface $paymentConfig, - Payment $paymentHelper, - BasketHelper $basketHelper, - \Magento\Sales\Helper\Data $salesHelper, - PaymentInformationCollectionFactory $paymentInformationCollectionFactory, - TransactionFactory $transactionFactory, - HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - SantanderHirePurchasePaymentMethod $paymentMethod, - AbstractResource $resource = null, - AbstractDb $resourceCollection = null, - array $data = [] - ) { - parent::__construct( - $context, - $registry, - $extensionFactory, - $customAttributeFactory, - $paymentData, - $mainConfig, - $request, - $urlinterface, - $encryptor, - $logger, - $localeResolver, - $productMetadata, - $moduleResource, - $paymentHelper, - $basketHelper, - $salesHelper, - $paymentInformationCollectionFactory, - $transactionFactory, - $transactionCollectionFactory, - $resource, - $resourceCollection, - $paymentConfig, - $data - ); + public function isAvailable(CartInterface $quote = null) + { + // in B2C payment methods, we don't want companies to be involved. + // so, if the address contains a company, return false. + if ($quote !== null && !empty($quote->getBillingAddress()->getCompany())) { + return false; + } - $this->_heidelpayPaymentMethod = $paymentMethod; + // process the parent isAvailable method + return parent::isAvailable($quote); } /** diff --git a/PaymentMethods/HeidelpaySofortPaymentMethod.php b/PaymentMethods/HeidelpaySofortPaymentMethod.php index dd95565d3d2..1c1cab52399 100755 --- a/PaymentMethods/HeidelpaySofortPaymentMethod.php +++ b/PaymentMethods/HeidelpaySofortPaymentMethod.php @@ -1,11 +1,5 @@ Heidelpay\PhpPaymentApi\PaymentMethods\SofortPaymentMethod + + + HgwSantanderHirePurchaseConfig + Heidelpay\PhpPaymentApi\PaymentMethods\SantanderHirePurchasePaymentMethod + + From 3dad20e67821f8443d52c40b972ee85deb5f793a Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 24 May 2019 13:12:20 +0200 Subject: [PATCH 023/114] [refactor] (MAGE2-175) Santander Hire Purchase: Debug - Remove optimizations. --- .../HeidelpayAbstractPaymentMethod.php | 30 +++---------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 32b97252be2..e52de3354e2 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -43,8 +43,6 @@ use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; use Magento\Sales\Model\Order\Payment; -use Magento\Sales\Model\Spi\OrderPaymentResourceInterface; -use Magento\Sales\Model\Spi\TransactionResourceInterface; use Magento\Store\Model\ScopeInterface as StoreScopeInterface; use Heidelpay\Gateway\Block\Payment\HgwAbstract; use Heidelpay\PhpPaymentApi\PaymentMethods\PaymentMethodInterface; @@ -130,11 +128,7 @@ class HeidelpayAbstractPaymentMethod extends AbstractMethod /** @var ResourceInterface $moduleResource Resource information about modules */ protected $moduleResource; - /** - * Factory for heidelpay payment information - * - * @var PaymentInformationCollectionFactory $paymentInformationCollectionFactory - */ + /** @var PaymentInformationCollectionFactory $paymentInformationCollectionFactory */ protected $paymentInformationCollectionFactory; /** @var TransactionFactory */ @@ -148,18 +142,8 @@ class HeidelpayAbstractPaymentMethod extends AbstractMethod /** @var HgwBasePaymentConfigInterface */ private $paymentConfig; - /** - * @var OrderPaymentResourceInterface - */ - private $paymentResource; - /** - * @var TransactionResourceInterface - */ - private $transactionResource; /** - * heidelpay Abstract Payment method constructor - * * @param Context $context * @param Registry $registry * @param ExtensionAttributesFactory $extensionFactory @@ -179,8 +163,6 @@ class HeidelpayAbstractPaymentMethod extends AbstractMethod * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory * @param TransactionFactory $transactionFactory * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory - * @param OrderPaymentResourceInterface $paymentResource - * @param TransactionResourceInterface $transactionResource * @param AbstractResource $resource * @param AbstractDb $resourceCollection * @param HgwBasePaymentConfigInterface $paymentConfig @@ -207,8 +189,6 @@ public function __construct( PaymentInformationCollectionFactory $paymentInformationCollectionFactory, TransactionFactory $transactionFactory, HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - OrderPaymentResourceInterface $paymentResource, - TransactionResourceInterface $transactionResource, AbstractResource $resource = null, AbstractDb $resourceCollection = null, HgwBasePaymentConfigInterface $paymentConfig = null, @@ -239,8 +219,6 @@ public function __construct( $this->_localResolver = $localeResolver; $this->productMetadata = $productMetadata; $this->moduleResource = $moduleResource; - $this->paymentResource = $paymentResource; - $this->transactionResource = $transactionResource; $this->paymentInformationCollectionFactory = $paymentInformationCollectionFactory; $this->transactionFactory = $transactionFactory; @@ -368,7 +346,7 @@ public function capture(InfoInterface $payment, $amount) // set the last transaction id to the Pre-Authorization. $payment->setLastTransId($this->_heidelpayPaymentMethod->getResponse()->getPaymentReferenceId()); - $this->paymentResource->save($payment); + $payment->save(); return $this; } @@ -448,7 +426,7 @@ public function refund(InfoInterface $payment, $amount) // set the last transaction id to the Pre-Authorization. $payment->setLastTransId($this->_heidelpayPaymentMethod->getResponse()->getPaymentReferenceId()); - $this->paymentResource->save($payment); + $payment->save(); return $this; } @@ -553,7 +531,7 @@ public function saveHeidelpayTransaction(Response $response, $paymentMethod, $pa ->setJsonResponse(json_encode($data)) ->setSource($source); - $this->transactionResource->save($transaction); + $transaction->save(); } /** From e0d391e40125003830f174e179c84dda9af4cc5e Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 24 May 2019 14:53:11 +0200 Subject: [PATCH 024/114] [refactor] Optimized payment method implementations. --- .../HeidelpayAbstractPaymentMethod.php | 75 ++++++------------- .../HeidelpayCreditCardPaymentMethod.php | 38 +++------- .../HeidelpayDebitCardPaymentMethod.php | 38 +++------- .../HeidelpayDirectDebitPaymentMethod.php | 23 +++--- ...idelpayDirectDebitSecuredPaymentMethod.php | 23 +++--- .../HeidelpayGiropayPaymentMethod.php | 23 +++--- .../HeidelpayIDealPaymentMethod.php | 15 ++-- .../HeidelpayInvoicePaymentMethod.php | 31 +++----- .../HeidelpayInvoiceSecuredPaymentMethod.php | 41 +++------- .../HeidelpayPayPalPaymentMethod.php | 34 ++++----- .../HeidelpayPrepaymentPaymentMethod.php | 31 +++----- ...lpaySantanderHirePurchasePaymentMethod.php | 27 +++---- .../HeidelpaySofortPaymentMethod.php | 26 +++---- 13 files changed, 153 insertions(+), 272 deletions(-) diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index e52de3354e2..f5c33b4775f 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -50,8 +50,6 @@ use RuntimeException; /** - * Heidelpay abstract payment method - * * All Heidelpay payment methods will extend this abstract payment method * * @license Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. @@ -68,32 +66,11 @@ class HeidelpayAbstractPaymentMethod extends AbstractMethod /** @var string PaymentCode */ const CODE = 'hgwabstract'; - /** @var string PaymentCode */ - protected $_code = self::CODE; - - /** @var boolean */ - protected $_isGateway = true; - - /** @var boolean */ - protected $_canCapture = false; - - /** @var boolean */ - protected $_canCapturePartial = false; - /** @var boolean */ - protected $_canRefund = false; + protected $_usingBasket; /** @var boolean */ - protected $_canRefundInvoicePartial = false; - - /** @var boolean */ - protected $_canUseInternal = false; - - /** @var boolean */ - private $usingBasketApi = false; - - /** @var string */ - protected $_formBlockType = HgwAbstract::class; + protected $_usingActiveRedirect; /** @var UrlInterface */ protected $urlBuilder; @@ -113,9 +90,6 @@ class HeidelpayAbstractPaymentMethod extends AbstractMethod /** @var PaymentMethodInterface $_heidelpayPaymentMethod The used heidelpay payment method */ protected $_heidelpayPaymentMethod; - /** @var Logger */ - protected $logger; - /** @var Encryptor $_encryptor Encryption & Hashing */ protected $_encryptor; @@ -209,7 +183,6 @@ public function __construct( ); $this->urlBuilder = $urlinterface; - $this->logger = $logger; $this->_requestHttp = $request; $this->_paymentHelper = $paymentHelper; $this->salesHelper = $salesHelper; @@ -230,6 +203,25 @@ public function __construct( $this->setup(); } + /** + * Performs setup steps to initialize the payment method. + * Override to perform additional tasks in constructor. + */ + protected function setup() + { + $this->_code = static::CODE; // set the payment code + $this->_isGateway = true; + $this->_canCapture = false; + $this->_canAuthorize = false; + $this->_canCapturePartial = false; + $this->_canRefund = false; + $this->_canRefundInvoicePartial = false; + $this->_canUseInternal = false; + $this->_usingBasket = false; + $this->_usingActiveRedirect = true; + $this->_formBlockType = HgwAbstract::class; + } + /** * Active redirect * @@ -237,10 +229,9 @@ public function __construct( * customer payment data to pursue. * @return boolean */ - public function activeRedirect() { - return true; + return $this->_usingActiveRedirect; } /** @@ -492,7 +483,7 @@ public function getHeidelpayUrl($quote) ); // submit the Quote to the Basket API if the payment method needs one. - if ($this->isUsingBasketApi()) { + if ($this->_usingBasket) { $basketId = $this->basketHelper->submitQuoteToBasketApi($quote); if ($basketId === null) { @@ -715,22 +706,6 @@ public function additionalPaymentInformation($response) return null; } - /** - * @return bool - */ - public function isUsingBasketApi() - { - return $this->usingBasketApi; - } - - /** - * @param bool $usingBasketApi - */ - public function setUsingBasketApi($usingBasketApi) - { - $this->usingBasketApi = $usingBasketApi; - } - /** * Set request authentication */ @@ -812,8 +787,4 @@ public function heidelpayTransactionExists($transactionID) return !$heidelpayTransaction === null && !$heidelpayTransaction->isEmpty(); } - - /** Override to perform additional tasks in constructor. */ - protected function setup() - {} } diff --git a/PaymentMethods/HeidelpayCreditCardPaymentMethod.php b/PaymentMethods/HeidelpayCreditCardPaymentMethod.php index a40bd051fce..9e7e23e1d42 100755 --- a/PaymentMethods/HeidelpayCreditCardPaymentMethod.php +++ b/PaymentMethods/HeidelpayCreditCardPaymentMethod.php @@ -21,41 +21,21 @@ class HeidelpayCreditCardPaymentMethod extends HeidelpayAbstractPaymentMethod /** @var string PaymentCode */ const CODE = 'hgwcc'; - /** @var string PaymentCode */ - protected $_code = self::CODE; - - /** @var boolean */ - protected $_isGateway = true; - - /** @var boolean */ - protected $_canAuthorize = true; - - /** @var boolean */ - protected $_canCapture = true; - - /** @var boolean */ - protected $_canCapturePartial = true; - - /** @var boolean */ - protected $_canRefund = true; - - /** @var boolean */ - protected $_canRefundInvoicePartial = true; - /** @var CreditCardPaymentMethod */ protected $_heidelpayPaymentMethod; /** - * Active redirect - * - * This function will return false, if the used payment method needs additional - * customer payment data to pursue. - * - * @return boolean + * {@inheritDoc} */ - public function activeRedirect() + protected function setup() { - return false; + parent::setup(); + $this->_canCapture = true; + $this->_canAuthorize = true; + $this->_canCapturePartial = true; + $this->_canRefund = true; + $this->_canRefundInvoicePartial = true; + $this->_usingActiveRedirect = false; } /** diff --git a/PaymentMethods/HeidelpayDebitCardPaymentMethod.php b/PaymentMethods/HeidelpayDebitCardPaymentMethod.php index a4cadc47485..3737c80bae8 100755 --- a/PaymentMethods/HeidelpayDebitCardPaymentMethod.php +++ b/PaymentMethods/HeidelpayDebitCardPaymentMethod.php @@ -21,41 +21,21 @@ class HeidelpayDebitCardPaymentMethod extends HeidelpayAbstractPaymentMethod /** @var string PaymentCode */ const CODE = 'hgwdc'; - /** @var string PaymentCode */ - protected $_code = self::CODE; - - /** @var boolean */ - protected $_isGateway = true; - - /** @var boolean */ - protected $_canAuthorize = true; - - /** @var boolean */ - protected $_canCapture = true; - - /** @var boolean */ - protected $_canCapturePartial = true; - - /** @var boolean */ - protected $_canRefund = true; - - /** @var boolean */ - protected $_canRefundInvoicePartial = true; - /** @var DebitCardPaymentMethod */ protected $_heidelpayPaymentMethod; /** - * Active redirect - * - * This function will return false, if the used payment method needs additional - * customer payment data to pursue. - * - * @return boolean + * {@inheritDoc} */ - public function activeRedirect() + protected function setup() { - return false; + parent::setup(); + $this->_canCapture = true; + $this->_canAuthorize = true; + $this->_canCapturePartial = true; + $this->_canRefund = true; + $this->_canRefundInvoicePartial = true; + $this->_usingActiveRedirect = false; } /** diff --git a/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php b/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php index d6c2ca7a2da..b265263dc79 100755 --- a/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php +++ b/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php @@ -28,21 +28,20 @@ class HeidelpayDirectDebitPaymentMethod extends HeidelpayAbstractPaymentMethod /** @var string PaymentCode */ const CODE = 'hgwdd'; - /** @var string heidelpay gateway payment code */ - protected $_code = self::CODE; - - /** @var bool */ - protected $_canAuthorize = true; - - /** @var boolean */ - protected $_canRefund = true; - - /** @var boolean */ - protected $_canRefundInvoicePartial = true; - /** @var DirectDebitPaymentMethod */ protected $_heidelpayPaymentMethod; + /** + * {@inheritDoc} + */ + protected function setup() + { + parent::setup(); + $this->_canAuthorize = true; + $this->_canRefund = true; + $this->_canRefundInvoicePartial = true; + } + /** * Fires the initial request to the heidelpay payment provider. * diff --git a/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php b/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php index a570b9dad68..9ef32dd9efd 100755 --- a/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php @@ -23,21 +23,20 @@ class HeidelpayDirectDebitSecuredPaymentMethod extends HeidelpayAbstractPaymentM /** @var string PaymentCode */ const CODE = 'hgwdds'; - /** @var string heidelpay gateway payment code */ - protected $_code = self::CODE; - - /** @var bool */ - protected $_canAuthorize = true; - - /** @var boolean */ - protected $_canRefund = true; - - /** @var boolean */ - protected $_canRefundInvoicePartial = true; - /** @var DirectDebitB2CSecuredPaymentMethod */ protected $_heidelpayPaymentMethod; + /** + * {@inheritDoc} + */ + protected function setup() + { + parent::setup(); + $this->_canAuthorize = true; + $this->_canRefund = true; + $this->_canRefundInvoicePartial = true; + } + /** * @inheritdoc */ diff --git a/PaymentMethods/HeidelpayGiropayPaymentMethod.php b/PaymentMethods/HeidelpayGiropayPaymentMethod.php index fb239e928fa..3928171e6f3 100755 --- a/PaymentMethods/HeidelpayGiropayPaymentMethod.php +++ b/PaymentMethods/HeidelpayGiropayPaymentMethod.php @@ -20,21 +20,20 @@ class HeidelpayGiropayPaymentMethod extends HeidelpayAbstractPaymentMethod /** @var string PaymentCode */ const CODE = 'hgwgp'; - /** @var string heidelpay gateway payment code */ - protected $_code = self::CODE; - - /** @var bool */ - protected $_canAuthorize = true; - - /** @var boolean */ - protected $_canRefund = true; - - /** @var boolean */ - protected $_canRefundInvoicePartial = true; - /** @var GiropayPaymentMethod */ protected $_heidelpayPaymentMethod; + /** + * {@inheritDoc} + */ + protected function setup() + { + parent::setup(); + $this->_canAuthorize = true; + $this->_canRefund = true; + $this->_canRefundInvoicePartial = true; + } + /** * @inheritdoc */ diff --git a/PaymentMethods/HeidelpayIDealPaymentMethod.php b/PaymentMethods/HeidelpayIDealPaymentMethod.php index 7349b1ad17a..7b554112760 100644 --- a/PaymentMethods/HeidelpayIDealPaymentMethod.php +++ b/PaymentMethods/HeidelpayIDealPaymentMethod.php @@ -22,15 +22,18 @@ class HeidelpayIDealPaymentMethod extends HeidelpayAbstractPaymentMethod { const CODE = 'hgwidl'; - protected $_code = self::CODE; - - protected $_canAuthorize = true; - - protected $_isGateway = true; - /** @var IDealPaymentMethod $_heidelpayPaymentMethod*/ protected $_heidelpayPaymentMethod; + /** + * {@inheritDoc} + */ + protected function setup() + { + parent::setup(); + $this->_canAuthorize = true; + } + /** * @inheritdoc * Prepare necessary information for bank selection diff --git a/PaymentMethods/HeidelpayInvoicePaymentMethod.php b/PaymentMethods/HeidelpayInvoicePaymentMethod.php index 17f8df4e5d9..81b0bd7eaba 100755 --- a/PaymentMethods/HeidelpayInvoicePaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoicePaymentMethod.php @@ -24,29 +24,20 @@ class HeidelpayInvoicePaymentMethod extends HeidelpayAbstractPaymentMethod /** @var string Payment Code */ const CODE = 'hgwiv'; - /** @var string Payment Code */ - protected $_code = self::CODE; + /** @var InvoicePaymentMethod */ + protected $_heidelpayPaymentMethod; /** - * Info Block Class (used for Order/Invoice details) - * @var string + * {@inheritDoc} */ - protected $_infoBlockType = InvoiceBlock::class; - - /** @var boolean */ - protected $_isGateway = true; - - /** @var boolean */ - protected $_canAuthorize = true; - - /** @var boolean */ - protected $_canRefund = true; - - /** @var boolean */ - protected $_canRefundInvoicePartial = true; - - /** @var InvoicePaymentMethod */ - protected $_heidelpayPaymentMethod; + protected function setup() + { + parent::setup(); + $this->_canAuthorize = true; + $this->_canRefund = true; + $this->_canRefundInvoicePartial = true; + $this->_formBlockType = InvoiceBlock::class; + } /** * Initial Request to heidelpay payment server to get the form / iframe url diff --git a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php index 3cfbebcd11a..2870364e919 100755 --- a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php @@ -26,29 +26,21 @@ class HeidelpayInvoiceSecuredPaymentMethod extends HeidelpayAbstractPaymentMetho /** @var string Payment Code */ const CODE = 'hgwivs'; - /** @var string Payment Code */ - protected $_code = self::CODE; + /** @var InvoiceB2CSecuredPaymentMethod */ + protected $_heidelpayPaymentMethod; /** - * Info Block Class (used for Order/Invoice details) - * @var string + * {@inheritDoc} */ - protected $_infoBlockType = InvoiceSecured::class; - - /** @var boolean */ - protected $_isGateway = true; - - /** @var boolean */ - protected $_canAuthorize = true; - - /** @var boolean */ - protected $_canRefund = true; - - /** @var boolean */ - protected $_canRefundInvoicePartial = true; - - /** @var InvoiceB2CSecuredPaymentMethod */ - protected $_heidelpayPaymentMethod; + protected function setup() + { + parent::setup(); + $this->_canAuthorize = true; + $this->_canRefund = true; + $this->_canRefundInvoicePartial = true; + $this->_usingBasket = true; + $this->_formBlockType = InvoiceSecured::class; + } /** * @inheritDoc @@ -154,13 +146,4 @@ public function pendingTransactionProcessing($data, &$order, $message = null) $this->_paymentHelper->saveTransaction($invoice); } } - - /** @inheritdoc */ - protected function setup() - { - parent::setup(); - $this->setUsingBasketApi(true); - } - - } diff --git a/PaymentMethods/HeidelpayPayPalPaymentMethod.php b/PaymentMethods/HeidelpayPayPalPaymentMethod.php index f1f4d076bc1..5d77ef513d0 100755 --- a/PaymentMethods/HeidelpayPayPalPaymentMethod.php +++ b/PaymentMethods/HeidelpayPayPalPaymentMethod.php @@ -21,30 +21,22 @@ class HeidelpayPayPalPaymentMethod extends HeidelpayAbstractPaymentMethod /** @var string PaymentCode */ const CODE = 'hgwpal'; - /** @var string PaymentCode */ - protected $_code = self::CODE; - - /** @var boolean */ - protected $_isGateway = true; - - /** @var boolean */ - protected $_canAuthorize = true; - - /** @var boolean */ - protected $_canCapture = true; - - /** @var boolean */ - protected $_canCapturePartial = true; - - /** @var boolean */ - protected $_canRefund = true; - - /** @var boolean */ - protected $_canRefundInvoicePartial = true; - /** @var PayPalPaymentMethod */ protected $_heidelpayPaymentMethod; + /** + * {@inheritDoc} + */ + protected function setup() + { + parent::setup(); + $this->_canCapture = true; + $this->_canAuthorize = true; + $this->_canCapturePartial = true; + $this->_canRefund = true; + $this->_canRefundInvoicePartial = true; + } + /** * Initial Request to heidelpay payment server to get the form / iframe url * {@inheritDoc} diff --git a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php index 4c5a02a5a95..2435f43f6e9 100755 --- a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php +++ b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php @@ -24,29 +24,20 @@ class HeidelpayPrepaymentPaymentMethod extends HeidelpayAbstractPaymentMethod /** @var string PaymentCode */ const CODE = 'hgwpp'; - /** @var string PaymentCode */ - protected $_code = self::CODE; + /** @var PrepaymentPaymentMethod */ + protected $_heidelpayPaymentMethod; /** - * Info Block Class (used for Order/Invoice details) - * @var string + * {@inheritDoc} */ - protected $_infoBlockType = Prepayment::class; - - /** @var boolean */ - protected $_isGateway = true; - - /** @var boolean */ - protected $_canAuthorize = true; - - /** @var boolean */ - protected $_canRefund = true; - - /** @var boolean */ - protected $_canRefundInvoicePartial = true; - - /** @var PrepaymentPaymentMethod */ - protected $_heidelpayPaymentMethod; + protected function setup() + { + parent::setup(); + $this->_canAuthorize = true; + $this->_canRefund = true; + $this->_canRefundInvoicePartial = true; + $this->_formBlockType = Prepayment::class; + } /** * Initial Request to heidelpay payment server to get the form / iframe url diff --git a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php index f63e33be617..1ecc0ebe1ed 100755 --- a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php +++ b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php @@ -23,24 +23,21 @@ class HeidelpaySantanderHirePurchasePaymentMethod extends HeidelpayAbstractPayme /** @var string PaymentCode */ const CODE = 'hgwsanhp'; - /** @var string PaymentCode */ - protected $_code = self::CODE; - - /** @var boolean $_isGateway */ - protected $_isGateway = true; - - /** @var boolean $_canAuthorize */ - protected $_canAuthorize = true; - - /** @var boolean $_canRefund */ - protected $_canRefund = true; - - /** @var boolean $_canRefundInvoicePartial */ - protected $_canRefundInvoicePartial = true; - /** @var SantanderHirePurchasePaymentMethod */ protected $_heidelpayPaymentMethod; + /** + * {@inheritDoc} + */ + protected function setup() + { + parent::setup(); + $this->_canAuthorize = true; + $this->_canRefund = true; + $this->_canRefundInvoicePartial = true; + $this->_usingBasket = true; + } + /** * Determines if the payment method will be displayed at the checkout. * For B2C methods, the payment method should not be displayed. diff --git a/PaymentMethods/HeidelpaySofortPaymentMethod.php b/PaymentMethods/HeidelpaySofortPaymentMethod.php index 1c1cab52399..e2dc012253c 100755 --- a/PaymentMethods/HeidelpaySofortPaymentMethod.php +++ b/PaymentMethods/HeidelpaySofortPaymentMethod.php @@ -20,24 +20,20 @@ class HeidelpaySofortPaymentMethod extends HeidelpayAbstractPaymentMethod /** @var string PaymentCode */ const CODE = 'hgwsue'; - /** @var string PaymentCode */ - protected $_code = self::CODE; - - /** @var boolean */ - protected $_isGateway = true; - - /** @var boolean */ - protected $_canAuthorize = true; - - /** @var boolean */ - protected $_canRefund = true; - - /** @var boolean */ - protected $_canRefundInvoicePartial = true; - /** @var SofortPaymentMethod */ protected $_heidelpayPaymentMethod; + /** + * {@inheritDoc} + */ + protected function setup() + { + parent::setup(); + $this->_canAuthorize = true; + $this->_canRefund = true; + $this->_canRefundInvoicePartial = true; + } + /** * Initial Request to heidelpay payment server to get the form / iframe url * {@inheritDoc} From 576bc760e55e16c5fa3ee22a47ccccd3da779c8f Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 27 May 2019 09:10:21 +0200 Subject: [PATCH 025/114] [refactor] Fix comments. --- .../web/template/payment/heidelpay-directdebit-form.html | 2 +- .../template/payment/heidelpay-directdebit-secured-form.html | 2 +- view/frontend/web/template/payment/heidelpay-form.html | 2 +- view/frontend/web/template/payment/heidelpay-ideal-form.html | 2 +- .../web/template/payment/heidelpay-invoice-secured-form.html | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/view/frontend/web/template/payment/heidelpay-directdebit-form.html b/view/frontend/web/template/payment/heidelpay-directdebit-form.html index 6e4d0418de2..f0aa160d491 100644 --- a/view/frontend/web/template/payment/heidelpay-directdebit-form.html +++ b/view/frontend/web/template/payment/heidelpay-directdebit-form.html @@ -1,7 +1,7 @@
diff --git a/view/frontend/web/template/payment/heidelpay-directdebit-secured-form.html b/view/frontend/web/template/payment/heidelpay-directdebit-secured-form.html index 98f129b889f..18b3030db59 100644 --- a/view/frontend/web/template/payment/heidelpay-directdebit-secured-form.html +++ b/view/frontend/web/template/payment/heidelpay-directdebit-secured-form.html @@ -1,7 +1,7 @@
diff --git a/view/frontend/web/template/payment/heidelpay-form.html b/view/frontend/web/template/payment/heidelpay-form.html index e0b4e5099ba..c7468960fcd 100644 --- a/view/frontend/web/template/payment/heidelpay-form.html +++ b/view/frontend/web/template/payment/heidelpay-form.html @@ -1,7 +1,7 @@ diff --git a/view/frontend/web/template/payment/heidelpay-ideal-form.html b/view/frontend/web/template/payment/heidelpay-ideal-form.html index c9b8bfc4993..f94842633aa 100644 --- a/view/frontend/web/template/payment/heidelpay-ideal-form.html +++ b/view/frontend/web/template/payment/heidelpay-ideal-form.html @@ -1,7 +1,7 @@
diff --git a/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html b/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html index a964eab8963..618219938d7 100644 --- a/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html +++ b/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html @@ -1,7 +1,7 @@
From fd80a34eda07b159b54984497a8759ece17ed245 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 27 May 2019 09:12:50 +0200 Subject: [PATCH 026/114] [refactor] Fix comments. --- .../template/payment/heidelpay-directdebit-form.html | 10 ++++++++-- .../payment/heidelpay-directdebit-secured-form.html | 10 ++++++++-- .../frontend/web/template/payment/heidelpay-form.html | 11 ++++++++--- .../web/template/payment/heidelpay-ideal-form.html | 10 ++++++++-- .../payment/heidelpay-invoice-secured-form.html | 10 ++++++++-- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/view/frontend/web/template/payment/heidelpay-directdebit-form.html b/view/frontend/web/template/payment/heidelpay-directdebit-form.html index f0aa160d491..685f471e30a 100644 --- a/view/frontend/web/template/payment/heidelpay-directdebit-form.html +++ b/view/frontend/web/template/payment/heidelpay-directdebit-form.html @@ -1,7 +1,13 @@
diff --git a/view/frontend/web/template/payment/heidelpay-directdebit-secured-form.html b/view/frontend/web/template/payment/heidelpay-directdebit-secured-form.html index 18b3030db59..97891160c5a 100644 --- a/view/frontend/web/template/payment/heidelpay-directdebit-secured-form.html +++ b/view/frontend/web/template/payment/heidelpay-directdebit-secured-form.html @@ -1,7 +1,13 @@
diff --git a/view/frontend/web/template/payment/heidelpay-form.html b/view/frontend/web/template/payment/heidelpay-form.html index c7468960fcd..b2107691a27 100644 --- a/view/frontend/web/template/payment/heidelpay-form.html +++ b/view/frontend/web/template/payment/heidelpay-form.html @@ -1,10 +1,15 @@ -
diff --git a/view/frontend/web/template/payment/heidelpay-ideal-form.html b/view/frontend/web/template/payment/heidelpay-ideal-form.html index f94842633aa..2e9bf0b0f64 100644 --- a/view/frontend/web/template/payment/heidelpay-ideal-form.html +++ b/view/frontend/web/template/payment/heidelpay-ideal-form.html @@ -1,7 +1,13 @@
diff --git a/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html b/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html index 618219938d7..166a4ca8ea4 100644 --- a/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html +++ b/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html @@ -1,7 +1,13 @@
From b55762925b08a4cb27f608d3b13c4e16f7a65cbb Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 27 May 2019 10:09:24 +0200 Subject: [PATCH 027/114] [refactor] (MAGE2-175) Santander Hire Purchase: Add form with logo. --- .../web/js/view/payment/hgw-payments.js | 2 +- .../hgw-santander-hire-purchase.js | 127 ++++++++++++ .../heidelpay-santander-hire-purchase.html | 180 ++++++++++++++++++ 3 files changed, 308 insertions(+), 1 deletion(-) create mode 100644 view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js create mode 100644 view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html diff --git a/view/frontend/web/js/view/payment/hgw-payments.js b/view/frontend/web/js/view/payment/hgw-payments.js index 8850e2ab234..c50e997b50c 100755 --- a/view/frontend/web/js/view/payment/hgw-payments.js +++ b/view/frontend/web/js/view/payment/hgw-payments.js @@ -55,7 +55,7 @@ define( }, { type: 'hgwsanhp', - component: 'Heidelpay_Gateway/js/view/payment/method-renderer/hgw-abstract' + component: 'Heidelpay_Gateway/js/view/payment/method-renderer/hgw-santander-hire-purchase' } ); return Component.extend({}); diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js b/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js new file mode 100644 index 00000000000..2861a56d3e7 --- /dev/null +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js @@ -0,0 +1,127 @@ +define( + [ + 'jquery', + 'Heidelpay_Gateway/js/view/payment/method-renderer/hgw-abstract', + 'Heidelpay_Gateway/js/action/place-order', + 'Magento_Checkout/js/model/url-builder', + 'mage/storage', + 'Magento_Checkout/js/model/payment/additional-validators', + 'Magento_Customer/js/model/customer', + 'Magento_Checkout/js/model/quote', + 'moment' + ], + function ($, Component, placeOrderAction, urlBuilder, storage, additionalValidators, customer, quote, moment) { + 'use strict'; + + return Component.extend({ + + /** + * Property that indicates, if the payment method is storing + * additional data. + */ + savesAdditionalData: true, + + defaults: { + template: 'Heidelpay_Gateway/payment/heidelpay-santander-hire-purchase', + hgwDobYear: '', + hgwDobMonth: '', + hgwDobDay: '', + hgwSalutation: '', + years: [null] + }, + + initialize: function () { + this._super(); + this.getAdditionalPaymentInformation(); + + // init years select menu + for (var i = (new Date().getFullYear() - 17); i >= new Date().getFullYear() - 120; i--) { + this.years.push(i); + } + + return this; + }, + + initObservable: function() { + this._super() + .observe(['hgwSalutation', 'hgwDobYear', 'hgwDobMonth', 'hgwDobDay', 'years']); + + return this; + }, + + + getAdditionalPaymentInformation: function() { + // recognition: only when there is a logged in customer + if (customer.isLoggedIn()) { + // if we have a shipping address, go on + if( quote.shippingAddress() !== null ) { + var parent = this; + var serviceUrl = urlBuilder.createUrl('/hgw/get-payment-info', {}); + var hgwPayload = { + quoteId: quote.getQuoteId(), + paymentMethod: this.item.method + }; + + storage.post( + serviceUrl, JSON.stringify(hgwPayload) + ).done( + function(data) { + var info = JSON.parse(data); + + // set salutation and birthdate, if set. + if( info !== null ) { + if (info.hasOwnProperty('hgw_salutation')) + parent.hgwSalutation(info.hgw_salutation); + + if (info.hasOwnProperty('hgw_birthdate') && info.hgw_birthdate !== null) { + var date = moment(info.hgw_birthdate, 'YYYY-MM-DD'); + + parent.hgwDobDay(date.date()); + parent.hgwDobMonth(date.month()); + parent.hgwDobYear(date.year()); + + // workaround: if month is 'january', the month isn't selected. + if (date.month() === 0) { + $("#hgwsanhp_birthdate_month option:eq(1)").prop('selected', true); + } + } + } + } + ); + } + } + }, + + getCode: function () { + return 'hgwsanhp'; + }, + + getData: function () { + return { + 'method': this.item.method, + 'additional_data': { + 'hgw_birthdate': this.getBirthdate(), + 'hgw_salutation': this.hgwSalutation() + } + }; + }, + + /** + * Returns the birthdate in ISO 8601 format. + * + * @returns {string} + */ + getBirthdate: function () { + return moment( + new Date(this.hgwDobYear(), this.hgwDobMonth(), this.hgwDobDay()) + ).format('YYYY-MM-DD'); + }, + + validate: function() { + var form = $('#hgw-santander-hire-purchase'); + + return form.validation() && form.validation('isValid'); + } + }); + } +); \ No newline at end of file diff --git a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html new file mode 100644 index 00000000000..32867dde874 --- /dev/null +++ b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html @@ -0,0 +1,180 @@ + +
+
+ + +
+ +
+ + + +
+ + + +
+
+ +
+
+ +
+
+
+ +
+ +
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+
+
+
+ + + +
+
+
+ +
+
+
+
From 5c651ed022ba584a0f486f7d77b081f34d0807f4 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 27 May 2019 13:45:10 +0200 Subject: [PATCH 028/114] [refactor] (MAGE2-175) Santander Hire Purchase: Add bButton translation. --- i18n/de_DE.csv | 13 +++++++------ i18n/en_US.csv | 12 +++++++++++- .../payment/heidelpay-santander-hire-purchase.html | 10 ++++------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index 218a0511fb3..afb6dd86d63 100755 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -30,9 +30,6 @@ "Same Shipping Address","Selbe Lieferadresse" "Always","Immer" -"Please confirm your payment:","Bitte führen Sie nun die Zahlung durch:" -"pay now","Jetzt bezahlen" - "Credit Card","Kreditkarte" "Debit Card","Debitkarte" "Direct Debit","Lastschrift" @@ -75,12 +72,16 @@ "November","November" "December","Dezember" -"This is a required field.","Dieses Feld ist erforderlich." - "ShortId : %1","ShortId : %1" -"Amount or currency missmatch : %1","Abweichender Betrag oder Währung : %1" +"Amount or currency missmatch : %1","Abweichender Betrag oder Währung : %1" + +"Please confirm your payment:","Bitte führen Sie nun die Zahlung durch:" +"pay now","Jetzt bezahlen" +"Choose installment plan","Ratenplan auswählen" +"This is a required field.","Dieses Feld ist erforderlich." "Payment information","Zahlungsinformationen" "Reference","Verwendungszweck" +"Place Order","Bestellung anlegen" "Please transfer the amount of %1 %2 to the following account

Holder: %3
IBAN: %4
BIC: %5

Please use only this identification number as the descriptor :
%6","Bitte überweisen Sie uns den Betrag von %1 %2 auf folgendes Konto:

Inhaber: %3
IBAN: %4
BIC: %5

Geben Sie als Verwendungszweck bitte ausschließlich diese Identifikationsnummer an:
%6" "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","Bitte überweisen Sie uns den Betrag von %1 %2 nach Erhalt der Ware auf folgendes Konto:

Inhaber: %3
IBAN: %4
BIC: %5

Geben Sie als Verwendungszweck bitte ausschließlich diese Identifikationsnummer an:
%6" "The amount of %1 %2 will be debited from this account within the next days:

IBAN: %3

The booking contains the mandate reference ID: %4
and the creditor identifier: %5


Please ensure that there will be sufficient funds on the corresponding account.","Der Betrag von %1 %2 wird in den nächsten Tagen von folgendem Konto abgebucht:

IBAN: %3

Die Abbuchung enthält die Mandatsreferenz-ID: %4
und die Gläubiger ID: %5


Bitte sorgen Sie für ausreichende Deckung auf dem entsprechenden Konto." diff --git a/i18n/en_US.csv b/i18n/en_US.csv index a2dc66adaff..bc1c99bb623 100755 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -15,7 +15,15 @@ "HGW_ABOUT_US","heidelpay 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" +"Security Sender","Sender-ID" +"User Login","Login" +"User Password","Password" +"Sandbox Mode","Sandbox" "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." +"Enabled","Enabled" +"Channel","Channel-ID" +"Insert 0 to disable limit.","Insert 0 to disable limit." +"If 'Debit' is enabled the card will be charged immediately. Otherwise the amount will first be authorised and charged at order creation.","If 'Debit' is enabled the card will be charged immediately. Otherwise the amount will first be authorised and charged at order creation." "An unexpected error occurred. Please contact us to get further information.","An unexpected error occurred. Please contact us to get further information." "Never","Never" @@ -69,9 +77,11 @@ "Please confirm your payment:","Please confirm your payment:" "pay now","pay now" -"Place Order","Place Order" +"Choose installment plan","Choose installment plan" +"This is a required field.","This is a required field." "Payment information","Payment information" "Reference","Reference" +"Place Order","Place Order" "Please transfer the amount of %1 %2 to the following account

Holder: %3
IBAN: %4
BIC: %5

Please use only this identification number as the descriptor :
%6","Please transfer the amount of %1 %2 to the following account

Holder: %3
IBAN: %4
BIC: %5

Please use only this identification number as the descriptor :
%6" "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","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" "The amount of %1 %2 will be debited from this account within the next days:

IBAN: %3

The booking contains the mandate reference ID: %4
and the creditor identifier: %5


Please ensure that there will be sufficient funds on the corresponding account.", "The amount of %1 %2 will be debited from this account within the next days:

IBAN: %3

The booking contains the mandate reference ID: %4
and the creditor identifier: %5


Please ensure that there will be sufficient funds on the corresponding account." diff --git a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html index 32867dde874..6287c946bd4 100644 --- a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html +++ b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html @@ -166,13 +166,11 @@
From 3f609c4f18b6943c00cda0c4476e5478527bc7d9 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 27 May 2019 16:12:30 +0200 Subject: [PATCH 029/114] (MAGE2-134) Response Mailer: Send order mail and invoice mail from redirect controller to response controller. --- Controller/Index/Redirect.php | 26 +------- Controller/Index/Response.php | 112 +++++++++++++++++++++++++++------- 2 files changed, 90 insertions(+), 48 deletions(-) diff --git a/Controller/Index/Redirect.php b/Controller/Index/Redirect.php index fe78fa149ca..8da2eed0e97 100755 --- a/Controller/Index/Redirect.php +++ b/Controller/Index/Redirect.php @@ -145,7 +145,7 @@ public function execute() // set Parameters for success page if ($this->heidelpayResponse->isSuccess()) { // lock the quote - $session->getQuote()->setIsActive(false)->save(); + //$session->getQuote()->setIsActive(false)->save(); /** @var Order $order */ $order = null; @@ -156,7 +156,6 @@ public function execute() 'Heidelpay - Redirect: Cannot receive order.' . $e->getMessage() ); } - $session->clearHelperData(); // set QuoteIds @@ -179,29 +178,6 @@ public function execute() // set response $response = $this->_redirect('checkout/onepage/success', ['_secure' => true]); - try { - // send order confirmation to the customer - if ($order && $order->getId()) { - $this->_orderSender->send($order); - } - } catch (\Exception $e) { - $this->_logger->error( - 'Heidelpay - Redirect: Cannot send order confirmation E-Mail. ' . $e->getMessage() - ); - } - - // 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); - } - } - } - // return response return $response; } diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index 18ba2a8c18c..da7e149a700 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -10,7 +10,9 @@ use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse; use Magento\Quote\Model\Quote; use Magento\Quote\Model\QuoteRepository; +use Magento\Sales\Helper\Data as SalesHelper; use Magento\Sales\Model\Order; +use Magento\Sales\Model\OrderRepository; use Magento\Sales\Model\Order\Email\Sender\InvoiceSender; use Magento\Sales\Model\Order\Email\Sender\OrderCommentSender; use Magento\Sales\Model\Order\Email\Sender\OrderSender; @@ -48,6 +50,14 @@ class Response extends \Heidelpay\Gateway\Controller\HgwAbstract /** @var CollectionFactory */ private $paymentInformationCollectionFactory; + /** + * @var SalesHelper + */ + private $salesHelper; + /** + * @var OrderRepository + */ + private $orderRepository; /** * heidelpay Response constructor. @@ -69,8 +79,10 @@ class Response extends \Heidelpay\Gateway\Controller\HgwAbstract * @param \Magento\Customer\Model\Url $customerUrl * @param \Magento\Framework\Controller\Result\RawFactory $rawResultFactory * @param QuoteRepository $quoteRepository - * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory, + * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory , * @param TransactionFactory $transactionFactory + * @param SalesHelper $salesHelper + * @param OrderRepository $orderRepository */ public function __construct( \Magento\Framework\App\Action\Context $context, @@ -91,7 +103,9 @@ public function __construct( \Magento\Framework\Controller\Result\RawFactory $rawResultFactory, QuoteRepository $quoteRepository, PaymentInformationCollectionFactory $paymentInformationCollectionFactory, - TransactionFactory $transactionFactory + TransactionFactory $transactionFactory, + SalesHelper $salesHelper, + OrderRepository $orderRepository ) { parent::__construct( $context, @@ -115,6 +129,8 @@ public function __construct( $this->quoteRepository = $quoteRepository; $this->paymentInformationCollectionFactory = $paymentInformationCollectionFactory; $this->transactionFactory = $transactionFactory; + $this->salesHelper = $salesHelper; + $this->orderRepository = $orderRepository; } /** @@ -243,7 +259,6 @@ public function execute() $this->_logger->debug($message); // return the heidelpay response url as raw response instead of echoing it out. - $result->setContents($redirectUrl); return $result; } @@ -252,19 +267,7 @@ public function execute() // get the quote by transactionid from the heidelpay response /** @var Quote $quote */ $quote = $this->quoteRepository->get($this->heidelpayResponse->getIdentification()->getTransactionId()); - - $quote->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode()); - $quote->collectTotals(); - // in case of guest checkout, set some customer related data. - if ($this->getRequest()->getPost('CRITERION_GUEST') === 'true') { - $quote->setCustomerId(null) - ->setCustomerEmail($quote->getBillingAddress()->getEmail()) - ->setCustomerIsGuest(true) - ->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID); - } - - // create an order by submitting the quote. - $order = $this->_cartManagement->submit($quote); + $order = $this->createOrderFromQuote($quote); } catch (\Exception $e) { $this->_logger->error('Heidelpay - Response: Cannot submit the Quote. ' . $e->getMessage()); @@ -278,11 +281,80 @@ public function execute() $order ); - $order->save(); + $this->handleOrderMail($order); + $this->handleInvoiceMails($order); + $this->orderRepository->save($order); } // if the customer is a guest, we'll delete the additional payment information, which // is only used for customer recognition. + $this->handleAdittionalPaymentInformation($quote); + $this->_logger->debug('Heidelpay - Response: redirectUrl is ' . $redirectUrl); + + // return the heidelpay response url as raw response instead of echoing it out. + return $result; + } + + /** + * @param $order + */ + protected function handleOrderMail($order) + { + try { + // send order confirmation to the customer + if ($order && $order->getId()) { + $this->_orderSender->send($order); + } + } catch (\Exception $e) { + $this->_logger->error( + 'Heidelpay - Redirect: Cannot send order confirmation E-Mail. ' . $e->getMessage() + ); + } + } + + /** + * @param $order + */ + protected function handleInvoiceMails($order) + { + if (!$order->canInvoice() && $this->salesHelper->canSendNewInvoiceEmail($order->getStore()->getId())) { + $invoices = $order->getInvoiceCollection(); + + foreach ($invoices as $invoice) { + $this->_invoiceSender->send($invoice); + } + } + } + + /** + * @param $quote + * @return \Magento\Framework\Model\AbstractExtensibleModel|\Magento\Sales\Api\Data\OrderInterface|null|object + * @throws \Magento\Framework\Exception\LocalizedException + */ + protected function createOrderFromQuote($quote) + { + $quote->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode()); + $quote->collectTotals(); + // in case of guest checkout, set some customer related data. + if ($this->getRequest()->getPost('CRITERION_GUEST') === 'true') { + $quote->setCustomerId(null) + ->setCustomerEmail($quote->getBillingAddress()->getEmail()) + ->setCustomerIsGuest(true) + ->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID); + } + + // create an order by submitting the quote. + $order = $this->_cartManagement->submit($quote); + + return $order; + } + + /** + * @param $quote + * @throws \Exception + */ + protected function handleAdittionalPaymentInformation($quote) + { if (isset($quote) && $quote->getCustomerIsGuest()) { // create a new instance for the payment information collection. $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); @@ -299,11 +371,5 @@ public function execute() $paymentInfo->delete(); } } - - $this->_logger->debug('Heidelpay - Response: redirectUrl is ' . $redirectUrl); - - // return the heidelpay response url as raw response instead of echoing it out. - $result->setContents($redirectUrl); - return $result; } } From 33431872076ad0db26e22d0fdd3ea455a122a89a Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 27 May 2019 16:26:57 +0200 Subject: [PATCH 030/114] [refactor] (MAGE2-175) Santander Hire Purchase: Change translation. --- i18n/de_DE.csv | 2 +- i18n/en_US.csv | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index afb6dd86d63..f80349d89d9 100755 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -77,7 +77,7 @@ "Please confirm your payment:","Bitte führen Sie nun die Zahlung durch:" "pay now","Jetzt bezahlen" -"Choose installment plan","Ratenplan auswählen" +"Select installment plan","Ratenplan auswählen" "This is a required field.","Dieses Feld ist erforderlich." "Payment information","Zahlungsinformationen" "Reference","Verwendungszweck" diff --git a/i18n/en_US.csv b/i18n/en_US.csv index bc1c99bb623..4b8d586d33e 100755 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -77,7 +77,7 @@ "Please confirm your payment:","Please confirm your payment:" "pay now","pay now" -"Choose installment plan","Choose installment plan" +"Select installment plan","Select installment plan" "This is a required field.","This is a required field." "Payment information","Payment information" "Reference","Reference" From 92b3afc0fc503a97be2ff6702933e3d2460416f3 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 27 May 2019 16:59:27 +0200 Subject: [PATCH 031/114] [cleanup] Apply micro optimizations. --- Controller/Index/Response.php | 75 +++++++++++-------- .../HeidelpayAbstractPaymentMethod.php | 3 +- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index 18ba2a8c18c..922df21c9bc 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -2,18 +2,33 @@ namespace Heidelpay\Gateway\Controller\Index; +use Exception; +use Heidelpay\Gateway\Controller\HgwAbstract; use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper; +use Heidelpay\Gateway\Model\PaymentInformation; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory; use Heidelpay\Gateway\Model\TransactionFactory; +use Magento\Framework\Controller\Result\RawFactory; +use Magento\Sales\Model\OrderFactory; use Heidelpay\PhpPaymentApi\Exceptions\HashVerificationException; use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse; +use Magento\Checkout\Model\Session as CheckoutSession; +use Magento\Customer\Model\Session; +use Magento\Customer\Model\Url; +use Magento\Framework\App\Action\Context; +use Magento\Framework\Encryption\Encryptor; +use Magento\Framework\Url\Helper\Data; +use Magento\Framework\View\Result\PageFactory; +use Magento\Quote\Api\CartManagementInterface; +use Magento\Quote\Api\CartRepositoryInterface; use Magento\Quote\Model\Quote; use Magento\Quote\Model\QuoteRepository; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Email\Sender\InvoiceSender; use Magento\Sales\Model\Order\Email\Sender\OrderCommentSender; use Magento\Sales\Model\Order\Email\Sender\OrderSender; +use Psr\Log\LoggerInterface; /** * Notification handler for the payment response @@ -35,7 +50,7 @@ * * @package heidelpay\magento2\controllers */ -class Response extends \Heidelpay\Gateway\Controller\HgwAbstract +class Response extends HgwAbstract { /** @var QuoteRepository */ private $quoteRepository; @@ -52,43 +67,43 @@ class Response extends \Heidelpay\Gateway\Controller\HgwAbstract /** * heidelpay Response constructor. * - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Checkout\Model\Session $checkoutSession - * @param \Magento\Sales\Model\OrderFactory $orderFactory - * @param \Magento\Framework\Url\Helper\Data $urlHelper - * @param \Psr\Log\LoggerInterface $logger - * @param \Magento\Quote\Api\CartManagementInterface $cartManagement - * @param \Magento\Quote\Api\CartRepositoryInterface $quoteObject - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory + * @param Context $context + * @param Session $customerSession + * @param CheckoutSession $checkoutSession + * @param OrderFactory $orderFactory + * @param Data $urlHelper + * @param LoggerInterface $logger + * @param CartManagementInterface $cartManagement + * @param CartRepositoryInterface $quoteObject + * @param PageFactory $resultPageFactory * @param HeidelpayHelper $paymentHelper * @param OrderSender $orderSender * @param InvoiceSender $invoiceSender * @param OrderCommentSender $orderCommentSender - * @param \Magento\Framework\Encryption\Encryptor $encryptor - * @param \Magento\Customer\Model\Url $customerUrl - * @param \Magento\Framework\Controller\Result\RawFactory $rawResultFactory + * @param Encryptor $encryptor + * @param Url $customerUrl + * @param RawFactory $rawResultFactory * @param QuoteRepository $quoteRepository * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory, * @param TransactionFactory $transactionFactory */ public function __construct( - \Magento\Framework\App\Action\Context $context, - \Magento\Customer\Model\Session $customerSession, - \Magento\Checkout\Model\Session $checkoutSession, - \Magento\Sales\Model\OrderFactory $orderFactory, - \Magento\Framework\Url\Helper\Data $urlHelper, - \Psr\Log\LoggerInterface $logger, - \Magento\Quote\Api\CartManagementInterface $cartManagement, - \Magento\Quote\Api\CartRepositoryInterface $quoteObject, - \Magento\Framework\View\Result\PageFactory $resultPageFactory, + Context $context, + Session $customerSession, + CheckoutSession $checkoutSession, + OrderFactory $orderFactory, + Data $urlHelper, + LoggerInterface $logger, + CartManagementInterface $cartManagement, + CartRepositoryInterface $quoteObject, + PageFactory $resultPageFactory, HeidelpayHelper $paymentHelper, OrderSender $orderSender, InvoiceSender $invoiceSender, OrderCommentSender $orderCommentSender, - \Magento\Framework\Encryption\Encryptor $encryptor, - \Magento\Customer\Model\Url $customerUrl, - \Magento\Framework\Controller\Result\RawFactory $rawResultFactory, + Encryptor $encryptor, + Url $customerUrl, + RawFactory $rawResultFactory, QuoteRepository $quoteRepository, PaymentInformationCollectionFactory $paymentInformationCollectionFactory, TransactionFactory $transactionFactory @@ -119,7 +134,7 @@ public function __construct( /** * @inheritdoc - * @throws \Exception + * @throws Exception */ public function execute() { @@ -158,7 +173,7 @@ public function execute() // initialize the Response object with data from the request. try { $this->heidelpayResponse = HeidelpayResponse::fromPost($this->getRequest()->getParams()); - } catch (\Exception $e) { + } catch (Exception $e) { $this->_logger->error( 'Heidelpay - Response: Cannot initialize response object from Post Request. ' . $e->getMessage() ); @@ -224,7 +239,7 @@ public function execute() ->setJsonResponse(json_encode($data)) ->setSource('RESPONSE') ->save(); - } catch (\Exception $e) { + } catch (Exception $e) { $this->_logger->error('Heidelpay - Response: Save transaction error. ' . $e->getMessage()); } @@ -265,7 +280,7 @@ public function execute() // create an order by submitting the quote. $order = $this->_cartManagement->submit($quote); - } catch (\Exception $e) { + } catch (Exception $e) { $this->_logger->error('Heidelpay - Response: Cannot submit the Quote. ' . $e->getMessage()); return $result; @@ -288,7 +303,7 @@ public function execute() $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); // load the payment information and delete it. - /** @var \Heidelpay\Gateway\Model\PaymentInformation $paymentInfo */ + /** @var PaymentInformation $paymentInfo */ $paymentInfo = $paymentInfoCollection->loadByCustomerInformation( $quote->getStoreId(), $quote->getBillingAddress()->getEmail(), diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index f5c33b4775f..a1debf061a2 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -43,7 +43,6 @@ use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; use Magento\Sales\Model\Order\Payment; -use Magento\Store\Model\ScopeInterface as StoreScopeInterface; use Heidelpay\Gateway\Block\Payment\HgwAbstract; use Heidelpay\PhpPaymentApi\PaymentMethods\PaymentMethodInterface; use Magento\Store\Model\ScopeInterface; @@ -253,7 +252,7 @@ public function getConfigData($field, $storeId = null) $path = 'payment/' . $this->getCode() . '/' . $field; - return $this->_scopeConfig->getValue($path, StoreScopeInterface::SCOPE_STORE, $storeId); + return $this->_scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeId); } /** From 383c66395fb22ac0edfe11267d9a69f091b98b62 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 27 May 2019 17:00:27 +0200 Subject: [PATCH 032/114] [refactor] (MAGE2-175) Santander Hire Purchase: Enable redirect to installment selection. --- ...lpaySantanderHirePurchasePaymentMethod.php | 23 +++++++++++++++++++ .../heidelpay-santander-hire-purchase.html | 9 ++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php index 1ecc0ebe1ed..c7b982e6a8f 100755 --- a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php +++ b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php @@ -15,6 +15,7 @@ */ namespace Heidelpay\Gateway\PaymentMethods; +use Heidelpay\Gateway\Model\PaymentInformation; use Heidelpay\PhpPaymentApi\PaymentMethods\SantanderHirePurchasePaymentMethod; use Magento\Quote\Api\Data\CartInterface; @@ -66,9 +67,31 @@ public function isAvailable(CartInterface $quote = null) */ public function getHeidelpayUrl($quote) { + // create the collection factory + $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); + + // load the payment information by store id, customer email address and payment method + /** @var PaymentInformation $paymentInfo */ + $paymentInfo = $paymentInfoCollection->loadByCustomerInformation( + $quote->getStoreId(), + $quote->getBillingAddress()->getEmail(), + $quote->getPayment()->getMethod() + ); + // set initial data for the request parent::getHeidelpayUrl($quote); + // add salutation and birthdate to the request + if (isset($paymentInfo->getAdditionalData()->hgw_salutation)) { + $this->_heidelpayPaymentMethod->getRequest()->getName() + ->set('salutation', $paymentInfo->getAdditionalData()->hgw_salutation); + } + + if (isset($paymentInfo->getAdditionalData()->hgw_birthdate)) { + $this->_heidelpayPaymentMethod->getRequest()->getName() + ->set('birthdate', $paymentInfo->getAdditionalData()->hgw_birthdate); + } + // send the authorize request $this->_heidelpayPaymentMethod->initialize(); diff --git a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html index 6287c946bd4..68b14008a13 100644 --- a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html +++ b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html @@ -166,11 +166,12 @@
From 759b524c6c3c96b4f1a6cc27a54e0c65638c0efb Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 28 May 2019 14:36:56 +0200 Subject: [PATCH 033/114] [refactor] (MAGE2-175) Santander Hire Purchase: Apply micro optimizations. --- Controller/Index/Index.php | 42 ++++++++++++------- Controller/Index/Response.php | 8 ++-- ...lpaySantanderHirePurchasePaymentMethod.php | 13 +++--- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/Controller/Index/Index.php b/Controller/Index/Index.php index afbb2314469..2023a222057 100755 --- a/Controller/Index/Index.php +++ b/Controller/Index/Index.php @@ -2,13 +2,27 @@ namespace Heidelpay\Gateway\Controller\Index; +use Exception; +use Heidelpay\Gateway\Controller\HgwAbstract; use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper; use Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod; +use Heidelpay\PhpBasketApi\Exception\InvalidBasketitemPositionException; +use Magento\Checkout\Model\Session as CheckoutSession; +use Magento\Customer\Model\Session; +use Magento\Customer\Model\Url; use Magento\Framework\App\Action\Context; +use Magento\Framework\Encryption\Encryptor; use Magento\Framework\Escaper; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Url\Helper\Data; +use Magento\Framework\View\Result\PageFactory; +use Magento\Quote\Api\CartManagementInterface; +use Magento\Quote\Api\CartRepositoryInterface; use Magento\Sales\Model\Order\Email\Sender\InvoiceSender; use Magento\Sales\Model\Order\Email\Sender\OrderCommentSender; use Magento\Sales\Model\Order\Email\Sender\OrderSender; +use Magento\Sales\Model\OrderFactory; +use Psr\Log\LoggerInterface; /** * Customer redirect to heidelpay payment or used to display the payment frontend to the customer @@ -20,27 +34,27 @@ * * @package heidelpay\magento2\controllers */ -class Index extends \Heidelpay\Gateway\Controller\HgwAbstract +class Index extends HgwAbstract { /** @var Escaper */ private $escaper; public function __construct( Context $context, - \Magento\Customer\Model\Session $customerSession, - \Magento\Checkout\Model\Session $checkoutSession, - \Magento\Sales\Model\OrderFactory $orderFactory, - \Magento\Framework\Url\Helper\Data $urlHelper, - \Psr\Log\LoggerInterface $logger, - \Magento\Quote\Api\CartManagementInterface $cartManagement, - \Magento\Quote\Api\CartRepositoryInterface $quoteObject, - \Magento\Framework\View\Result\PageFactory $resultPageFactory, + Session $customerSession, + CheckoutSession $checkoutSession, + OrderFactory $orderFactory, + Data $urlHelper, + LoggerInterface $logger, + CartManagementInterface $cartManagement, + CartRepositoryInterface $quoteObject, + PageFactory $resultPageFactory, HeidelpayHelper $paymentHelper, OrderSender $orderSender, InvoiceSender $invoiceSender, OrderCommentSender $orderCommentSender, - \Magento\Framework\Encryption\Encryptor $encryptor, - \Magento\Customer\Model\Url $customerUrl, + Encryptor $encryptor, + Url $customerUrl, Escaper $escaper ) { parent::__construct( @@ -66,9 +80,9 @@ public function __construct( /** * {@inheritDoc} - * @throws \Heidelpay\PhpBasketApi\Exception\InvalidBasketitemPositionException - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Exception + * @throws InvalidBasketitemPositionException + * @throws LocalizedException + * @throws Exception */ public function execute() { diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index 922df21c9bc..e89832e173f 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -6,11 +6,11 @@ use Heidelpay\Gateway\Controller\HgwAbstract; use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper; use Heidelpay\Gateway\Model\PaymentInformation; -use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory; use Heidelpay\Gateway\Model\TransactionFactory; use Magento\Framework\Controller\Result\RawFactory; use Magento\Sales\Model\OrderFactory; +use Magento\Customer\Model\Group; use Heidelpay\PhpPaymentApi\Exceptions\HashVerificationException; use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse; use Magento\Checkout\Model\Session as CheckoutSession; @@ -84,7 +84,7 @@ class Response extends HgwAbstract * @param Url $customerUrl * @param RawFactory $rawResultFactory * @param QuoteRepository $quoteRepository - * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory, + * @param CollectionFactory $paymentInformationCollectionFactory, * @param TransactionFactory $transactionFactory */ public function __construct( @@ -105,7 +105,7 @@ public function __construct( Url $customerUrl, RawFactory $rawResultFactory, QuoteRepository $quoteRepository, - PaymentInformationCollectionFactory $paymentInformationCollectionFactory, + CollectionFactory $paymentInformationCollectionFactory, TransactionFactory $transactionFactory ) { parent::__construct( @@ -275,7 +275,7 @@ public function execute() $quote->setCustomerId(null) ->setCustomerEmail($quote->getBillingAddress()->getEmail()) ->setCustomerIsGuest(true) - ->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID); + ->setCustomerGroupId(Group::NOT_LOGGED_IN_ID); } // create an order by submitting the quote. diff --git a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php index c7b982e6a8f..24284644938 100755 --- a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php +++ b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php @@ -19,14 +19,14 @@ use Heidelpay\PhpPaymentApi\PaymentMethods\SantanderHirePurchasePaymentMethod; use Magento\Quote\Api\Data\CartInterface; +/** + * @property SantanderHirePurchasePaymentMethod $_heidelpayPaymentMethod + */ class HeidelpaySantanderHirePurchasePaymentMethod extends HeidelpayAbstractPaymentMethod { /** @var string PaymentCode */ const CODE = 'hgwsanhp'; - /** @var SantanderHirePurchasePaymentMethod */ - protected $_heidelpayPaymentMethod; - /** * {@inheritDoc} */ @@ -82,14 +82,13 @@ public function getHeidelpayUrl($quote) parent::getHeidelpayUrl($quote); // add salutation and birthdate to the request + $request = $this->_heidelpayPaymentMethod->getRequest(); if (isset($paymentInfo->getAdditionalData()->hgw_salutation)) { - $this->_heidelpayPaymentMethod->getRequest()->getName() - ->set('salutation', $paymentInfo->getAdditionalData()->hgw_salutation); + $request->getName()->set('salutation', $paymentInfo->getAdditionalData()->hgw_salutation); } if (isset($paymentInfo->getAdditionalData()->hgw_birthdate)) { - $this->_heidelpayPaymentMethod->getRequest()->getName() - ->set('birthdate', $paymentInfo->getAdditionalData()->hgw_birthdate); + $request->getName()->set('birthdate', $paymentInfo->getAdditionalData()->hgw_birthdate); } // send the authorize request From 9937dfb2a9860431cb53fbb0e15aba8f3da7ad40 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Tue, 28 May 2019 15:00:00 +0200 Subject: [PATCH 034/114] (MAGE2-134) refactor: Outsource some parts of response handling into functions. --- Controller/Index/Response.php | 152 +++++++++++++++++++--------------- 1 file changed, 86 insertions(+), 66 deletions(-) diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index da7e149a700..24d2cccddbf 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -5,9 +5,11 @@ use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory; +use Heidelpay\Gateway\Model\Transaction; use Heidelpay\Gateway\Model\TransactionFactory; use Heidelpay\PhpPaymentApi\Exceptions\HashVerificationException; use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse; +use Magento\Framework\Controller\Result\RawFactory; use Magento\Quote\Model\Quote; use Magento\Quote\Model\QuoteRepository; use Magento\Sales\Helper\Data as SalesHelper; @@ -77,7 +79,7 @@ class Response extends \Heidelpay\Gateway\Controller\HgwAbstract * @param OrderCommentSender $orderCommentSender * @param \Magento\Framework\Encryption\Encryptor $encryptor * @param \Magento\Customer\Model\Url $customerUrl - * @param \Magento\Framework\Controller\Result\RawFactory $rawResultFactory + * @param RawFactory $rawResultFactory * @param QuoteRepository $quoteRepository * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory , * @param TransactionFactory $transactionFactory @@ -100,7 +102,7 @@ public function __construct( OrderCommentSender $orderCommentSender, \Magento\Framework\Encryption\Encryptor $encryptor, \Magento\Customer\Model\Url $customerUrl, - \Magento\Framework\Controller\Result\RawFactory $rawResultFactory, + RawFactory $rawResultFactory, QuoteRepository $quoteRepository, PaymentInformationCollectionFactory $paymentInformationCollectionFactory, TransactionFactory $transactionFactory, @@ -139,12 +141,6 @@ public function __construct( */ public function execute() { - // initialize the Raw Response object from the factory. - $result = $this->resultFactory->create(); - - // we just want the response to return a plain url, so we set the header to text/plain. - $result->setHeader('Content-Type', 'text/plain'); - // the url where the payment will redirect the customer to. $redirectUrl = $this->_url->getUrl('hgw/index/redirect', [ '_forced_secure' => true, @@ -152,6 +148,10 @@ public function execute() '_nosid' => true ]); + // initialize the Raw Response object from the factory. + $result = $this->resultFactory->create(); + // we just want the response to return a plain url, so we set the header to text/plain. + $result->setHeader('Content-Type', 'text/plain'); // the payment just wants a url as result, so we set the content to the redirectUrl. $result->setContents($redirectUrl); @@ -186,24 +186,7 @@ public function execute() $secret = $this->_encryptor->exportKeys(); $identificationTransactionId = $this->heidelpayResponse->getIdentification()->getTransactionId(); - $this->_logger->debug('Heidelpay secret: ' . $secret); - $this->_logger->debug('Heidelpay identificationTransactionId: ' . $identificationTransactionId); - - // validate Hash to prevent manipulation - try { - $this->heidelpayResponse->verifySecurityHash($secret, $identificationTransactionId); - } catch (HashVerificationException $e) { - $this->_logger->critical('Heidelpay Response - HashVerification Exception: ' . $e->getMessage()); - $this->_logger->critical( - 'Heidelpay Response - Received request form server ' - . $this->getRequest()->getServer('REMOTE_ADDR') - . ' with an invalid hash. This could be some kind of manipulation.' - ); - $this->_logger->critical( - 'Heidelpay Response - Reference secret hash: ' - . $this->heidelpayResponse->getCriterion()->getSecretHash() - ); - + if(!$this->validateSecurityHash($secret, $identificationTransactionId)) { return $result; } @@ -219,30 +202,7 @@ public function execute() $quote = null; $data = $this->getRequest()->getParams(); - - // save the heidelpay transaction data - list($paymentMethod, $paymentType) = $this->_paymentHelper->splitPaymentCode( - $this->heidelpayResponse->getPayment()->getCode() - ); - - 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(); - } catch (\Exception $e) { - $this->_logger->error('Heidelpay - Response: Save transaction error. ' . $e->getMessage()); - } + $this->saveHeidelpayTransaction($this->heidelpayResponse, $data, 'RESPONSE'); // if something went wrong, return the redirect url without processing the order. if ($this->heidelpayResponse->isError()) { @@ -266,7 +226,7 @@ public function execute() try { // get the quote by transactionid from the heidelpay response /** @var Quote $quote */ - $quote = $this->quoteRepository->get($this->heidelpayResponse->getIdentification()->getTransactionId()); + $quote = $this->quoteRepository->get($identificationTransactionId); $order = $this->createOrderFromQuote($quote); } catch (\Exception $e) { $this->_logger->error('Heidelpay - Response: Cannot submit the Quote. ' . $e->getMessage()); @@ -276,19 +236,14 @@ public function execute() $data['ORDER_ID'] = $order->getIncrementId(); - $this->_paymentHelper->mapStatus( - $data, - $order - ); - + $this->_paymentHelper->mapStatus($data, $order); $this->handleOrderMail($order); $this->handleInvoiceMails($order); + $this->orderRepository->save($order); } - // if the customer is a guest, we'll delete the additional payment information, which - // is only used for customer recognition. - $this->handleAdittionalPaymentInformation($quote); + $this->handleAdditionalPaymentInformation($quote); $this->_logger->debug('Heidelpay - Response: redirectUrl is ' . $redirectUrl); // return the heidelpay response url as raw response instead of echoing it out. @@ -296,12 +251,12 @@ public function execute() } /** + * Send order confirmation to the customer * @param $order */ protected function handleOrderMail($order) { try { - // send order confirmation to the customer if ($order && $order->getId()) { $this->_orderSender->send($order); } @@ -313,6 +268,7 @@ protected function handleOrderMail($order) } /** + * Send invoice mails to the customer * @param $order */ protected function handleInvoiceMails($order) @@ -327,12 +283,14 @@ protected function handleInvoiceMails($order) } /** + * Create an order by submitting the quote. * @param $quote * @return \Magento\Framework\Model\AbstractExtensibleModel|\Magento\Sales\Api\Data\OrderInterface|null|object * @throws \Magento\Framework\Exception\LocalizedException */ protected function createOrderFromQuote($quote) { + // Ensure to use the currency of the quote. $quote->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode()); $quote->collectTotals(); // in case of guest checkout, set some customer related data. @@ -343,19 +301,18 @@ protected function createOrderFromQuote($quote) ->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID); } - // create an order by submitting the quote. - $order = $this->_cartManagement->submit($quote); - - return $order; + return $this->_cartManagement->submit($quote); } /** + * If the customer is a guest, we'll delete the additional payment information, which + * is only used for customer recognition. * @param $quote * @throws \Exception */ - protected function handleAdittionalPaymentInformation($quote) + protected function handleAdditionalPaymentInformation($quote) { - if (isset($quote) && $quote->getCustomerIsGuest()) { + if ($quote !== null && $quote->getCustomerIsGuest()) { // create a new instance for the payment information collection. $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); @@ -372,4 +329,67 @@ protected function handleAdittionalPaymentInformation($quote) } } } + + /** + * Validate Hash to prevent manipulation + * @param $secret + * @param $identificationTransactionId + * @return bool + */ + protected function validateSecurityHash($secret, $identificationTransactionId) + { + $this->_logger->debug('Heidelpay secret: ' . $secret); + $this->_logger->debug('Heidelpay identificationTransactionId: ' . $identificationTransactionId); + + try { + $this->heidelpayResponse->verifySecurityHash($secret, $identificationTransactionId); + return true; + } catch (HashVerificationException $e) { + $this->_logger->critical('Heidelpay Response - HashVerification Exception: ' . $e->getMessage()); + $this->_logger->critical( + 'Heidelpay Response - Received request form server ' + . $this->getRequest()->getServer('REMOTE_ADDR') + . ' with an invalid hash. This could be some kind of manipulation.' + ); + $this->_logger->critical( + 'Heidelpay Response - Reference secret hash: ' + . $this->heidelpayResponse->getCriterion()->getSecretHash() + ); + return false; + } + } + + /** + * Save the heidelpay transaction data + * @param Response $response + * @param $data + * @param $source + * @return void + */ + protected function saveHeidelpayTransaction($response, $data, $source) + { + list($paymentMethod, $paymentType) = $this->_paymentHelper->splitPaymentCode( + $response->getPayment()->getCode() + ); + + try { + // save the response details into the heidelpay Transactions table. + /** @var Transaction $transaction */ + $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(); + } catch (\Exception $e) { + $this->_logger->error('Heidelpay - ' . $source . ': Save transaction error. ' . $e->getMessage()); + } + } } From a28999220cd82df34c52df1ee43ebcf93e55626f Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 29 May 2019 08:36:18 +0200 Subject: [PATCH 035/114] [feature] (MAGE2-175) Santander Hire Purchase: Add risk information to request. --- .../HeidelpayAbstractPaymentMethod.php | 4 +- ...lpaySantanderHirePurchasePaymentMethod.php | 10 ++ Wrapper/CustomerWrapper.php | 113 ++++++++++++++++++ 3 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 Wrapper/CustomerWrapper.php diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index a1debf061a2..ce1fa183028 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -8,11 +8,11 @@ use Heidelpay\Gateway\Helper\BasketHelper; use Heidelpay\Gateway\Helper\Payment as PaymentHelper; use Heidelpay\Gateway\Model\Config\Source\BookingMode; -use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\Transaction\Collection as TransactionCollection; +use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; -use Heidelpay\Gateway\Model\Transaction; use Heidelpay\Gateway\Model\TransactionFactory; +use Heidelpay\Gateway\Model\Transaction; use Heidelpay\PhpBasketApi\Exception\InvalidBasketitemPositionException; use Heidelpay\PhpPaymentApi\ParameterGroups\BasketParameterGroup; use Heidelpay\PhpPaymentApi\Response; diff --git a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php index 24284644938..a28ad99c3cb 100755 --- a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php +++ b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php @@ -16,7 +16,9 @@ namespace Heidelpay\Gateway\PaymentMethods; use Heidelpay\Gateway\Model\PaymentInformation; +use Heidelpay\Gateway\Wrapper\CustomerWrapper; use Heidelpay\PhpPaymentApi\PaymentMethods\SantanderHirePurchasePaymentMethod; +use Magento\Framework\App\ObjectManager; use Magento\Quote\Api\Data\CartInterface; /** @@ -91,6 +93,14 @@ public function getHeidelpayUrl($quote) $request->getName()->set('birthdate', $paymentInfo->getAdditionalData()->hgw_birthdate); } + $objectManager = ObjectManager::getInstance(); + /** @var CustomerWrapper $customer */ + $customer = $objectManager->create(CustomerWrapper::class)->setCustomer($quote->getCustomer()); + $request->getRiskInformation() + ->setCustomerGuestCheckout($customer->isGuest()) + ->setCustomerOrderCount($customer->numberOfOrders()) + ->setCustomerSince($customer->customerSince()); + // send the authorize request $this->_heidelpayPaymentMethod->initialize(); diff --git a/Wrapper/CustomerWrapper.php b/Wrapper/CustomerWrapper.php new file mode 100644 index 00000000000..b9aaf75c75c --- /dev/null +++ b/Wrapper/CustomerWrapper.php @@ -0,0 +1,113 @@ + + * + * @package magento2 + */ +namespace Heidelpay\Gateway\Wrapper; + +use Exception; +use Magento\Customer\Api\Data\CustomerInterface; +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\Api\SearchCriteriaInterface; +use Magento\Framework\Stdlib\DateTime; +use Magento\Sales\Api\OrderRepositoryInterface; +use Magento\Sales\Model\ResourceModel\Order\Collection; +use Magento\Sales\Model\Order; + +class CustomerWrapper +{ + /** @var CustomerInterface */ + private $customer; + + /** @var OrderRepositoryInterface */ + private $orderRepository; + + /** @var SearchCriteriaBuilder */ + private $searchCriteriaBuilder; + + /** @var DateTime */ + private $dateTime; + + /** + * CustomerWrapper constructor. + * + * @param OrderRepositoryInterface $orderRepository + * @param SearchCriteriaBuilder $searchCriteriaBuilder + * @param DateTime $dateTime + */ + public function __construct( + OrderRepositoryInterface $orderRepository, + SearchCriteriaBuilder $searchCriteriaBuilder, + DateTime $dateTime + ) { + $this->orderRepository = $orderRepository; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->dateTime = $dateTime; + } + + /** + * @param CustomerInterface $customer + * @return CustomerWrapper + */ + public function setCustomer($customer) + { + $this->customer = $customer; + + return $this; + } + + /** + * Returns true if the customer is a guest. + * + * @return bool + */ + public function isGuest() + { + return empty($this->customer->getId()); + } + + /** + * Returns the day the customer entity has been created or the current date if it is a guest. + * The date is returned as string in the following format 'yyyy-mm-dd'. + * + * @return string + * @throws Exception + */ + public function customerSince() + { + $date = $this->customer->getCreatedAt(); + if ($this->isGuest()) { + $date = true; + } + return $this->dateTime->formatDate($date, false); + } + + /** + * Returns the number of orders the given customer has created over time. + * + * @return int + */ + public function numberOfOrders() + { + if ($this->isGuest()) { + return 0; + } + + /** @var SearchCriteriaInterface $searchCriteria */ + $searchCriteria = $this->searchCriteriaBuilder + ->addFilter('customer_id', $this->customer->getId()) + ->addFilter('state', Order::STATE_COMPLETE) + ->create(); + + /** @var Collection $orderList */ + $orderList = $this->orderRepository->getList($searchCriteria); + + return $orderList->count(); + } +} From 4fec611f882b0669ea0039400c26f6cbeff31083 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 29 May 2019 11:10:35 +0200 Subject: [PATCH 036/114] [refactor] (MAGE2-175) Santander Hire Purchase: Avoid creating the order if it was an initialization result. Several code optimizations. --- Controller/Index/Response.php | 82 ++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index e89832e173f..bc613aa9c78 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -10,9 +10,14 @@ use Heidelpay\Gateway\Model\TransactionFactory; use Magento\Framework\Controller\Result\RawFactory; use Magento\Sales\Model\OrderFactory; +use Heidelpay\Gateway\Model\Transaction; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Model\AbstractExtensibleModel; +use Magento\Sales\Api\Data\OrderInterface; use Magento\Customer\Model\Group; use Heidelpay\PhpPaymentApi\Exceptions\HashVerificationException; use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse; +use Heidelpay\PhpPaymentApi\Constants\TransactionType; use Magento\Checkout\Model\Session as CheckoutSession; use Magento\Customer\Model\Session; use Magento\Customer\Model\Url; @@ -220,12 +225,12 @@ public function execute() $data = $this->getRequest()->getParams(); // save the heidelpay transaction data - list($paymentMethod, $paymentType) = $this->_paymentHelper->splitPaymentCode( - $this->heidelpayResponse->getPayment()->getCode() - ); + $code = $this->heidelpayResponse->getPayment()->getCode(); + list($paymentMethod, $paymentType) = $this->_paymentHelper->splitPaymentCode($code); try { // save the response details into the heidelpay Transactions table. + /** @var Transaction $transaction */ $transaction = $this->transactionFactory->create(); $transaction->setPaymentMethod($paymentMethod) ->setPaymentType($paymentType) @@ -262,43 +267,43 @@ public function execute() return $result; } - if ($this->heidelpayResponse->isSuccess()) { + // Create order if transaction is successful and not just an initialization + if ($paymentType !== TransactionType::INITIALIZE && $this->heidelpayResponse->isSuccess()) { try { // get the quote by transactionid from the heidelpay response /** @var Quote $quote */ $quote = $this->quoteRepository->get($this->heidelpayResponse->getIdentification()->getTransactionId()); - - $quote->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode()); - $quote->collectTotals(); - // in case of guest checkout, set some customer related data. - if ($this->getRequest()->getPost('CRITERION_GUEST') === 'true') { - $quote->setCustomerId(null) - ->setCustomerEmail($quote->getBillingAddress()->getEmail()) - ->setCustomerIsGuest(true) - ->setCustomerGroupId(Group::NOT_LOGGED_IN_ID); - } - - // create an order by submitting the quote. - $order = $this->_cartManagement->submit($quote); + $order = $this->createOrder($quote); } catch (Exception $e) { $this->_logger->error('Heidelpay - Response: Cannot submit the Quote. ' . $e->getMessage()); - return $result; } $data['ORDER_ID'] = $order->getIncrementId(); - - $this->_paymentHelper->mapStatus( - $data, - $order - ); - + $this->_paymentHelper->mapStatus($data, $order); $order->save(); } // if the customer is a guest, we'll delete the additional payment information, which - // is only used for customer recognition. - if (isset($quote) && $quote->getCustomerIsGuest()) { + // is used for customer recognition and has already been sent to the payment API at this point. + if (isset($quote)) { + $this->removeAdditionalPaymentInformation($quote); + } + + // return the heidelpay response url as raw response instead of echoing it out. + $result->setContents($redirectUrl); + return $result; + } + + /** + * Remove the additional customer information from the payment form. + * + * @param Quote $quote + * @throws Exception + */ + private function removeAdditionalPaymentInformation(Quote $quote) + { + if ($quote->getCustomerIsGuest()) { // create a new instance for the payment information collection. $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); @@ -314,11 +319,28 @@ public function execute() $paymentInfo->delete(); } } + } - $this->_logger->debug('Heidelpay - Response: redirectUrl is ' . $redirectUrl); + /** + * Create the order object from the given quote. + * + * @param Quote $quote + * @return AbstractExtensibleModel|OrderInterface|object|null + * @throws LocalizedException + */ + private function createOrder(Quote $quote) + { + $quote->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode()); + $quote->collectTotals(); + // in case of guest checkout, set some customer related data. + if ($this->getRequest()->getPost('CRITERION_GUEST') === 'true') { + $quote->setCustomerId(null) + ->setCustomerEmail($quote->getBillingAddress()->getEmail()) + ->setCustomerIsGuest(true) + ->setCustomerGroupId(Group::NOT_LOGGED_IN_ID); + } - // return the heidelpay response url as raw response instead of echoing it out. - $result->setContents($redirectUrl); - return $result; + // create an order by submitting the quote. + return $this->_cartManagement->submit($quote); } } From dccf579b6d063eac939e96ef28d38adb0ce468dc Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 29 May 2019 11:11:53 +0200 Subject: [PATCH 037/114] [refactor] Applied several optimizations. --- Helper/Payment.php | 118 +++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/Helper/Payment.php b/Helper/Payment.php index 693c9b8d1f6..1a26cdc8fa0 100755 --- a/Helper/Payment.php +++ b/Helper/Payment.php @@ -1,10 +1,17 @@ httpClientFactory = $httpClientFactory; $this->transactionFactory = $transactionFactory; @@ -57,41 +64,42 @@ public function __construct( parent::__construct($context); } + /** + * Returns an array containing the payment method code and the transaction type code. + * + * @see PaymentMethod + * @see TransactionType + * @param $PAYMENT_CODE + * @return array + */ public function splitPaymentCode($PAYMENT_CODE) { - return preg_split('/\./', $PAYMENT_CODE); + return explode('.', $PAYMENT_CODE); } /** - * @param array $data - * @param \Magento\Sales\Model\Order $order - * @param bool $message + * @param array $data + * @param Order $order + * @param bool $message */ public function mapStatus($data, $order, $message = false) { $paymentCode = $this->splitPaymentCode($data['PAYMENT_CODE']); - $message = !empty($message) ? $message : $data['PROCESSING_RETURN']; - $quoteID = ($order->getLastQuoteId() === false) - ? $order->getQuoteId() - : $order->getLastQuoteId(); // last_quote_id workaround for trusted shop buyerprotection - // If an order has been canceled, closed or complete -> do not change order status. - if ($order->getStatus() == Order::STATE_CANCELED - || $order->getStatus() == Order::STATE_CLOSED - || $order->getStatus() == Order::STATE_COMPLETE - ) { + if (in_array($order->getStatus(), [Order::STATE_CANCELED, Order::STATE_CLOSED, Order::STATE_COMPLETE], true)) { // you can use this event for example to get a notification when a canceled order has been paid return; } - if ($data['PROCESSING_RESULT'] == 'NOK') { - $order->getPayment()->getMethodInstance()->cancelledTransactionProcessing($order, $message); + $payment = $order->getPayment(); + if ($data['PROCESSING_RESULT'] === ProcessingResult::NOK) { + $payment->getMethodInstance()->cancelledTransactionProcessing($order, $message); } elseif ($this->isProcessing($paymentCode[1], $data)) { - $order->getPayment()->getMethodInstance()->processingTransactionProcessing($data, $order); + $payment->getMethodInstance()->processingTransactionProcessing($data, $order); } else { - $order->getPayment()->getMethodInstance()->pendingTransactionProcessing($data, $order, $message); + $payment->getMethodInstance()->pendingTransactionProcessing($data, $order, $message); } } @@ -113,7 +121,7 @@ public function format($number) * @param string|null $errorCode * * @return string - * @throws \Heidelpay\MessageCodeMapper\Exceptions\MissingLocaleFileException + * @throws MissingLocaleFileException */ public function handleError($errorCode = null) { @@ -152,7 +160,7 @@ public function isMatchingCurrency(Order $order, $data) return false; } - return $order->getOrderCurrencyCode() == $data['PRESENTATION_CURRENCY']; + return $order->getOrderCurrencyCode() === $data['PRESENTATION_CURRENCY']; } /** @@ -169,9 +177,15 @@ public function isProcessing($paymentCode, $data) return false; } - return in_array($paymentCode, ['CP', 'DB', 'FI', 'RC']) - && $data['PROCESSING_RESULT'] == 'ACK' - && $data['PROCESSING_STATUS_CODE'] != 80; + $processingTransactions = [ + TransactionType::CAPTURE, + TransactionType::DEBIT, + TransactionType::FINALIZE, + TransactionType::RECEIPT + ]; + return in_array($paymentCode, $processingTransactions, true) + && $data['PROCESSING_RESULT'] === ProcessingResult::ACK + && $data['PROCESSING_STATUS_CODE'] !== StatusCode::WAITING; } /** @@ -184,14 +198,8 @@ 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; + list(, $paymentCode) = $this->splitPaymentCode($data['PAYMENT_CODE']); + return $paymentCode === TransactionType::RESERVATION; } /** @@ -204,21 +212,20 @@ public function isPreAuthorization(array $data) */ public function isReceiptAble($paymentMethod, $paymentType) { - if ($paymentType !== 'RC') { + if ($paymentType !== TransactionType::RECEIPT) { return false; } switch ($paymentMethod) { - case 'DD': - case 'PP': - case 'IV': - case 'OT': - case 'PC': - case 'MP': - case 'HP': + case PaymentMethod::DIRECT_DEBIT: + case PaymentMethod::PREPAYMENT: + case PaymentMethod::INVOICE: + case PaymentMethod::ONLINE_TRANSFER: + case PaymentMethod::PAYMENT_CARD: + case PaymentMethod::MOBILE_PAYMENT: + case PaymentMethod::HIRE_PURCHASE: $return = true; break; - default: $return = false; break; @@ -228,19 +235,16 @@ public function isReceiptAble($paymentMethod, $paymentType) } /** - * Checks if the given paymentcode is viable for a refund transaction. + * Checks if the given payment code is viable for a refund transaction. * - * @param string $paymentcode + * @param string $paymentCode * * @return bool */ - public function isRefundable($paymentcode) + public function isRefundable($paymentCode) { - if ($paymentcode === 'DB' || $paymentcode === 'CP' || $paymentcode === 'RC') { - return true; - } - - return false; + $refundableTransactions = [TransactionType::DEBIT, TransactionType::CAPTURE, TransactionType::RECEIPT]; + return in_array($paymentCode, $refundableTransactions, true); } /** @@ -251,8 +255,6 @@ public function isRefundable($paymentcode) public function saveTransaction(Invoice $invoice) { $transaction = $this->transactionFactory->create(); - $transaction->addObject($invoice) - ->addObject($invoice->getOrder()) - ->save(); + $transaction->addObject($invoice)->addObject($invoice->getOrder())->save(); } } From 35db3d011c246a3cf23dce812fe3b9ef029b5090 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 29 May 2019 11:12:38 +0200 Subject: [PATCH 038/114] [feature] (MAGE2-175) Santander Hire Purchase: Fix risk information. --- PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php index a28ad99c3cb..627bf36db6e 100755 --- a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php +++ b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php @@ -97,7 +97,7 @@ public function getHeidelpayUrl($quote) /** @var CustomerWrapper $customer */ $customer = $objectManager->create(CustomerWrapper::class)->setCustomer($quote->getCustomer()); $request->getRiskInformation() - ->setCustomerGuestCheckout($customer->isGuest()) + ->setCustomerGuestCheckout($customer->isGuest() ? 'TRUE' : 'FALSE') ->setCustomerOrderCount($customer->numberOfOrders()) ->setCustomerSince($customer->customerSince()); From 867fe2e0285983163776db5242b57da4bf7bc210 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Wed, 29 May 2019 14:20:28 +0200 Subject: [PATCH 039/114] (MAGE2-134) refactor: move create order and save transaction function to payment helper. --- Controller/HgwAbstract.php | 5 +-- Controller/Index/Redirect.php | 7 +--- Controller/Index/Response.php | 64 ++---------------------------- Helper/Payment.php | 75 ++++++++++++++++++++++++++++++++++- 4 files changed, 81 insertions(+), 70 deletions(-) diff --git a/Controller/HgwAbstract.php b/Controller/HgwAbstract.php index 4795434dee9..59d56e1262d 100755 --- a/Controller/HgwAbstract.php +++ b/Controller/HgwAbstract.php @@ -3,6 +3,7 @@ namespace Heidelpay\Gateway\Controller; use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper; +use Magento\Quote\Model\QuoteManagement; use Magento\Sales\Model\Order\Email\Sender\OrderSender; use Magento\Sales\Model\Order\Email\Sender\OrderCommentSender; use Magento\Sales\Model\Order\Email\Sender\InvoiceSender; @@ -45,9 +46,7 @@ abstract class HgwAbstract extends \Magento\Framework\App\Action\Action protected $_quoteObject; - /** - * @var \Magento\Quote\Model\QuoteManagement - */ + /** @var QuoteManagement */ protected $_cartManagement; /** diff --git a/Controller/Index/Redirect.php b/Controller/Index/Redirect.php index 8da2eed0e97..8753cfe57a3 100755 --- a/Controller/Index/Redirect.php +++ b/Controller/Index/Redirect.php @@ -172,14 +172,9 @@ public function execute() ->additionalPaymentInformation($data); $this->_checkoutSession->setHeidelpayInfo($additionalPaymentInformation); - $this->_logger->debug('Heidelpay - Redirect: Redirecting customer to success page.'); - // set response - $response = $this->_redirect('checkout/onepage/success', ['_secure' => true]); - - // return response - return $response; + return $this->_redirect('checkout/onepage/success', ['_secure' => true]); } // unlock the quote in case of error diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index 24d2cccddbf..d3319de11d6 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -5,7 +5,6 @@ use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory; -use Heidelpay\Gateway\Model\Transaction; use Heidelpay\Gateway\Model\TransactionFactory; use Heidelpay\PhpPaymentApi\Exceptions\HashVerificationException; use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse; @@ -202,7 +201,7 @@ public function execute() $quote = null; $data = $this->getRequest()->getParams(); - $this->saveHeidelpayTransaction($this->heidelpayResponse, $data, 'RESPONSE'); + $this->_paymentHelper->saveHeidelpayTransaction($this->heidelpayResponse, $data, 'RESPONSE'); // if something went wrong, return the redirect url without processing the order. if ($this->heidelpayResponse->isError()) { @@ -227,7 +226,8 @@ public function execute() // get the quote by transactionid from the heidelpay response /** @var Quote $quote */ $quote = $this->quoteRepository->get($identificationTransactionId); - $order = $this->createOrderFromQuote($quote); + $isGuest = $this->getRequest()->getPost('CRITERION_GUEST') === 'true'; + $order = $this->_paymentHelper->createOrderFromQuote($quote, $isGuest); } catch (\Exception $e) { $this->_logger->error('Heidelpay - Response: Cannot submit the Quote. ' . $e->getMessage()); @@ -282,32 +282,10 @@ protected function handleInvoiceMails($order) } } - /** - * Create an order by submitting the quote. - * @param $quote - * @return \Magento\Framework\Model\AbstractExtensibleModel|\Magento\Sales\Api\Data\OrderInterface|null|object - * @throws \Magento\Framework\Exception\LocalizedException - */ - protected function createOrderFromQuote($quote) - { - // Ensure to use the currency of the quote. - $quote->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode()); - $quote->collectTotals(); - // in case of guest checkout, set some customer related data. - if ($this->getRequest()->getPost('CRITERION_GUEST') === 'true') { - $quote->setCustomerId(null) - ->setCustomerEmail($quote->getBillingAddress()->getEmail()) - ->setCustomerIsGuest(true) - ->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID); - } - - return $this->_cartManagement->submit($quote); - } - /** * If the customer is a guest, we'll delete the additional payment information, which * is only used for customer recognition. - * @param $quote + * @param Quote $quote * @throws \Exception */ protected function handleAdditionalPaymentInformation($quote) @@ -358,38 +336,4 @@ protected function validateSecurityHash($secret, $identificationTransactionId) return false; } } - - /** - * Save the heidelpay transaction data - * @param Response $response - * @param $data - * @param $source - * @return void - */ - protected function saveHeidelpayTransaction($response, $data, $source) - { - list($paymentMethod, $paymentType) = $this->_paymentHelper->splitPaymentCode( - $response->getPayment()->getCode() - ); - - try { - // save the response details into the heidelpay Transactions table. - /** @var Transaction $transaction */ - $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(); - } catch (\Exception $e) { - $this->_logger->error('Heidelpay - ' . $source . ': Save transaction error. ' . $e->getMessage()); - } - } } diff --git a/Helper/Payment.php b/Helper/Payment.php index 693c9b8d1f6..7c74c62935e 100755 --- a/Helper/Payment.php +++ b/Helper/Payment.php @@ -2,11 +2,15 @@ namespace Heidelpay\Gateway\Helper; use Heidelpay\MessageCodeMapper\MessageCodeMapper; +use Heidelpay\PhpPaymentApi\Response; use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\Context; use Magento\Framework\HTTP\ZendClientFactory; +use Magento\Quote\Model\Quote; +use Magento\Quote\Model\QuoteManagement; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; +use Heidelpay\Gateway\Model\TransactionFactory; /** * Heidelpay payment helper @@ -38,23 +42,36 @@ class Payment extends AbstractHelper /** @var \Magento\Framework\Locale\Resolver */ protected $localeResolver; + /** @var QuoteManagement */ + private $_cartManagement; + /** + * @var Heidelpay\Gateway\Model\Transaction + */ + private $heidelpayTransactionFactory; + /** * @param Context $context * @param \Magento\Framework\HTTP\ZendClientFactory $httpClientFactory * @param \Magento\Framework\DB\TransactionFactory $transactionFactory * @param \Magento\Framework\Locale\Resolver $localeResolver + * @param QuoteManagement $cartManagement + * @param Heidelpay\Gateway\Model\Transaction $heidelpayTransactionFactory */ public function __construct( Context $context, \Magento\Framework\HTTP\ZendClientFactory $httpClientFactory, \Magento\Framework\DB\TransactionFactory $transactionFactory, - \Magento\Framework\Locale\Resolver $localeResolver + \Magento\Framework\Locale\Resolver $localeResolver, + QuoteManagement $cartManagement, + TransactionFactory $heidelpayTransactionFactory ) { $this->httpClientFactory = $httpClientFactory; $this->transactionFactory = $transactionFactory; $this->localeResolver = $localeResolver; parent::__construct($context); + $this->_cartManagement = $cartManagement; + $this->heidelpayTransactionFactory = $heidelpayTransactionFactory; } public function splitPaymentCode($PAYMENT_CODE) @@ -255,4 +272,60 @@ public function saveTransaction(Invoice $invoice) ->addObject($invoice->getOrder()) ->save(); } + + /** + * Save the heidelpay transaction data + * @param Response $response + * @param $data + * @param $source + * @return void + */ + public function saveHeidelpayTransaction($response, $data, $source) + { + list($paymentMethod, $paymentType) = $this->splitPaymentCode( + $response->getPayment()->getCode() + ); + + try { + // save the response details into the heidelpay Transactions table. + /** @var Transaction $transaction */ + $transaction = $this->heidelpayTransactionFactory->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(); + } catch (\Exception $e) { + $this->_logger->error('Heidelpay - ' . $source . ': Save transaction error. ' . $e->getMessage()); + } + } + + /** + * Create an order by submitting the quote. + * @param Quote $quote + * @return \Magento\Framework\Model\AbstractExtensibleModel|\Magento\Sales\Api\Data\OrderInterface|null|object + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function createOrderFromQuote($quote, $isGuest = false) + { + // Ensure to use the currency of the quote. + $quote->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode()); + $quote->collectTotals(); + // in case of guest checkout, set some customer related data. + if ($isGuest) { + $quote->setCustomerId(null) + ->setCustomerEmail($quote->getBillingAddress()->getEmail()) + ->setCustomerIsGuest(true) + ->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID); + } + + return $this->_cartManagement->submit($quote); + } } From ea19c511b5cf549c3cd6c338b4c6eb4b396c9a04 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Wed, 29 May 2019 16:44:47 +0200 Subject: [PATCH 040/114] Update Controller/Index/Response.php Co-Authored-By: Simon Gabriel --- Controller/Index/Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index d3319de11d6..50eed49efd5 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -151,7 +151,7 @@ public function execute() $result = $this->resultFactory->create(); // we just want the response to return a plain url, so we set the header to text/plain. $result->setHeader('Content-Type', 'text/plain'); - // the payment just wants a url as result, so we set the content to the redirectUrl. + // the payment just wants an url as result, so we set the content to the redirectUrl. $result->setContents($redirectUrl); // if there is no post request, just redirect to the cart instantly and show an error message to the customer. From bc856c3ec28a01b399bb6941c1dfd25ba2a0c6b1 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Wed, 29 May 2019 16:54:07 +0200 Subject: [PATCH 041/114] Update Controller/Index/Response.php Co-Authored-By: Simon Gabriel --- Controller/Index/Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index 50eed49efd5..9521cab8d7b 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -262,7 +262,7 @@ protected function handleOrderMail($order) } } catch (\Exception $e) { $this->_logger->error( - 'Heidelpay - Redirect: Cannot send order confirmation E-Mail. ' . $e->getMessage() + 'Heidelpay - Response: Cannot send order confirmation E-Mail. ' . $e->getMessage() ); } } From ec95a777f23a483f95a4bbca5fb1e4bb71e0693f Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 31 May 2019 11:18:11 +0200 Subject: [PATCH 042/114] [refactor] (MAGE2-175) Santander Hire Purchase: Remove debug outputs. --- PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php index 627bf36db6e..a7df2412081 100755 --- a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php +++ b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php @@ -93,6 +93,7 @@ public function getHeidelpayUrl($quote) $request->getName()->set('birthdate', $paymentInfo->getAdditionalData()->hgw_birthdate); } + // set risk information $objectManager = ObjectManager::getInstance(); /** @var CustomerWrapper $customer */ $customer = $objectManager->create(CustomerWrapper::class)->setCustomer($quote->getCustomer()); @@ -101,7 +102,7 @@ public function getHeidelpayUrl($quote) ->setCustomerOrderCount($customer->numberOfOrders()) ->setCustomerSince($customer->customerSince()); - // send the authorize request + // send the initialize request $this->_heidelpayPaymentMethod->initialize(); return $this->_heidelpayPaymentMethod->getResponse(); From e94e463696edbf5cdb938801f60f467498c86dee Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 31 May 2019 12:42:04 +0200 Subject: [PATCH 043/114] [refactor] Apply micro optimization. --- Controller/Index/Index.php | 3 ++- Controller/Index/Response.php | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Controller/Index/Index.php b/Controller/Index/Index.php index 2023a222057..c5539f205cd 100755 --- a/Controller/Index/Index.php +++ b/Controller/Index/Index.php @@ -7,6 +7,7 @@ use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper; use Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod; use Heidelpay\PhpBasketApi\Exception\InvalidBasketitemPositionException; +use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse; use Magento\Checkout\Model\Session as CheckoutSession; use Magento\Customer\Model\Session; use Magento\Customer\Model\Url; @@ -100,7 +101,7 @@ public function execute() $payment = $quote->getPayment()->getMethodInstance(); // get the response object from the initial request. - /** @var \Heidelpay\PhpPaymentApi\Response $response */ + /** @var HeidelpayResponse $response */ $response = $payment->getHeidelpayUrl($quote); $this->_logger->debug('Heidelpay init response : ' . print_r($response, 1)); diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index bc613aa9c78..27553206f03 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -295,6 +295,8 @@ public function execute() return $result; } + // + /** * Remove the additional customer information from the payment form. * @@ -343,4 +345,6 @@ private function createOrder(Quote $quote) // create an order by submitting the quote. return $this->_cartManagement->submit($quote); } + + // } From 8be2d7cd4cf271871414ed52a783563b39f4149d Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Wed, 29 May 2019 17:32:48 +0200 Subject: [PATCH 044/114] (MAGE2-134) refactor: solve PR discussions --- Controller/Index/Redirect.php | 6 ------ Controller/Index/Response.php | 21 +++++++++---------- Helper/Payment.php | 4 ++-- .../HeidelpayAbstractPaymentMethod.php | 2 +- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/Controller/Index/Redirect.php b/Controller/Index/Redirect.php index 8753cfe57a3..d8ed3f4b565 100755 --- a/Controller/Index/Redirect.php +++ b/Controller/Index/Redirect.php @@ -144,9 +144,6 @@ public function execute() // set Parameters for success page if ($this->heidelpayResponse->isSuccess()) { - // lock the quote - //$session->getQuote()->setIsActive(false)->save(); - /** @var Order $order */ $order = null; try { @@ -177,9 +174,6 @@ public function execute() return $this->_redirect('checkout/onepage/success', ['_secure' => true]); } - // unlock the quote in case of error - $session->getQuote()->setIsActive(true)->save(); - $this->_logger->error( 'Heidelpay - Redirect: Redirect with error to cart: ' . $this->heidelpayResponse->getError()['message'] ); diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index 9521cab8d7b..ac1cd0656b9 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -182,10 +182,7 @@ public function execute() return $result; } - $secret = $this->_encryptor->exportKeys(); - $identificationTransactionId = $this->heidelpayResponse->getIdentification()->getTransactionId(); - - if(!$this->validateSecurityHash($secret, $identificationTransactionId)) { + if(!$this->validateSecurityHash($this->heidelpayResponse)) { return $result; } @@ -223,11 +220,11 @@ public function execute() if ($this->heidelpayResponse->isSuccess()) { try { + $identificationTransactionId = $this->heidelpayResponse->getIdentification()->getTransactionId(); // get the quote by transactionid from the heidelpay response /** @var Quote $quote */ $quote = $this->quoteRepository->get($identificationTransactionId); - $isGuest = $this->getRequest()->getPost('CRITERION_GUEST') === 'true'; - $order = $this->_paymentHelper->createOrderFromQuote($quote, $isGuest); + $order = $this->_paymentHelper->createOrderFromQuote($quote); } catch (\Exception $e) { $this->_logger->error('Heidelpay - Response: Cannot submit the Quote. ' . $e->getMessage()); @@ -310,17 +307,19 @@ protected function handleAdditionalPaymentInformation($quote) /** * Validate Hash to prevent manipulation - * @param $secret - * @param $identificationTransactionId + * @param HeidelpayResponse $response * @return bool */ - protected function validateSecurityHash($secret, $identificationTransactionId) + protected function validateSecurityHash($response) { + $secret = $this->_encryptor->exportKeys(); + $identificationTransactionId = $response->getIdentification()->getTransactionId(); + $this->_logger->debug('Heidelpay secret: ' . $secret); $this->_logger->debug('Heidelpay identificationTransactionId: ' . $identificationTransactionId); try { - $this->heidelpayResponse->verifySecurityHash($secret, $identificationTransactionId); + $response->verifySecurityHash($secret, $identificationTransactionId); return true; } catch (HashVerificationException $e) { $this->_logger->critical('Heidelpay Response - HashVerification Exception: ' . $e->getMessage()); @@ -331,7 +330,7 @@ protected function validateSecurityHash($secret, $identificationTransactionId) ); $this->_logger->critical( 'Heidelpay Response - Reference secret hash: ' - . $this->heidelpayResponse->getCriterion()->getSecretHash() + . $response->getCriterion()->getSecretHash() ); return false; } diff --git a/Helper/Payment.php b/Helper/Payment.php index 7c74c62935e..4db074f33ed 100755 --- a/Helper/Payment.php +++ b/Helper/Payment.php @@ -313,13 +313,13 @@ public function saveHeidelpayTransaction($response, $data, $source) * @return \Magento\Framework\Model\AbstractExtensibleModel|\Magento\Sales\Api\Data\OrderInterface|null|object * @throws \Magento\Framework\Exception\LocalizedException */ - public function createOrderFromQuote($quote, $isGuest = false) + public function createOrderFromQuote($quote) { // Ensure to use the currency of the quote. $quote->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode()); $quote->collectTotals(); // in case of guest checkout, set some customer related data. - if ($isGuest) { + if ($quote->getCustomerId() === null) { $quote->setCustomerId(null) ->setCustomerEmail($quote->getBillingAddress()->getEmail()) ->setCustomerIsGuest(true) diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 0f29da6b890..b5d07844447 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -616,7 +616,7 @@ public function getUser($order) $billingStreet .= $street . ' '; } - $user['CRITERION.GUEST'] = $order->getCustomer()->getId() == 0 ? 'true' : 'false'; + $user['CRITERION.GUEST'] = $order->getCustomer()->getId() === null ? 'true' : 'false'; $user['NAME.COMPANY'] = ($billing->getCompany() === false) ? null : trim($billing->getCompany()); $user['NAME.GIVEN'] = trim($billing->getFirstname()); From 98606f432b6b3d391876d2f0ff569850523d27a2 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 7 Jun 2019 10:27:28 +0200 Subject: [PATCH 045/114] [refactor] Reduced complexity of hgw-block. --- Block/Hgw.php | 24 ++++++------------------ Controller/Index/Index.php | 9 +++++---- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/Block/Hgw.php b/Block/Hgw.php index 5ce879a1eb0..9b512317ae5 100755 --- a/Block/Hgw.php +++ b/Block/Hgw.php @@ -1,10 +1,11 @@ _hgwUrl = $url; - } - - protected function getHgwUrl() { - return $this->_hgwUrl; - } - */ } diff --git a/Controller/Index/Index.php b/Controller/Index/Index.php index c5539f205cd..e6efb651848 100755 --- a/Controller/Index/Index.php +++ b/Controller/Index/Index.php @@ -3,6 +3,7 @@ namespace Heidelpay\Gateway\Controller\Index; use Exception; +use Heidelpay\Gateway\Block\Hgw; use Heidelpay\Gateway\Controller\HgwAbstract; use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper; use Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod; @@ -114,10 +115,10 @@ public function execute() $resultPage = $this->_resultPageFactory->create(); $resultPage->getConfig()->getTitle()->prepend(__('Please confirm your payment:')); - $resultPage->getLayout()->getBlock('heidelpay_gateway')->setHgwUrl( - $response->getPaymentFormUrl() - ); - $resultPage->getLayout()->getBlock('heidelpay_gateway')->setHgwCode($payment->getCode()); + + /** @var Hgw $hgwBlock */ + $hgwBlock = $resultPage->getLayout()->getBlock('heidelpay_gateway'); + $hgwBlock->setHgwUrl($response->getPaymentFormUrl())->setHgwCode($payment->getCode()); return $resultPage; } From dda4ebe8be178659f8560e952212cec9b38e11f3 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 7 Jun 2019 10:32:16 +0200 Subject: [PATCH 046/114] [refactor] Apply micro optimization. --- .../web/js/view/payment/method-renderer/hgw-abstract.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js b/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js index 5d9615ac4a9..6f785088860 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js @@ -143,7 +143,7 @@ define( checkoutData.setSelectedPaymentMethod(this.item.method); return true; - } + }, }); } ); From 7d5e131915df05fd94543f3249a8ab4a870c2ab4 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 7 Jun 2019 15:00:03 +0200 Subject: [PATCH 047/114] [refactor] Apply micro optimization and fix style issues. --- Api/Payment.php | 126 ++++++++++++++++++-------------- Api/PaymentInterface.php | 2 +- Model/TransactionRepository.php | 79 ++++++++++---------- 3 files changed, 112 insertions(+), 95 deletions(-) diff --git a/Api/Payment.php b/Api/Payment.php index 325d54c4404..0f7ddc2a87e 100755 --- a/Api/Payment.php +++ b/Api/Payment.php @@ -1,13 +1,5 @@ quoteRepository = $quoteRepository; $this->quoteIdMaskFactory = $quoteIdMaskFactory; @@ -82,24 +92,25 @@ public function getAdditionalPaymentInformation($quoteId, $paymentMethod) { $result = null; + /** @var PaymentInformationInterface|Quote $quote */ // get the quote information by cart id - $quote = $this->quoteRepository->get($quoteId); + $quote = $this->quoteRepository->getById($quoteId); // get the recognition configuration for the given payment method and store id. $allowRecognition = $this->scopeConfig->getValue( 'payment/' . $paymentMethod . '/recognition', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + ScopeInterface::SCOPE_STORE, $quote->getStoreId() ); // if recognition is set to 'never', we don't return any data. - if ($allowRecognition == Recognition::RECOGNITION_NEVER) { + if ($allowRecognition === Recognition::RECOGNITION_NEVER) { return json_encode(null); } // get the customer payment information by given data from the request. $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); - /** @var \Heidelpay\Gateway\Model\PaymentInformation $paymentInfo */ + /** @var PaymentInformation $paymentInfo */ $paymentInfo = $paymentInfoCollection->loadByCustomerInformation( $quote->getStoreId(), $quote->getCustomerEmail(), @@ -115,8 +126,8 @@ public function getAdditionalPaymentInformation($quoteId, $paymentMethod) // we only return additional payment data, if the shipping data is the same (to prevent fraud) if ($allowRecognition === Recognition::RECOGNITION_SAME_SHIPPING_ADDRESS) { - // if the shipping hashes are the same, we can safely return the addtional payment data. - if ($this->createShippingHash($quote->getShippingAddress()) == $paymentInfo->getShippingHash()) { + // if the shipping hashes are the same, we can safely return the additional payment data. + if ($this->createShippingHash($quote->getShippingAddress()) === $paymentInfo->getShippingHash()) { $result = $paymentInfo->getAdditionalData(); } } @@ -136,23 +147,25 @@ public function getAdditionalPaymentInformation($quoteId, $paymentMethod) */ public function saveAdditionalPaymentInfo($cartId, $method, $additionalData) { + $returnValue = true; + + /** @var PaymentInformationInterface|Quote $quote */ // get the quote information by cart id - $quote = $this->quoteRepository->get($cartId); + $quote = $this->quoteRepository->getById($cartId); - // if the quote is empty, there is no relation that - // we can work with... so we return false. + // if the quote is empty, there is no relation that we can work with... so we return false. if ($quote->isEmpty()) { - return json_encode(false); + $returnValue = false; } // save the information with the given quote and additional data. // if there is nothing stored, we'll return false... - if (!$this->savePaymentInformation($quote, $method, $quote->getCustomerEmail(), $additionalData)) { - return json_encode(false); + if ($returnValue && !$this->savePaymentInformation($quote, $method, $quote->getCustomerEmail(), $additionalData)) { + $returnValue = false; } // ... if it was successful, we return true. - return json_encode(true); + return json_encode($returnValue); } /** @@ -160,38 +173,41 @@ public function saveAdditionalPaymentInfo($cartId, $method, $additionalData) */ public function saveGuestAdditionalPaymentInfo($cartId, $method, $additionalData) { + $returnValue = true; + // get the real quote id by guest cart id (masked random string serves as guest cart id) - /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ + /** @var QuoteIdMask $quoteIdMask */ $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); $quoteId = $quoteIdMask->getQuoteId(); + /** @var PaymentInformationInterface|Quote $quote */ // get the quote information by cart id - $quote = $this->quoteRepository->get($quoteId); + $quote = $this->quoteRepository->getById($quoteId); // if the quote is empty, there is no relation that // we can work with... so we return false. if ($quote->isEmpty()) { - return json_encode(false); + $returnValue = false; } // save the information with the given quote and additional data. // if there is nothing stored, we'll return false... // - since guest email is stored in the billing information, we have to pull it from there. - if (!$this->savePaymentInformation($quote, $method, $quote->getBillingAddress()->getEmail(), $additionalData)) { - return json_encode(false); + if ($returnValue && !$this->savePaymentInformation($quote, $method, $quote->getBillingAddress()->getEmail(), $additionalData)) { + $returnValue = false; } // ... if it was successful, we return true. - return json_encode(true); + return json_encode($returnValue); } /** * Create a shipping hash. * - * @param \Magento\Quote\Api\Data\AddressInterface $address + * @param AddressInterface $address * @return string */ - private function createShippingHash(\Magento\Quote\Api\Data\AddressInterface $address) + private function createShippingHash(AddressInterface $address) { return $this->encryptor->hash( implode('', [ @@ -216,7 +232,7 @@ private function createShippingHash(\Magento\Quote\Api\Data\AddressInterface $ad * the Billing address. * * @param string $method - * @param \Magento\Quote\Model\Quote $quote + * @param Quote $quote * @return array|null */ private function getAdditionalDataForPaymentMethod($method, $quote) @@ -251,19 +267,19 @@ private function getAdditionalDataForPaymentMethod($method, $quote) * If a data set with the given information exists, it will just * be updated. Else, a new data set will be created. * - * @param \Magento\Quote\Model\Quote $quote + * @param Quote $quote * @param string $method * @param string $email * @param array $additionalData * @param string $paymentRef - * @return \Heidelpay\Gateway\Api\Data\PaymentInformationInterface + * @return PaymentInformationInterface */ private function savePaymentInformation($quote, $method, $email, $additionalData, $paymentRef = null) { - // make some additional data changes, if neccessary - array_walk($additionalData, function (&$value, $key) { + // make some additional data changes, if necessary + array_walk($additionalData, static function (&$value, $key) { // if somehow the country code in the IBAN is lowercase, convert it to uppercase. - if ($key == 'hgw_iban') { + if ($key === 'hgw_iban') { $value = strtoupper($value); } }); @@ -272,7 +288,7 @@ private function savePaymentInformation($quote, $method, $email, $additionalData $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); // load payment information by the customer's quote. - /** @var \Heidelpay\Gateway\Model\PaymentInformation $paymentInfo */ + /** @var PaymentInformationInterface $paymentInfo */ $paymentInformation = $paymentInfoCollection->loadByCustomerInformation( $quote->getStoreId(), $email, diff --git a/Api/PaymentInterface.php b/Api/PaymentInterface.php index 0c9cb60f130..7e2686e29bc 100755 --- a/Api/PaymentInterface.php +++ b/Api/PaymentInterface.php @@ -6,7 +6,7 @@ * API implementation for the heidelpay Payment functionality * * To work with additional data, the module stored customer payment information - * in a seperate data set to avoid mixing up Magento 2 and heidelpay data. + * in a separate data set to avoid mixing up Magento 2 and heidelpay data. * * @license Use of this software requires acceptance of the License Agreement. See LICENSE file. * @copyright Copyright © 2016-present heidelpay GmbH. All rights reserved. diff --git a/Model/TransactionRepository.php b/Model/TransactionRepository.php index d453ecfcde8..79f2e2c1247 100755 --- a/Model/TransactionRepository.php +++ b/Model/TransactionRepository.php @@ -1,51 +1,41 @@ getCacheKey([$id]); - if (!isset($this->instances[$id][$cacheKey]) || $forceReload) { + if ($forceReload || !isset($this->instances[$id][$cacheKey])) { $transaction = $this->transactionFactory->create(); if (!$id) { - throw new NoSuchEntityException(__('Requested product doesn\'t exist')); + throw new NoSuchEntityException(__('Requested transaction does not exist')); } $transaction->load($id); @@ -73,15 +69,20 @@ public function get($id, $forceReload = false) return $this->instances[$id][$cacheKey]; } - public function getByQuoteId($quoteId, $forceReload = false) - { - $cacheKey = $this->getCacheKey([$quoteId]); - if (!isset($this->instancesByQuoteId[$quoteId][$cacheKey]) || $forceReload) { - $transaction = $this->transactionFactory->create(); - - $transactionId = $this->resourceModel; - } - } +// /** +// * Fetches a a list of transactions by qouteId. +// * +// * @param $quoteId +// * @param bool $forceReload +// */ +// public function getByQuoteId($quoteId, $forceReload = false) +// { +// $cacheKey = $this->getCacheKey([$quoteId]); +// if ($forceReload || !isset($this->instancesByQuoteId[$quoteId][$cacheKey])) { +// $transaction = $this->transactionFactory->create(); +// $transactionId = $this->resourceModel; +// } +// } /** * Get key for cache From 313640db389b4f843cc66b36f1b229f919aa2c16 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 17 Jun 2019 11:49:19 +0200 Subject: [PATCH 048/114] [refactor] Apply micro optimization. --- Api/Data/PaymentInformationInterface.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Api/Data/PaymentInformationInterface.php b/Api/Data/PaymentInformationInterface.php index 19acf7bbe3b..a21881d9930 100755 --- a/Api/Data/PaymentInformationInterface.php +++ b/Api/Data/PaymentInformationInterface.php @@ -1,7 +1,4 @@ Date: Mon, 17 Jun 2019 11:52:32 +0200 Subject: [PATCH 049/114] [feature] (MAGE2-175) Santander Hire Purchase: Add basic provisions to show payment plan in checkout. --- Api/Payment.php | 4 ++ Block/Hgw.php | 2 + Controller/Index/Response.php | 19 +++++- i18n/de_DE.csv | 3 + i18n/en_US.csv | 3 + .../layout/installment_plan_index_index.xml | 11 ++++ .../frontend/templates/installment-plan.phtml | 26 ++++++++ .../hgw-santander-hire-purchase.js | 38 ++++++------ ...tander-hire-purchase-installment-plan.html | 61 +++++++++++++++++++ 9 files changed, 146 insertions(+), 21 deletions(-) create mode 100644 view/frontend/layout/installment_plan_index_index.xml create mode 100644 view/frontend/templates/installment-plan.phtml create mode 100644 view/frontend/web/template/payment/heidelpay-santander-hire-purchase-installment-plan.html diff --git a/Api/Payment.php b/Api/Payment.php index 0f7ddc2a87e..3294a410b33 100755 --- a/Api/Payment.php +++ b/Api/Payment.php @@ -253,6 +253,10 @@ private function getAdditionalDataForPaymentMethod($method, $quote) $result['hgw_birthdate'] = $quote->getCustomer()->getDob(); break; + case 'hgwsanhp': + $result['hgw_installment_plan_url'] = 'http://www.google.com'; + break; + default: $result = null; break; diff --git a/Block/Hgw.php b/Block/Hgw.php index 9b512317ae5..17ad39b4f7d 100755 --- a/Block/Hgw.php +++ b/Block/Hgw.php @@ -19,6 +19,8 @@ * * @method setHgwUrl(string $url) * @method getHgwUrl() + * @method setInstallmentPlanUrl(string $url) + * @method getInstallmentPlanUrl() */ class Hgw extends Template { diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index 9f9837affad..7274e31b617 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -10,6 +10,7 @@ use Heidelpay\Gateway\Model\TransactionFactory; use Magento\Framework\Controller\Result\RawFactory; use Magento\Sales\Model\OrderFactory; +use Heidelpay\PhpPaymentApi\Constants\PaymentMethod; use Heidelpay\Gateway\Model\Transaction; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Model\AbstractExtensibleModel; @@ -267,8 +268,22 @@ public function execute() return $result; } - // Create order if transaction is successful and not just an initialization - if ($paymentType !== TransactionType::INITIALIZE && $this->heidelpayResponse->isSuccess()) { + if ($paymentType === TransactionType::INITIALIZE && $paymentMethod === PaymentMethod::HIRE_PURCHASE) { + if ($this->heidelpayResponse->isSuccess()) { + $redirectUrl = $this->_url->getUrl('hgw/index/', [ + '_forced_secure' => true, + '_scope_to_url' => true, + '_nosid' => true + ]); + } + + // return the heidelpay response url as raw response instead of echoing it out. + $result->setContents($redirectUrl); + return $result; + } + + // Create order if transaction is successful + if ($this->heidelpayResponse->isSuccess()) { try { // get the quote by transactionid from the heidelpay response /** @var Quote $quote */ diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index f80349d89d9..33a334a6494 100755 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -88,3 +88,6 @@ "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." + +"Hire Purchase Precontract","Vorvertragliche Informationen:" +"Hire Purchase Precontract download","Vorvertragliche Informationen zum Ratenkauf hier abrufen" diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 4b8d586d33e..cee5fc829e7 100755 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -88,3 +88,6 @@ "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." + +"Hire Purchase Precontract","Precontract:" +"Hire Purchase Precontract download","Download precontract here" diff --git a/view/frontend/layout/installment_plan_index_index.xml b/view/frontend/layout/installment_plan_index_index.xml new file mode 100644 index 00000000000..09d0a04580c --- /dev/null +++ b/view/frontend/layout/installment_plan_index_index.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/view/frontend/templates/installment-plan.phtml b/view/frontend/templates/installment-plan.phtml new file mode 100644 index 00000000000..477d5fc8a9e --- /dev/null +++ b/view/frontend/templates/installment-plan.phtml @@ -0,0 +1,26 @@ + + +
+ + +

+ +
diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js b/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js index 08b90a9c32f..c3a7caf95e0 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js @@ -23,6 +23,7 @@ define( defaults: { template: 'Heidelpay_Gateway/payment/heidelpay-santander-hire-purchase', + hgwInstallmentPlanUrl: '', hgwDobYear: '', hgwDobMonth: '', hgwDobDay: '', @@ -34,11 +35,14 @@ define( this._super(); this.getAdditionalPaymentInformation(); - // init years select menu - for (var i = (new Date().getFullYear() - 17); i >= new Date().getFullYear() - 120; i--) { - this.years.push(i); + if (this.hgwInstallmentPlanUrl !== '') { + this.template = 'Heidelpay_Gateway/payment/heidelpay-santander-hire-purchase-installment-plan'; + } else { + // init years select menu + for (let i = (new Date().getFullYear() - 17); i >= new Date().getFullYear() - 120; i--) { + this.years.push(i); + } } - return this; }, @@ -67,22 +71,10 @@ define( function(data) { var info = JSON.parse(data); - // set salutation and birthdate, if set. + // set link to installment plan if( info !== null ) { - if (info.hasOwnProperty('hgw_salutation')) - parent.hgwSalutation(info.hgw_salutation); - - if (info.hasOwnProperty('hgw_birthdate') && info.hgw_birthdate !== null) { - var date = moment(info.hgw_birthdate, 'YYYY-MM-DD'); - - parent.hgwDobDay(date.date()); - parent.hgwDobMonth(date.month()); - parent.hgwDobYear(date.year()); - - // workaround: if month is 'january', the month isn't selected. - if (date.month() === 0) { - $("#hgwsanhp_birthdate_month option:eq(1)").prop('selected', true); - } + if (info.hasOwnProperty('hgw_installment_plan_url')) { + parent.hgwInstallmentPlanUrl = info.hgw_installment_plan_url; } } } @@ -125,6 +117,14 @@ define( var form = $('#hgw-santander-hire-purchase'); return form.validation() && form.validation('isValid'); + }, + + /** + * Returns the installmentPlanUrl + * @returns {string} + */ + getInstallmentPlan: function () { + return this.hgwInstallmentPlanUrl } }); } diff --git a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase-installment-plan.html b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase-installment-plan.html new file mode 100644 index 00000000000..6e3dfeeaea1 --- /dev/null +++ b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase-installment-plan.html @@ -0,0 +1,61 @@ + +
+
+ + +
+ +
+ + + +
+ +
+
+ +
+ +
+
+
+
+
+ + + +
+
+
+ +
+
+
+
From 88b7a9b4c8550f3355d99c881c315ee7cbb3ac47 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 17 Jun 2019 12:11:51 +0200 Subject: [PATCH 050/114] [feature] (MAGE2-175) Santander Hire Purchase: Add basic provisions to show payment plan in checkout #2. --- Model/TransactionRepositoryInterface.php | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Model/TransactionRepositoryInterface.php diff --git a/Model/TransactionRepositoryInterface.php b/Model/TransactionRepositoryInterface.php new file mode 100644 index 00000000000..bc1f1a3e478 --- /dev/null +++ b/Model/TransactionRepositoryInterface.php @@ -0,0 +1,28 @@ + + * + * @package heidelpay/${Package} + */ + +namespace Heidelpay\Gateway\Model; + +use Magento\Framework\Exception\NoSuchEntityException; + +interface TransactionRepositoryInterface +{ + /** + * @param $id + * @param bool $forceReload + * @return mixed + * @throws NoSuchEntityException + */ + public function getById($id, $forceReload = false); +} \ No newline at end of file From 255dca60e33b9caec1fe8cec42ed3314141e6c81 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 17 Jun 2019 15:35:45 +0200 Subject: [PATCH 051/114] [feature] (MAGE2-175) Santander Hire Purchase: Fix redirect after payment plan selection. --- Api/Payment.php | 18 ++++++++---------- Controller/Index/Response.php | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Api/Payment.php b/Api/Payment.php index 3294a410b33..2e6a74b858f 100755 --- a/Api/Payment.php +++ b/Api/Payment.php @@ -20,10 +20,9 @@ use Heidelpay\Gateway\Model\PaymentInformation; use Heidelpay\Gateway\Model\PaymentInformationFactory; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; -use Heidelpay\Gateway\Model\TransactionRepository; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; -use Klarna\Kp\Api\QuoteRepositoryInterface; +use Magento\Quote\Model\QuoteRepository; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Encryption\EncryptorInterface; use Magento\Quote\Api\Data\AddressInterface; @@ -57,7 +56,7 @@ class Payment implements PaymentInterface /** * Payment Information API constructor. * - * @param QuoteRepositoryInterface $quoteRepository + * @param QuoteRepository $quoteRepository * @param QuoteIdMaskFactory $quoteIdMaskFactory * @param PaymentInformationFactory $paymentInformationFactory * @param EncryptorInterface $encryptor @@ -66,7 +65,7 @@ class Payment implements PaymentInterface * @param ScopeConfigInterface $scopeConfig */ public function __construct( - QuoteRepositoryInterface $quoteRepository, + QuoteRepository $quoteRepository, QuoteIdMaskFactory $quoteIdMaskFactory, PaymentInformationFactory $paymentInformationFactory, EncryptorInterface $encryptor, @@ -92,9 +91,8 @@ public function getAdditionalPaymentInformation($quoteId, $paymentMethod) { $result = null; - /** @var PaymentInformationInterface|Quote $quote */ // get the quote information by cart id - $quote = $this->quoteRepository->getById($quoteId); + $quote = $this->quoteRepository->get($quoteId); // get the recognition configuration for the given payment method and store id. $allowRecognition = $this->scopeConfig->getValue( @@ -149,18 +147,19 @@ public function saveAdditionalPaymentInfo($cartId, $method, $additionalData) { $returnValue = true; - /** @var PaymentInformationInterface|Quote $quote */ // get the quote information by cart id - $quote = $this->quoteRepository->getById($cartId); + $quote = $this->quoteRepository->get($cartId); // if the quote is empty, there is no relation that we can work with... so we return false. if ($quote->isEmpty()) { + $this->logger->warning('Heidelpay: Could not find quote with id ' . $cartId . '.'); $returnValue = false; } // save the information with the given quote and additional data. // if there is nothing stored, we'll return false... if ($returnValue && !$this->savePaymentInformation($quote, $method, $quote->getCustomerEmail(), $additionalData)) { + $this->logger->warning('Heidelpay: Could not save payment information for quote id ' . $cartId . '.'); $returnValue = false; } @@ -180,9 +179,8 @@ public function saveGuestAdditionalPaymentInfo($cartId, $method, $additionalData $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); $quoteId = $quoteIdMask->getQuoteId(); - /** @var PaymentInformationInterface|Quote $quote */ // get the quote information by cart id - $quote = $this->quoteRepository->getById($quoteId); + $quote = $this->quoteRepository->get($quoteId); // if the quote is empty, there is no relation that // we can work with... so we return false. diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index 7274e31b617..0aa0de15532 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -270,11 +270,11 @@ public function execute() if ($paymentType === TransactionType::INITIALIZE && $paymentMethod === PaymentMethod::HIRE_PURCHASE) { if ($this->heidelpayResponse->isSuccess()) { - $redirectUrl = $this->_url->getUrl('hgw/index/', [ + $redirectUrl = $this->_url->getUrl('checkout/', [ '_forced_secure' => true, '_scope_to_url' => true, '_nosid' => true - ]); + ]) . '#payment'; } // return the heidelpay response url as raw response instead of echoing it out. From e5736c347c378e9c6b646e4ceadd862e8f829122 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 23 May 2019 09:34:01 +0200 Subject: [PATCH 052/114] [feature] (MAGE2-175) Santander Hire Purchase: Add new payment method. --- etc/di.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/di.xml b/etc/di.xml index 871f70720f7..8df0a97bbf7 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -143,7 +143,7 @@ Heidelpay\Gateway\PaymentMethods\HeidelpayIDealPaymentMethod::CODE - + Heidelpay\Gateway\PaymentMethods\HeidelpaySantanderHirePurchasePaymentMethod::CODE From 472576326052151e61c51f620428df04ee514ec8 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 24 May 2019 08:52:10 +0200 Subject: [PATCH 053/114] [cleanup] Apply micro optimizations. --- .../HeidelpayAbstractPaymentMethod.php | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index edf8c9c99a1..948e23ef78c 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -6,13 +6,12 @@ use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; use Heidelpay\Gateway\Helper\BasketHelper; -use Heidelpay\Gateway\Helper\Payment as PaymentHelper; use Heidelpay\Gateway\Model\Config\Source\BookingMode; use Heidelpay\Gateway\Model\ResourceModel\Transaction\Collection as TransactionCollection; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; -use Heidelpay\Gateway\Model\TransactionFactory; use Heidelpay\Gateway\Model\Transaction; +use Heidelpay\Gateway\Model\TransactionFactory; use Heidelpay\PhpBasketApi\Exception\InvalidBasketitemPositionException; use Heidelpay\PhpPaymentApi\ParameterGroups\BasketParameterGroup; use Heidelpay\PhpPaymentApi\Response; @@ -30,18 +29,17 @@ use Magento\Framework\Phrase; use Magento\Framework\Registry; use Magento\Framework\UrlInterface; -use Magento\Payment\Helper\Data as DataHelper; use Magento\Payment\Model\InfoInterface; use Magento\Payment\Model\Method\AbstractMethod; use Magento\Payment\Model\Method\Logger; -use Magento\Quote\Api\Data\AddressInterface; use Magento\Quote\Api\Data\CartInterface; use Magento\Quote\Model\Quote; -use Magento\Sales\Api\Data\OrderPaymentInterface; use Magento\Sales\Api\Data\TransactionInterface; use Magento\Sales\Helper\Data; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; +use Magento\Sales\Model\Order\Payment\Interceptor; +use Magento\Store\Model\ScopeInterface as StoreScopeInterface; use Magento\Sales\Model\Order\Payment; use Heidelpay\Gateway\Block\Payment\HgwAbstract; use Heidelpay\PhpPaymentApi\PaymentMethods\PaymentMethodInterface; @@ -86,7 +84,11 @@ class HeidelpayAbstractPaymentMethod extends AbstractMethod /** @var ResolverInterface */ protected $_localResolver; - /** @var PaymentMethodInterface $_heidelpayPaymentMethod The used heidelpay payment method */ + /** + * The used heidelpay payment method + * + * @var PaymentMethodInterface $_heidelpayPaymentMethod + */ protected $_heidelpayPaymentMethod; /** @var Encryptor $_encryptor Encryption & Hashing */ @@ -98,10 +100,18 @@ class HeidelpayAbstractPaymentMethod extends AbstractMethod /** @var Data */ protected $salesHelper; - /** @var ResourceInterface $moduleResource Resource information about modules */ + /** + * Resource information about modules + * + * @var ResourceInterface + */ protected $moduleResource; - /** @var PaymentInformationCollectionFactory $paymentInformationCollectionFactory */ + /** + * Factory for heidelpay payment information + * + * @var PaymentInformationCollectionFactory + */ protected $paymentInformationCollectionFactory; /** @var TransactionFactory */ @@ -574,7 +584,7 @@ public function getUser($order) $billingStreet .= $street . ' '; } - $user['CRITERION.GUEST'] = $order->getCustomer()->getId() === 0; + $user['CRITERION.GUEST'] = $order->getCustomer()->getId() === null; $user['NAME.COMPANY'] = ($billing->getCompany() === false) ? null : trim($billing->getCompany()); $user['NAME.GIVEN'] = trim($billing->getFirstname()); From ba55a90d6226fa95182aff3f43d19abe55d879d1 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 24 May 2019 09:10:00 +0200 Subject: [PATCH 054/114] [refactor] Apply micro optimizations and replaced deprecated constructs. --- PaymentMethods/HeidelpayAbstractPaymentMethod.php | 1 - 1 file changed, 1 deletion(-) diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 948e23ef78c..8d094c144f6 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -38,7 +38,6 @@ use Magento\Sales\Helper\Data; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; -use Magento\Sales\Model\Order\Payment\Interceptor; use Magento\Store\Model\ScopeInterface as StoreScopeInterface; use Magento\Sales\Model\Order\Payment; use Heidelpay\Gateway\Block\Payment\HgwAbstract; From 02d8f251a4072d8006125e7fa17720aee761604e Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 24 May 2019 13:03:47 +0200 Subject: [PATCH 055/114] [refactor] (MAGE2-175) Santander Hire Purchase: Simplify payment methods. --- .../HeidelpayAbstractPaymentMethod.php | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 8d094c144f6..c708b4d8d87 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -6,6 +6,7 @@ use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; use Heidelpay\Gateway\Helper\BasketHelper; +use Heidelpay\Gateway\Helper\Payment as PaymentHelper; use Heidelpay\Gateway\Model\Config\Source\BookingMode; use Heidelpay\Gateway\Model\ResourceModel\Transaction\Collection as TransactionCollection; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; @@ -29,17 +30,22 @@ use Magento\Framework\Phrase; use Magento\Framework\Registry; use Magento\Framework\UrlInterface; +use Magento\Payment\Helper\Data as DataHelper; use Magento\Payment\Model\InfoInterface; use Magento\Payment\Model\Method\AbstractMethod; use Magento\Payment\Model\Method\Logger; +use Magento\Quote\Api\Data\AddressInterface; use Magento\Quote\Api\Data\CartInterface; use Magento\Quote\Model\Quote; +use Magento\Sales\Api\Data\OrderPaymentInterface; use Magento\Sales\Api\Data\TransactionInterface; use Magento\Sales\Helper\Data; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; -use Magento\Store\Model\ScopeInterface as StoreScopeInterface; use Magento\Sales\Model\Order\Payment; +use Magento\Sales\Model\Spi\OrderPaymentResourceInterface; +use Magento\Sales\Model\Spi\TransactionResourceInterface; +use Magento\Store\Model\ScopeInterface as StoreScopeInterface; use Heidelpay\Gateway\Block\Payment\HgwAbstract; use Heidelpay\PhpPaymentApi\PaymentMethods\PaymentMethodInterface; use Magento\Store\Model\ScopeInterface; @@ -109,7 +115,7 @@ class HeidelpayAbstractPaymentMethod extends AbstractMethod /** * Factory for heidelpay payment information * - * @var PaymentInformationCollectionFactory + * @var PaymentInformationCollectionFactory $paymentInformationCollectionFactory */ protected $paymentInformationCollectionFactory; @@ -124,6 +130,14 @@ class HeidelpayAbstractPaymentMethod extends AbstractMethod /** @var HgwBasePaymentConfigInterface */ private $paymentConfig; + /** + * @var OrderPaymentResourceInterface + */ + private $paymentResource; + /** + * @var TransactionResourceInterface + */ + private $transactionResource; /** * @param Context $context @@ -145,6 +159,8 @@ class HeidelpayAbstractPaymentMethod extends AbstractMethod * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory * @param TransactionFactory $transactionFactory * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory + * @param OrderPaymentResourceInterface $paymentResource + * @param TransactionResourceInterface $transactionResource * @param AbstractResource $resource * @param AbstractDb $resourceCollection * @param HgwBasePaymentConfigInterface $paymentConfig @@ -171,6 +187,8 @@ public function __construct( PaymentInformationCollectionFactory $paymentInformationCollectionFactory, TransactionFactory $transactionFactory, HeidelpayTransactionCollectionFactory $transactionCollectionFactory, + OrderPaymentResourceInterface $paymentResource, + TransactionResourceInterface $transactionResource, AbstractResource $resource = null, AbstractDb $resourceCollection = null, HgwBasePaymentConfigInterface $paymentConfig = null, @@ -200,6 +218,8 @@ public function __construct( $this->_localResolver = $localeResolver; $this->productMetadata = $productMetadata; $this->moduleResource = $moduleResource; + $this->paymentResource = $paymentResource; + $this->transactionResource = $transactionResource; $this->paymentInformationCollectionFactory = $paymentInformationCollectionFactory; $this->transactionFactory = $transactionFactory; @@ -345,7 +365,7 @@ public function capture(InfoInterface $payment, $amount) // set the last transaction id to the Pre-Authorization. $payment->setLastTransId($this->_heidelpayPaymentMethod->getResponse()->getPaymentReferenceId()); - $payment->save(); + $this->paymentResource->save($payment); return $this; } @@ -425,7 +445,7 @@ public function refund(InfoInterface $payment, $amount) // set the last transaction id to the Pre-Authorization. $payment->setLastTransId($this->_heidelpayPaymentMethod->getResponse()->getPaymentReferenceId()); - $payment->save(); + $this->paymentResource->save($payment); return $this; } @@ -530,7 +550,8 @@ public function saveHeidelpayTransaction(Response $response, $paymentMethod, $pa ->setJsonResponse(json_encode($data)) ->setSource($source); - $transaction->save(); + $this->transactionResource->save($transaction); + } /** From e10896e0d8546edeb76330a1df76c1391c9f98f8 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 27 May 2019 16:59:27 +0200 Subject: [PATCH 056/114] [cleanup] Apply micro optimizations. --- Controller/Index/Response.php | 184 ++++++++++++++++------------------ 1 file changed, 88 insertions(+), 96 deletions(-) diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index 0aa0de15532..f942b1b4af3 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -4,21 +4,15 @@ use Exception; use Heidelpay\Gateway\Controller\HgwAbstract; -use Heidelpay\Gateway\Helper\Payment; +use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper; use Heidelpay\Gateway\Model\PaymentInformation; -use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory; +use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\TransactionFactory; use Magento\Framework\Controller\Result\RawFactory; use Magento\Sales\Model\OrderFactory; use Heidelpay\PhpPaymentApi\Constants\PaymentMethod; -use Heidelpay\Gateway\Model\Transaction; -use Magento\Framework\Exception\LocalizedException; -use Magento\Framework\Model\AbstractExtensibleModel; -use Magento\Sales\Api\Data\OrderInterface; -use Magento\Customer\Model\Group; use Heidelpay\PhpPaymentApi\Exceptions\HashVerificationException; use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse; -use Heidelpay\PhpPaymentApi\Constants\TransactionType; use Magento\Checkout\Model\Session as CheckoutSession; use Magento\Customer\Model\Session; use Magento\Customer\Model\Url; @@ -28,6 +22,7 @@ use Magento\Framework\View\Result\PageFactory; use Magento\Quote\Api\CartManagementInterface; use Magento\Quote\Api\CartRepositoryInterface; +use Heidelpay\PhpPaymentApi\Constants\TransactionType; use Magento\Quote\Model\Quote; use Magento\Quote\Model\QuoteRepository; use Magento\Sales\Model\Order; @@ -70,6 +65,9 @@ class Response extends HgwAbstract /** @var CollectionFactory */ private $paymentInformationCollectionFactory; + /** @var SalesHelper */ + private $salesHelper; + /** * heidelpay Response constructor. * @@ -82,7 +80,7 @@ class Response extends HgwAbstract * @param CartManagementInterface $cartManagement * @param CartRepositoryInterface $quoteObject * @param PageFactory $resultPageFactory - * @param Payment $paymentHelper + * @param HeidelpayHelper $paymentHelper * @param OrderSender $orderSender * @param InvoiceSender $invoiceSender * @param OrderCommentSender $orderCommentSender @@ -103,7 +101,7 @@ public function __construct( CartManagementInterface $cartManagement, CartRepositoryInterface $quoteObject, PageFactory $resultPageFactory, - Payment $paymentHelper, + HeidelpayHelper $paymentHelper, OrderSender $orderSender, InvoiceSender $invoiceSender, OrderCommentSender $orderCommentSender, @@ -111,8 +109,9 @@ public function __construct( Url $customerUrl, RawFactory $rawResultFactory, QuoteRepository $quoteRepository, - CollectionFactory $paymentInformationCollectionFactory, - TransactionFactory $transactionFactory + PaymentInformationCollectionFactory $paymentInformationCollectionFactory, + TransactionFactory $transactionFactory, + SalesHelper $salesHelper ) { parent::__construct( $context, @@ -135,7 +134,7 @@ public function __construct( $this->resultFactory = $rawResultFactory; $this->quoteRepository = $quoteRepository; $this->paymentInformationCollectionFactory = $paymentInformationCollectionFactory; - $this->transactionFactory = $transactionFactory; + $this->salesHelper = $salesHelper; } /** @@ -144,12 +143,6 @@ public function __construct( */ public function execute() { - // initialize the Raw Response object from the factory. - $result = $this->resultFactory->create(); - - // we just want the response to return a plain url, so we set the header to text/plain. - $result->setHeader('Content-Type', 'text/plain'); - // the url where the payment will redirect the customer to. $redirectUrl = $this->_url->getUrl('hgw/index/redirect', [ '_forced_secure' => true, @@ -157,7 +150,11 @@ public function execute() '_nosid' => true ]); - // the payment just wants a url as result, so we set the content to the redirectUrl. + // initialize the Raw Response object from the factory. + $result = $this->resultFactory->create(); + // we just want the response to return a plain url, so we set the header to text/plain. + $result->setHeader('Content-Type', 'text/plain'); + // the payment just wants an url as result, so we set the content to the redirectUrl. $result->setContents($redirectUrl); // if there is no post request, just redirect to the cart instantly and show an error message to the customer. @@ -188,27 +185,7 @@ public function execute() return $result; } - $secret = $this->_encryptor->exportKeys(); - $identificationTransactionId = $this->heidelpayResponse->getIdentification()->getTransactionId(); - - $this->_logger->debug('Heidelpay secret: ' . $secret); - $this->_logger->debug('Heidelpay identificationTransactionId: ' . $identificationTransactionId); - - // validate Hash to prevent manipulation - try { - $this->heidelpayResponse->verifySecurityHash($secret, $identificationTransactionId); - } catch (HashVerificationException $e) { - $this->_logger->critical('Heidelpay Response - HashVerification Exception: ' . $e->getMessage()); - $this->_logger->critical( - 'Heidelpay Response - Received request form server ' - . $this->getRequest()->getServer('REMOTE_ADDR') - . ' with an invalid hash. This could be some kind of manipulation.' - ); - $this->_logger->critical( - 'Heidelpay Response - Reference secret hash: ' - . $this->heidelpayResponse->getCriterion()->getSecretHash() - ); - + if(!$this->validateSecurityHash($this->heidelpayResponse)) { return $result; } @@ -224,30 +201,7 @@ public function execute() $quote = null; $data = $this->getRequest()->getParams(); - - // save the heidelpay transaction data - $code = $this->heidelpayResponse->getPayment()->getCode(); - list($paymentMethod, $paymentType) = $this->_paymentHelper->splitPaymentCode($code); - - try { - // save the response details into the heidelpay Transactions table. - /** @var Transaction $transaction */ - $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(); - } catch (Exception $e) { - $this->_logger->error('Heidelpay - Response: Save transaction error. ' . $e->getMessage()); - } + $this->_paymentHelper->saveHeidelpayTransaction($this->heidelpayResponse, $data, 'RESPONSE'); // if something went wrong, return the redirect url without processing the order. if ($this->heidelpayResponse->isError()) { @@ -264,7 +218,6 @@ public function execute() $this->_logger->debug($message); // return the heidelpay response url as raw response instead of echoing it out. - $result->setContents($redirectUrl); return $result; } @@ -285,42 +238,73 @@ public function execute() // Create order if transaction is successful if ($this->heidelpayResponse->isSuccess()) { try { + $identificationTransactionId = $this->heidelpayResponse->getIdentification()->getTransactionId(); // get the quote by transactionid from the heidelpay response /** @var Quote $quote */ - $quote = $this->quoteRepository->get($this->heidelpayResponse->getIdentification()->getTransactionId()); - $order = $this->createOrder($quote); + $quote = $this->quoteRepository->get($identificationTransactionId); + $order = $this->_paymentHelper->createOrderFromQuote($quote); } catch (Exception $e) { $this->_logger->error('Heidelpay - Response: Cannot submit the Quote. ' . $e->getMessage()); return $result; } $data['ORDER_ID'] = $order->getIncrementId(); + $this->_paymentHelper->mapStatus($data, $order); + $this->handleOrderMail($order); + $this->handleInvoiceMails($order); $order->save(); - } - // if the customer is a guest, we'll delete the additional payment information, which - // is used for customer recognition and has already been sent to the payment API at this point. - if (isset($quote)) { - $this->removeAdditionalPaymentInformation($quote); - } + $this->handleAdditionalPaymentInformation($quote); + $this->_logger->debug('Heidelpay - Response: redirectUrl is ' . $redirectUrl); // return the heidelpay response url as raw response instead of echoing it out. - $result->setContents($redirectUrl); return $result; } // /** - * Remove the additional customer information from the payment form. - * + * Send order confirmation to the customer + * @param $order + */ + protected function handleOrderMail($order) + { + try { + if ($order && $order->getId()) { + $this->_orderSender->send($order); + } + } catch (\Exception $e) { + $this->_logger->error( + 'Heidelpay - Response: Cannot send order confirmation E-Mail. ' . $e->getMessage() + ); + } + } + + /** + * Send invoice mails to the customer + * @param $order + */ + protected function handleInvoiceMails($order) + { + if (!$order->canInvoice() && $this->salesHelper->canSendNewInvoiceEmail($order->getStore()->getId())) { + $invoices = $order->getInvoiceCollection(); + + foreach ($invoices as $invoice) { + $this->_invoiceSender->send($invoice); + } + } + } + + /** + * If the customer is a guest, we'll delete the additional payment information, which + * is only used for customer recognition. * @param Quote $quote * @throws Exception */ - private function removeAdditionalPaymentInformation(Quote $quote) + protected function handleAdditionalPaymentInformation($quote) { - if ($quote->getCustomerIsGuest()) { + if ($quote !== null && $quote->getCustomerIsGuest()) { // create a new instance for the payment information collection. $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); @@ -339,26 +323,34 @@ private function removeAdditionalPaymentInformation(Quote $quote) } /** - * Create the order object from the given quote. - * - * @param Quote $quote - * @return AbstractExtensibleModel|OrderInterface|object|null - * @throws LocalizedException + * Validate Hash to prevent manipulation + * @param HeidelpayResponse $response + * @return bool */ - private function createOrder(Quote $quote) + protected function validateSecurityHash($response) { - $quote->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode()); - $quote->collectTotals(); - // in case of guest checkout, set some customer related data. - if ($this->getRequest()->getPost('CRITERION_GUEST') === 'true') { - $quote->setCustomerId(null) - ->setCustomerEmail($quote->getBillingAddress()->getEmail()) - ->setCustomerIsGuest(true) - ->setCustomerGroupId(Group::NOT_LOGGED_IN_ID); - } + $secret = $this->_encryptor->exportKeys(); + $identificationTransactionId = $response->getIdentification()->getTransactionId(); + + $this->_logger->debug('Heidelpay secret: ' . $secret); + $this->_logger->debug('Heidelpay identificationTransactionId: ' . $identificationTransactionId); - // create an order by submitting the quote. - return $this->_cartManagement->submit($quote); + try { + $response->verifySecurityHash($secret, $identificationTransactionId); + return true; + } catch (HashVerificationException $e) { + $this->_logger->critical('Heidelpay Response - HashVerification Exception: ' . $e->getMessage()); + $this->_logger->critical( + 'Heidelpay Response - Received request form server ' + . $this->getRequest()->getServer('REMOTE_ADDR') + . ' with an invalid hash. This could be some kind of manipulation.' + ); + $this->_logger->critical( + 'Heidelpay Response - Reference secret hash: ' + . $response->getCriterion()->getSecretHash() + ); + return false; + } } // From ecd85688777fb0bd7eb4bf916509f1ee2ed4e4c0 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 28 May 2019 14:36:56 +0200 Subject: [PATCH 057/114] [refactor] (MAGE2-175) Santander Hire Purchase: Apply micro optimizations. --- Controller/Index/Index.php | 4 ++-- Controller/Index/Response.php | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Controller/Index/Index.php b/Controller/Index/Index.php index e6efb651848..2dcb2308f6f 100755 --- a/Controller/Index/Index.php +++ b/Controller/Index/Index.php @@ -3,15 +3,15 @@ namespace Heidelpay\Gateway\Controller\Index; use Exception; -use Heidelpay\Gateway\Block\Hgw; use Heidelpay\Gateway\Controller\HgwAbstract; +use Heidelpay\Gateway\Block\Hgw; use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper; use Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod; use Heidelpay\PhpBasketApi\Exception\InvalidBasketitemPositionException; -use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse; use Magento\Checkout\Model\Session as CheckoutSession; use Magento\Customer\Model\Session; use Magento\Customer\Model\Url; +use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse; use Magento\Framework\App\Action\Context; use Magento\Framework\Encryption\Encryptor; use Magento\Framework\Escaper; diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index f942b1b4af3..02266e0d672 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -88,8 +88,8 @@ class Response extends HgwAbstract * @param Url $customerUrl * @param RawFactory $rawResultFactory * @param QuoteRepository $quoteRepository - * @param CollectionFactory $paymentInformationCollectionFactory, - * @param TransactionFactory $transactionFactory + * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory , + * @param SalesHelper $salesHelper */ public function __construct( Context $context, @@ -110,7 +110,6 @@ public function __construct( RawFactory $rawResultFactory, QuoteRepository $quoteRepository, PaymentInformationCollectionFactory $paymentInformationCollectionFactory, - TransactionFactory $transactionFactory, SalesHelper $salesHelper ) { parent::__construct( @@ -245,6 +244,7 @@ public function execute() $order = $this->_paymentHelper->createOrderFromQuote($quote); } catch (Exception $e) { $this->_logger->error('Heidelpay - Response: Cannot submit the Quote. ' . $e->getMessage()); + return $result; } @@ -254,6 +254,7 @@ public function execute() $this->handleOrderMail($order); $this->handleInvoiceMails($order); $order->save(); + } $this->handleAdditionalPaymentInformation($quote); $this->_logger->debug('Heidelpay - Response: redirectUrl is ' . $redirectUrl); From a51a43356e323dce37fbac2adc8a315dd014d084 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 29 May 2019 11:10:35 +0200 Subject: [PATCH 058/114] [refactor] (MAGE2-175) Santander Hire Purchase: Avoid creating the order if it was an initialization result. Several code optimizations. --- Controller/Index/Response.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index 02266e0d672..5a0f45518db 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -13,6 +13,7 @@ use Heidelpay\PhpPaymentApi\Constants\PaymentMethod; use Heidelpay\PhpPaymentApi\Exceptions\HashVerificationException; use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse; +use Heidelpay\PhpPaymentApi\Constants\TransactionType; use Magento\Checkout\Model\Session as CheckoutSession; use Magento\Customer\Model\Session; use Magento\Customer\Model\Url; @@ -22,7 +23,6 @@ use Magento\Framework\View\Result\PageFactory; use Magento\Quote\Api\CartManagementInterface; use Magento\Quote\Api\CartRepositoryInterface; -use Heidelpay\PhpPaymentApi\Constants\TransactionType; use Magento\Quote\Model\Quote; use Magento\Quote\Model\QuoteRepository; use Magento\Sales\Model\Order; @@ -220,6 +220,7 @@ public function execute() return $result; } + // Create order if transaction is successful and not just an initialization if ($paymentType === TransactionType::INITIALIZE && $paymentMethod === PaymentMethod::HIRE_PURCHASE) { if ($this->heidelpayResponse->isSuccess()) { $redirectUrl = $this->_url->getUrl('checkout/', [ @@ -244,7 +245,6 @@ public function execute() $order = $this->_paymentHelper->createOrderFromQuote($quote); } catch (Exception $e) { $this->_logger->error('Heidelpay - Response: Cannot submit the Quote. ' . $e->getMessage()); - return $result; } From 53896f680c930a8d9d686f4fee16231905fe0d6b Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 29 May 2019 11:11:53 +0200 Subject: [PATCH 059/114] [refactor] Applied several optimizations. --- Helper/Payment.php | 79 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/Helper/Payment.php b/Helper/Payment.php index 1a26cdc8fa0..b0926bb00e9 100755 --- a/Helper/Payment.php +++ b/Helper/Payment.php @@ -7,13 +7,22 @@ use Heidelpay\PhpPaymentApi\Constants\ProcessingResult; use Heidelpay\PhpPaymentApi\Constants\StatusCode; use Heidelpay\PhpPaymentApi\Constants\TransactionType; +use Heidelpay\PhpPaymentApi\Response; +use Magento\Customer\Model\Group; use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\Context; use Magento\Framework\DB\TransactionFactory; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\HTTP\ZendClientFactory; use Magento\Framework\Locale\Resolver; +use Magento\Framework\Model\AbstractExtensibleModel; +use Magento\Quote\Model\Quote; +use Magento\Quote\Model\QuoteManagement; +use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; +use Heidelpay\Gateway\Model\Transaction; +use Heidelpay\Gateway\Model\TransactionFactory as HgwTransactionFactory; /** * Heidelpay payment helper @@ -45,23 +54,35 @@ class Payment extends AbstractHelper /** @var Resolver */ protected $localeResolver; + /** @var QuoteManagement */ + private $_cartManagement; + + /** @var HgwTransactionFactory */ + private $heidelpayTransactionFactory; + /** * @param Context $context * @param ZendClientFactory $httpClientFactory * @param TransactionFactory $transactionFactory * @param Resolver $localeResolver + * @param QuoteManagement $cartManagement + * @param Transaction $heidelpayTransactionFactory */ public function __construct( Context $context, ZendClientFactory $httpClientFactory, TransactionFactory $transactionFactory, - Resolver $localeResolver + Resolver $localeResolver, + QuoteManagement $cartManagement, + Transaction $heidelpayTransactionFactory ) { $this->httpClientFactory = $httpClientFactory; $this->transactionFactory = $transactionFactory; $this->localeResolver = $localeResolver; parent::__construct($context); + $this->_cartManagement = $cartManagement; + $this->heidelpayTransactionFactory = $heidelpayTransactionFactory; } /** @@ -257,4 +278,60 @@ public function saveTransaction(Invoice $invoice) $transaction = $this->transactionFactory->create(); $transaction->addObject($invoice)->addObject($invoice->getOrder())->save(); } + + /** + * Save the heidelpay transaction data + * @param Response $response + * @param $data + * @param $source + * @return void + */ + public function saveHeidelpayTransaction($response, $data, $source) + { + list($paymentMethod, $paymentType) = $this->splitPaymentCode( + $response->getPayment()->getCode() + ); + + try { + // save the response details into the heidelpay Transactions table. + /** @var Transaction $transaction */ + $transaction = $this->heidelpayTransactionFactory->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(); + } catch (\Exception $e) { + $this->_logger->error('Heidelpay - ' . $source . ': Save transaction error. ' . $e->getMessage()); + } + } + + /** + * Create an order by submitting the quote. + * @param Quote $quote + * @return AbstractExtensibleModel|OrderInterface|null|object + * @throws LocalizedException + */ + public function createOrderFromQuote($quote) + { + // Ensure to use the currency of the quote. + $quote->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode()); + $quote->collectTotals(); + // in case of guest checkout, set some customer related data. + if ($quote->getCustomerId() === null) { + $quote->setCustomerId(null) + ->setCustomerEmail($quote->getBillingAddress()->getEmail()) + ->setCustomerIsGuest(true) + ->setCustomerGroupId(Group::NOT_LOGGED_IN_ID); + } + + return $this->_cartManagement->submit($quote); + } } From 24d22c10848058542670dfabfe261e0e8d5b9cbf Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 31 May 2019 12:42:04 +0200 Subject: [PATCH 060/114] [refactor] Apply micro optimization. --- Controller/Index/Index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Controller/Index/Index.php b/Controller/Index/Index.php index 2dcb2308f6f..2d6b1e98fc6 100755 --- a/Controller/Index/Index.php +++ b/Controller/Index/Index.php @@ -8,6 +8,7 @@ use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper; use Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod; use Heidelpay\PhpBasketApi\Exception\InvalidBasketitemPositionException; +use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse; use Magento\Checkout\Model\Session as CheckoutSession; use Magento\Customer\Model\Session; use Magento\Customer\Model\Url; From 096f6ca8f70ca7d620fc3b5a6e20fd976114ed1a Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 19 Jun 2019 18:05:59 +0200 Subject: [PATCH 061/114] [cleanup] (MAGE2-175) Apply optimizations after rebase. --- Controller/Index/Response.php | 19 +++++++++---------- Helper/Payment.php | 30 ++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index 5a0f45518db..47e5f9de3f0 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -6,10 +6,10 @@ use Heidelpay\Gateway\Controller\HgwAbstract; use Heidelpay\Gateway\Helper\Payment as HeidelpayHelper; use Heidelpay\Gateway\Model\PaymentInformation; +use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\TransactionFactory; use Magento\Framework\Controller\Result\RawFactory; -use Magento\Sales\Model\OrderFactory; use Heidelpay\PhpPaymentApi\Constants\PaymentMethod; use Heidelpay\PhpPaymentApi\Exceptions\HashVerificationException; use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse; @@ -25,6 +25,8 @@ use Magento\Quote\Api\CartRepositoryInterface; use Magento\Quote\Model\Quote; use Magento\Quote\Model\QuoteRepository; +use Magento\Sales\Helper\Data as SalesHelper; +use Magento\Sales\Model\OrderFactory; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Email\Sender\InvoiceSender; use Magento\Sales\Model\Order\Email\Sender\OrderCommentSender; @@ -59,9 +61,6 @@ class Response extends HgwAbstract /** @var HeidelpayResponse The heidelpay response object */ private $heidelpayResponse; - /** @var TransactionFactory */ - private $transactionFactory; - /** @var CollectionFactory */ private $paymentInformationCollectionFactory; @@ -188,10 +187,7 @@ public function execute() return $result; } - $this->_logger->debug( - 'Heidelpay - Response: Response object: ' - . print_r($this->heidelpayResponse, true) - ); + $this->_logger->debug('Heidelpay - Response: Response object: ' . print_r($this->heidelpayResponse, true)); /** @var Order $order */ $order = null; @@ -221,6 +217,7 @@ public function execute() } // Create order if transaction is successful and not just an initialization + list($paymentMethod, $paymentType) = $this->_paymentHelper->getPaymentMethodAndType($this->heidelpayResponse); if ($paymentType === TransactionType::INITIALIZE && $paymentMethod === PaymentMethod::HIRE_PURCHASE) { if ($this->heidelpayResponse->isSuccess()) { $redirectUrl = $this->_url->getUrl('checkout/', [ @@ -242,6 +239,8 @@ public function execute() // get the quote by transactionid from the heidelpay response /** @var Quote $quote */ $quote = $this->quoteRepository->get($identificationTransactionId); + + /** @var Order $order */ $order = $this->_paymentHelper->createOrderFromQuote($quote); } catch (Exception $e) { $this->_logger->error('Heidelpay - Response: Cannot submit the Quote. ' . $e->getMessage()); @@ -284,9 +283,9 @@ protected function handleOrderMail($order) /** * Send invoice mails to the customer - * @param $order + * @param Order $order */ - protected function handleInvoiceMails($order) + protected function handleInvoiceMails(Order $order) { if (!$order->canInvoice() && $this->salesHelper->canSendNewInvoiceEmail($order->getStore()->getId())) { $invoices = $order->getInvoiceCollection(); diff --git a/Helper/Payment.php b/Helper/Payment.php index b0926bb00e9..b7a9f89dc6e 100755 --- a/Helper/Payment.php +++ b/Helper/Payment.php @@ -1,6 +1,7 @@ splitPaymentCode( - $response->getPayment()->getCode() - ); + list($paymentMethod, $paymentType) = $this->getPaymentMethodAndType($response); try { // save the response details into the heidelpay Transactions table. @@ -308,7 +311,7 @@ public function saveHeidelpayTransaction($response, $data, $source) ->setJsonResponse(json_encode($data)) ->setSource($source) ->save(); - } catch (\Exception $e) { + } catch (Exception $e) { $this->_logger->error('Heidelpay - ' . $source . ': Save transaction error. ' . $e->getMessage()); } } @@ -334,4 +337,15 @@ public function createOrderFromQuote($quote) return $this->_cartManagement->submit($quote); } + + /** + * Returns an array containing the payment method and payment type of the given Response object. + * + * @param $response + * @return array + */ + public function getPaymentMethodAndType(Response $response) + { + return $this->splitPaymentCode($response->getPayment()->getCode()); + } } From 78b51da79a3ee28518cc799573980b56ee39d71a Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 20 Jun 2019 11:40:02 +0200 Subject: [PATCH 062/114] [cleanup] (MAGE2-175) Apply optimizations after rebase. --- Api/Payment.php | 2 +- .../web/js/view/payment/method-renderer/hgw-abstract.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Api/Payment.php b/Api/Payment.php index 2e6a74b858f..54ea49e205f 100755 --- a/Api/Payment.php +++ b/Api/Payment.php @@ -280,7 +280,7 @@ private function savePaymentInformation($quote, $method, $email, $additionalData { // make some additional data changes, if necessary array_walk($additionalData, static function (&$value, $key) { - // if somehow the country code in the IBAN is lowercase, convert it to uppercase. + // make sure the country code in the IBAN is uppercase. if ($key === 'hgw_iban') { $value = strtoupper($value); } diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js b/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js index 6f785088860..f7a197f435e 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js @@ -33,7 +33,7 @@ define( }, /** - * Indicates if the payment method is storing addtional + * Indicates if the payment method is storing additional * information for the payment. * * @returns {boolean} From 4c07ebfb5303a0718a643df73c85e31f95d5a74d Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 20 Jun 2019 12:06:23 +0200 Subject: [PATCH 063/114] [cleanup] (MAGE2-175) Remove duplicated use statement. --- Controller/Index/Index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Controller/Index/Index.php b/Controller/Index/Index.php index 2d6b1e98fc6..6baa4ff51bc 100755 --- a/Controller/Index/Index.php +++ b/Controller/Index/Index.php @@ -12,7 +12,6 @@ use Magento\Checkout\Model\Session as CheckoutSession; use Magento\Customer\Model\Session; use Magento\Customer\Model\Url; -use Heidelpay\PhpPaymentApi\Response as HeidelpayResponse; use Magento\Framework\App\Action\Context; use Magento\Framework\Encryption\Encryptor; use Magento\Framework\Escaper; From 33e61746e5d8c443ad8e0e9a8abea098ac2297b8 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 20 Jun 2019 13:26:42 +0200 Subject: [PATCH 064/114] [cleanup] (MAGE2-175) Fix problems after rebase. --- .../HeidelpayAbstractPaymentMethod.php | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index c708b4d8d87..79ea79f8c8c 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -43,9 +43,6 @@ use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; use Magento\Sales\Model\Order\Payment; -use Magento\Sales\Model\Spi\OrderPaymentResourceInterface; -use Magento\Sales\Model\Spi\TransactionResourceInterface; -use Magento\Store\Model\ScopeInterface as StoreScopeInterface; use Heidelpay\Gateway\Block\Payment\HgwAbstract; use Heidelpay\PhpPaymentApi\PaymentMethods\PaymentMethodInterface; use Magento\Store\Model\ScopeInterface; @@ -130,14 +127,6 @@ class HeidelpayAbstractPaymentMethod extends AbstractMethod /** @var HgwBasePaymentConfigInterface */ private $paymentConfig; - /** - * @var OrderPaymentResourceInterface - */ - private $paymentResource; - /** - * @var TransactionResourceInterface - */ - private $transactionResource; /** * @param Context $context @@ -159,8 +148,6 @@ class HeidelpayAbstractPaymentMethod extends AbstractMethod * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory * @param TransactionFactory $transactionFactory * @param HeidelpayTransactionCollectionFactory $transactionCollectionFactory - * @param OrderPaymentResourceInterface $paymentResource - * @param TransactionResourceInterface $transactionResource * @param AbstractResource $resource * @param AbstractDb $resourceCollection * @param HgwBasePaymentConfigInterface $paymentConfig @@ -187,8 +174,6 @@ public function __construct( PaymentInformationCollectionFactory $paymentInformationCollectionFactory, TransactionFactory $transactionFactory, HeidelpayTransactionCollectionFactory $transactionCollectionFactory, - OrderPaymentResourceInterface $paymentResource, - TransactionResourceInterface $transactionResource, AbstractResource $resource = null, AbstractDb $resourceCollection = null, HgwBasePaymentConfigInterface $paymentConfig = null, @@ -218,8 +203,6 @@ public function __construct( $this->_localResolver = $localeResolver; $this->productMetadata = $productMetadata; $this->moduleResource = $moduleResource; - $this->paymentResource = $paymentResource; - $this->transactionResource = $transactionResource; $this->paymentInformationCollectionFactory = $paymentInformationCollectionFactory; $this->transactionFactory = $transactionFactory; @@ -365,7 +348,7 @@ public function capture(InfoInterface $payment, $amount) // set the last transaction id to the Pre-Authorization. $payment->setLastTransId($this->_heidelpayPaymentMethod->getResponse()->getPaymentReferenceId()); - $this->paymentResource->save($payment); + $payment->save(); return $this; } @@ -445,7 +428,7 @@ public function refund(InfoInterface $payment, $amount) // set the last transaction id to the Pre-Authorization. $payment->setLastTransId($this->_heidelpayPaymentMethod->getResponse()->getPaymentReferenceId()); - $this->paymentResource->save($payment); + $payment->save(); return $this; } From ebc297b086cbfe10610d12c9a50764db78702de3 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 20 Jun 2019 13:35:51 +0200 Subject: [PATCH 065/114] [cleanup] (MAGE2-175) Fix problems after rebase #2. --- etc/di.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/di.xml b/etc/di.xml index 8df0a97bbf7..871f70720f7 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -143,7 +143,7 @@ Heidelpay\Gateway\PaymentMethods\HeidelpayIDealPaymentMethod::CODE - + Heidelpay\Gateway\PaymentMethods\HeidelpaySantanderHirePurchasePaymentMethod::CODE From 0b3e868fb16e86d4f5f2a35e1991d4724460eb50 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 20 Jun 2019 14:28:03 +0200 Subject: [PATCH 066/114] [feature] (MAGE2-175) Add means to fetch installment plan if one has been selected. --- Api/Payment.php | 13 + Api/PaymentInterface.php | 9 + etc/webapi.xml | 6 + .../layout/installment_plan_index_index.xml | 11 - .../frontend/templates/installment-plan.phtml | 26 -- .../hgw-santander-hire-purchase.js | 63 ++++- ...tander-hire-purchase-installment-plan.html | 61 ----- .../heidelpay-santander-hire-purchase.html | 247 +++++++++--------- 8 files changed, 205 insertions(+), 231 deletions(-) delete mode 100644 view/frontend/layout/installment_plan_index_index.xml delete mode 100644 view/frontend/templates/installment-plan.phtml delete mode 100644 view/frontend/web/template/payment/heidelpay-santander-hire-purchase-installment-plan.html diff --git a/Api/Payment.php b/Api/Payment.php index 54ea49e205f..ec94a627056 100755 --- a/Api/Payment.php +++ b/Api/Payment.php @@ -311,4 +311,17 @@ private function savePaymentInformation($quote, $method, $email, $additionalData ->setHeidelpayPaymentReference($paymentRef) ->save(); } + + /** + * Fetches and returns the selected installment plan if there is one. + * + * @param string $quoteId + * @param string $paymentMethod The payment method code + * @return string + */ + public function getInstallmentPlan($quoteId, $paymentMethod) + { + $this->logger->error(__METHOD__ . ' ' . $quoteId . ' '. $paymentMethod); + return json_encode(['test' => 'test']); + } } diff --git a/Api/PaymentInterface.php b/Api/PaymentInterface.php index 7e2686e29bc..b48cad542bb 100755 --- a/Api/PaymentInterface.php +++ b/Api/PaymentInterface.php @@ -54,4 +54,13 @@ public function saveAdditionalPaymentInfo($cartId, $method, $additionalData); * @return string */ public function saveGuestAdditionalPaymentInfo($cartId, $method, $additionalData); + + /** + * Fetches and returns the selected installment plan if there is one. + * + * @param string $quoteId + * @param string $paymentMethod The payment method code + * @return string + */ + public function getInstallmentPlan($quoteId, $paymentMethod); } diff --git a/etc/webapi.xml b/etc/webapi.xml index 8d40dc3592c..03ab7c3242d 100644 --- a/etc/webapi.xml +++ b/etc/webapi.xml @@ -18,4 +18,10 @@ + + + + + + \ No newline at end of file diff --git a/view/frontend/layout/installment_plan_index_index.xml b/view/frontend/layout/installment_plan_index_index.xml deleted file mode 100644 index 09d0a04580c..00000000000 --- a/view/frontend/layout/installment_plan_index_index.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/view/frontend/templates/installment-plan.phtml b/view/frontend/templates/installment-plan.phtml deleted file mode 100644 index 477d5fc8a9e..00000000000 --- a/view/frontend/templates/installment-plan.phtml +++ /dev/null @@ -1,26 +0,0 @@ - - -
- - -

- -
diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js b/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js index c3a7caf95e0..d605b1900e7 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js @@ -33,16 +33,14 @@ define( initialize: function () { this._super(); + this.getInstallmentPlan(); this.getAdditionalPaymentInformation(); - if (this.hgwInstallmentPlanUrl !== '') { - this.template = 'Heidelpay_Gateway/payment/heidelpay-santander-hire-purchase-installment-plan'; - } else { - // init years select menu - for (let i = (new Date().getFullYear() - 17); i >= new Date().getFullYear() - 120; i--) { - this.years.push(i); - } + // init years select menu + for (let i = (new Date().getFullYear() - 17); i >= new Date().getFullYear() - 120; i--) { + this.years.push(i); } + return this; }, @@ -71,10 +69,22 @@ define( function(data) { var info = JSON.parse(data); - // set link to installment plan + // set salutation and birthdate, if set. if( info !== null ) { - if (info.hasOwnProperty('hgw_installment_plan_url')) { - parent.hgwInstallmentPlanUrl = info.hgw_installment_plan_url; + if (info.hasOwnProperty('hgw_salutation')) + parent.hgwSalutation(info.hgw_salutation); + + if (info.hasOwnProperty('hgw_birthdate') && info.hgw_birthdate !== null) { + var date = moment(info.hgw_birthdate, 'YYYY-MM-DD'); + + parent.hgwDobDay(date.date()); + parent.hgwDobMonth(date.month()); + parent.hgwDobYear(date.year()); + + // workaround: if month is 'january', the month isn't selected. + if (date.month() === 0) { + $("#hgwivs_birthdate_month option:eq(1)").prop('selected', true); + } } } } @@ -120,11 +130,40 @@ define( }, /** - * Returns the installmentPlanUrl + * Fetches the installment plan url if it exists * @returns {string} */ getInstallmentPlan: function () { - return this.hgwInstallmentPlanUrl + var parent = this; + var serviceUrl = urlBuilder.createUrl('/hgw/get-installment-plan', {}); + var hgwPayload = { + quoteId: quote.getQuoteId(), + paymentMethod: this.item.method + }; + + // todo: start spinner here + storage.post(serviceUrl, JSON.stringify(hgwPayload)).done( + function(rawData) { + var data = JSON.parse(rawData); + + // set link to installment plan + if( data !== null ) { + if (data.hasOwnProperty('hgw_installment_plan_url')) { + console.log('installment_plan_url: ' + data.hgw_installment_plan_url); + parent.hgwInstallmentPlanUrl = data.hgw_installment_plan_url; + } + } + } + ).fail( + function(rawData) { + console.log('something went horribly wrong: ' + rawData); + } + ).always( + function(rawData) { + // todo stop spinner here + console.log('Whatever'); + } + ); } }); } diff --git a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase-installment-plan.html b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase-installment-plan.html deleted file mode 100644 index 6e3dfeeaea1..00000000000 --- a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase-installment-plan.html +++ /dev/null @@ -1,61 +0,0 @@ - -
-
- - -
- -
- - - -
- -
-
- -
- -
-
-
-
-
- - - -
-
-
- -
-
-
-
diff --git a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html index 68b14008a13..b5b8ee126e4 100644 --- a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html +++ b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html @@ -30,132 +30,137 @@
-
- -
-
- -
-
-
- -
- -
- -
- + + + +
+
+ +
+
+
+ +
+ +
+ +
+ +
-
-
+
+
-
- -
- -
-
-
-
- - -
-
- - + +
+ +
+
+
+
+ + +
+
+ + +
+
+ + +
-
- - -
-
-
+ - + +
-
- - + + + +
From 2e8c0206433be15a2ada65ac791ffbd2d282c7aa Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 21 Jun 2019 14:22:59 +0200 Subject: [PATCH 067/114] [feature] (MAGE2-175) SAN HP: Enable fetching the last installment plan for the current quote via web api. * Extend WebAPI * Refactor Transaction model --- Api/Data/TransactionInterface.php | 141 ++++++++++++++ Api/Data/TransactionSearchResultInterface.php | 29 +++ Api/Payment.php | 98 +++++++++- Api/TransactionRepositoryInterface.php | 72 +++++++ Model/Transaction.php | 80 ++++---- Model/TransactionRepository.php | 182 ++++++++++++------ Model/TransactionRepositoryInterface.php | 28 --- Model/TransactionSearchResult.php | 22 +++ etc/di.xml | 4 + etc/webapi.xml | 4 +- 10 files changed, 526 insertions(+), 134 deletions(-) create mode 100644 Api/Data/TransactionInterface.php create mode 100644 Api/Data/TransactionSearchResultInterface.php create mode 100644 Api/TransactionRepositoryInterface.php mode change 100755 => 100644 Model/TransactionRepository.php delete mode 100644 Model/TransactionRepositoryInterface.php create mode 100644 Model/TransactionSearchResult.php diff --git a/Api/Data/TransactionInterface.php b/Api/Data/TransactionInterface.php new file mode 100644 index 00000000000..3b1642008b5 --- /dev/null +++ b/Api/Data/TransactionInterface.php @@ -0,0 +1,141 @@ + + * + * @package heidelpay/magento2 + */ +namespace Heidelpay\Gateway\Api\Data; + +interface TransactionInterface +{ + /** + * @return string + */ + public function getPaymentMethod(); + + /** + * @param string $paymentMethod + * @return $this + */ + public function setPaymentMethod($paymentMethod); + + /** + * @return string + */ + public function getPaymentType(); + + /** + * @param string $paymentType + * @return $this + */ + public function setPaymentType($paymentType); + + /** + * @return string + */ + public function getTransactionId(); + + /** + * @param string $transactionId + * @return $this + */ + public function setTransactionId($transactionId); + + /** + * @return string + */ + public function getUniqueId(); + + /** + * @param string $uniqueId + * @return $this + */ + public function setUniqueId($uniqueId); + + /** + * @return string + */ + public function getShortId(); + + /** + * @param string $shortId + * @return $this + */ + public function setShortId($shortId); + + /** + * @return string + */ + public function getResult(); + + /** + * @param string $result + * @return $this + */ + public function setResult($result); + + /** + * @return integer + */ + public function getStatusCode(); + + /** + * @param integer $statusCode + * @return $this + */ + public function setStatusCode($statusCode); + + /** + * @return string + */ + public function getReturnMessage(); + + /** + * @param string $returnMessage + * @return $this + */ + public function setReturnMessage($returnMessage); + + /** + * @return string + */ + public function getReturnCode(); + + /** + * @param string $returnCode + * @return $this + */ + public function setReturnCode($returnCode); + + /** + * @return array + */ + public function getJsonResponse(); + + /** + * @param string $jsonResponse + * @return $this + */ + public function setJsonResponse($jsonResponse); + + /** + * @return string + */ + public function getDatetime(); + + /** + * @return string + */ + public function getSource(); + + /** + * @param string $source + * @return $this + */ + public function setSource($source); +} diff --git a/Api/Data/TransactionSearchResultInterface.php b/Api/Data/TransactionSearchResultInterface.php new file mode 100644 index 00000000000..d157f109ca7 --- /dev/null +++ b/Api/Data/TransactionSearchResultInterface.php @@ -0,0 +1,29 @@ + + * + * @package heidelpay/magento2 + */ +namespace Heidelpay\Gateway\Api\Data; + +use Magento\Framework\Api\SearchResultsInterface; + +interface TransactionSearchResultInterface extends SearchResultsInterface +{ + /** + * @return \Heidelpay\Gateway\Api\Data\TransactionInterface[] + */ + public function getItems(); + + /** + * @param \Heidelpay\Gateway\Api\Data\TransactionInterface[] $items + * @return void + */ + public function setItems(array $items); +} diff --git a/Api/Payment.php b/Api/Payment.php index ec94a627056..57974300d80 100755 --- a/Api/Payment.php +++ b/Api/Payment.php @@ -9,17 +9,28 @@ * * @author Stephano Vogel * - * @package heidelpay - * @subpackage magento2 - * @category magento2 + * @package heidelpay/magento2 */ namespace Heidelpay\Gateway\Api; +use Exception; use Heidelpay\Gateway\Api\Data\PaymentInformationInterface; +use Heidelpay\Gateway\Api\Data\TransactionInterface; use Heidelpay\Gateway\Model\Config\Source\Recognition; use Heidelpay\Gateway\Model\PaymentInformation; use Heidelpay\Gateway\Model\PaymentInformationFactory; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; +use Heidelpay\Gateway\Model\Transaction; +use Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod; +use Heidelpay\PhpPaymentApi\Constants\PaymentMethod; +use Heidelpay\PhpPaymentApi\Constants\ProcessingResult; +use Heidelpay\PhpPaymentApi\Constants\TransactionType; +use Heidelpay\PhpPaymentApi\Response; +use Klarna\Kp\Api\QuoteRepositoryInterface; +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\Api\SortOrder; +use Magento\Framework\Api\SortOrderBuilder; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; use Magento\Quote\Model\QuoteRepository; @@ -27,6 +38,7 @@ use Magento\Framework\Encryption\EncryptorInterface; use Magento\Quote\Api\Data\AddressInterface; use Magento\Quote\Model\Quote; +use Magento\Sales\Api\Data\TransactionSearchResultInterface; use Magento\Store\Model\ScopeInterface; use Psr\Log\LoggerInterface; @@ -53,6 +65,15 @@ class Payment implements PaymentInterface /** @var PaymentInformationCollectionFactory */ public $paymentInformationCollectionFactory; + /** @var SearchCriteriaBuilder */ + private $searchCriteriaBuilder; + + /** @var TransactionRepositoryInterface */ + private $transactionRepository; + + /** @var SortOrderBuilder*/ + private $sortOrderBuilder; + /** * Payment Information API constructor. * @@ -63,6 +84,9 @@ class Payment implements PaymentInterface * @param PaymentInformationCollectionFactory $paymentInformationCollectionFactory * @param LoggerInterface $logger * @param ScopeConfigInterface $scopeConfig + * @param SearchCriteriaBuilder $searchCriteriaBuilder + * @param TransactionRepositoryInterface $transactionRepository + * @param SortOrderBuilder $sortOrderBuilder */ public function __construct( QuoteRepository $quoteRepository, @@ -71,7 +95,10 @@ public function __construct( EncryptorInterface $encryptor, PaymentInformationCollectionFactory $paymentInformationCollectionFactory, LoggerInterface $logger, - ScopeConfigInterface $scopeConfig + ScopeConfigInterface $scopeConfig, + SearchCriteriaBuilder $searchCriteriaBuilder, + TransactionRepositoryInterface $transactionRepository, + SortOrderBuilder $sortOrderBuilder ) { $this->quoteRepository = $quoteRepository; $this->quoteIdMaskFactory = $quoteIdMaskFactory; @@ -82,6 +109,9 @@ public function __construct( $this->encryptor = $encryptor; $this->logger = $logger; $this->scopeConfig = $scopeConfig; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->transactionRepository = $transactionRepository; + $this->sortOrderBuilder = $sortOrderBuilder; } /** @@ -169,6 +199,8 @@ public function saveAdditionalPaymentInfo($cartId, $method, $additionalData) /** * @inheritdoc + * + * @throws Exception */ public function saveGuestAdditionalPaymentInfo($cartId, $method, $additionalData) { @@ -251,10 +283,6 @@ private function getAdditionalDataForPaymentMethod($method, $quote) $result['hgw_birthdate'] = $quote->getCustomer()->getDob(); break; - case 'hgwsanhp': - $result['hgw_installment_plan_url'] = 'http://www.google.com'; - break; - default: $result = null; break; @@ -274,7 +302,10 @@ private function getAdditionalDataForPaymentMethod($method, $quote) * @param string $email * @param array $additionalData * @param string $paymentRef + * * @return PaymentInformationInterface + * + * @throws Exception */ private function savePaymentInformation($quote, $method, $email, $additionalData, $paymentRef = null) { @@ -317,11 +348,58 @@ private function savePaymentInformation($quote, $method, $email, $additionalData * * @param string $quoteId * @param string $paymentMethod The payment method code + * * @return string + * + * @throws NoSuchEntityException */ public function getInstallmentPlan($quoteId, $paymentMethod) { - $this->logger->error(__METHOD__ . ' ' . $quoteId . ' '. $paymentMethod); - return json_encode(['test' => 'test']); + $response = []; + + // do nothing if the payment method does not belong to heidelpay + $quote = $this->quoteRepository->get($quoteId); + $methodInstance = $quote->getPayment()->getMethodInstance(); + if (!$methodInstance instanceof HeidelpayAbstractPaymentMethod) { + return json_encode([]); + } + + // fetch the latest installment plan for the selected HP-method + $paymentMethodInstance = $methodInstance->getHeidelpayPaymentMethodInstance(); + if ($paymentMethodInstance->getPaymentCode() === PaymentMethod::HIRE_PURCHASE) { + /** @var TransactionSearchResultInterface $results */ + $results = $this->getAllHpInsForThisQuote($quoteId); + foreach ($results->getItems() as $item) { + /** @var TransactionInterface $item */ + $heidelpayResponse = new Response($item->getJsonResponse()); + if ($heidelpayResponse->getAccount()->getBrand() === $paymentMethodInstance->getBrand()) { + $contractUrlField = $paymentMethodInstance->getBrand() . '_PDF_URL'; + $response['hgw_installment_plan_url'] = $heidelpayResponse->getCriterion()->get($contractUrlField); + break; + } + } + } + return json_encode($response); + } + + /** + * @param $quoteId + * @param string $direction + * @return TransactionSearchResultInterface + */ + private function getAllHpInsForThisQuote($quoteId, $direction = SortOrder::SORT_DESC) + { + $sortOrder = $this->sortOrderBuilder->setField(Transaction::ID)->setDirection($direction)->create(); + $criteria = $this->searchCriteriaBuilder + ->addFilter(Transaction::QUOTE_ID, $quoteId) + ->addFilter(Transaction::PAYMENT_TYPE, TransactionType::INITIALIZE) + ->addFilter(Transaction::PAYMENT_METHOD, PaymentMethod::HIRE_PURCHASE) + ->addFilter(Transaction::RESULT, ProcessingResult::ACK) + ->addSortOrder($sortOrder) + ->create(); + + /** @var TransactionSearchResultInterface $results */ + $results = $this->transactionRepository->getList($criteria); + return $results; } } diff --git a/Api/TransactionRepositoryInterface.php b/Api/TransactionRepositoryInterface.php new file mode 100644 index 00000000000..84a33cbc5c2 --- /dev/null +++ b/Api/TransactionRepositoryInterface.php @@ -0,0 +1,72 @@ + + * + * @package heidelpay/magento2 + */ +namespace Heidelpay\Gateway\Api; + +use Heidelpay\Gateway\Model\Transaction; +use Magento\Framework\Exception\CouldNotDeleteException; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Api\SearchCriteriaInterface; + +interface TransactionRepositoryInterface +{ + /** + * Retrieves the transaction with the given id. + * + * @param int $id + * + * @return \Heidelpay\Gateway\Api\Data\TransactionInterface + * + * @throws NoSuchEntityException + */ + public function getById($id); + + /** + * Saves the given transaction. + * + * @param Transaction $transaction + * + * @return \Heidelpay\Gateway\Api\Data\TransactionInterface + * + * @throws \Magento\Framework\Exception\AlreadyExistsException + */ + public function save(Transaction $transaction); + + /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ + /** + * Lists transactions that match specified search criteria. + * + * This call returns an array of objects, but detailed information about each object’s attributes might not be + * included. + * + * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria The search criteria. + * + * @return \Heidelpay\Gateway\Api\Data\TransactionSearchResultInterface + */ + public function getList(SearchCriteriaInterface $searchCriteria); + + /** + * Deletes the given transaction. + * + * @param Transaction $transaction + * + * @return \Heidelpay\Gateway\Api\Data\TransactionSearchResultInterface + * + * @throws CouldNotDeleteException + */ + public function delete(Transaction $transaction); + + + +} \ No newline at end of file diff --git a/Model/Transaction.php b/Model/Transaction.php index b5f99db0544..8e9991cff21 100755 --- a/Model/Transaction.php +++ b/Model/Transaction.php @@ -2,6 +2,9 @@ namespace Heidelpay\Gateway\Model; +use Heidelpay\Gateway\Api\Data\TransactionInterface; +use Magento\Framework\Model\AbstractModel; + /** * Transaction resource model * @@ -16,22 +19,27 @@ * @subpackage magento2 * @category magento2 */ -class Transaction extends \Magento\Framework\Model\AbstractModel +class Transaction extends AbstractModel implements TransactionInterface { - public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Payment\Helper\Data $paymentData, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] - ) { - parent::__construct($context, $registry, $resource, $resourceCollection, $data); - } - + const ID = 'id'; + const PAYMENT_METHOD = 'payment_methode'; + const PAYMENT_TYPE = 'payment_type'; + const TRANSACTION_ID = 'transactionid'; + const QUOTE_ID = self::TRANSACTION_ID; + const UNIQUE_ID = 'uniqeid'; + const SHORT_ID = 'shortid'; + const RESULT = 'result'; + const STATUS_CODE = 'statuscode'; + const RETURN_MSG = 'return'; + const RETURN_CODE = 'returncode'; + const JSON_RESPONSE = 'jsonresponse'; + const DATE_TIME = 'datatime'; + const SOURCE = 'source'; + + /** @noinspection MagicMethodsValidityInspection */ public function _construct() { - $this->_init('Heidelpay\Gateway\Model\ResourceModel\Transaction'); + $this->_init(ResourceModel\Transaction::class); } /** @@ -39,7 +47,7 @@ public function _construct() */ public function getPaymentMethod() { - return $this->getData('payment_methode'); + return $this->getData(self::PAYMENT_METHOD); } /** @@ -48,7 +56,7 @@ public function getPaymentMethod() */ public function setPaymentMethod($paymentMethod) { - $this->setData('payment_methode', $paymentMethod); + $this->setData(self::PAYMENT_METHOD, $paymentMethod); return $this; } @@ -57,7 +65,7 @@ public function setPaymentMethod($paymentMethod) */ public function getPaymentType() { - return $this->getData('payment_type'); + return $this->getData(self::PAYMENT_TYPE); } /** @@ -66,7 +74,7 @@ public function getPaymentType() */ public function setPaymentType($paymentType) { - $this->setData('payment_type', $paymentType); + $this->setData(self::PAYMENT_TYPE, $paymentType); return $this; } @@ -75,7 +83,7 @@ public function setPaymentType($paymentType) */ public function getTransactionId() { - return $this->getData('transactionid'); + return $this->getData(self::TRANSACTION_ID); } /** @@ -84,7 +92,7 @@ public function getTransactionId() */ public function setTransactionId($transactionId) { - $this->setData('transactionid', $transactionId); + $this->setData(self::TRANSACTION_ID, $transactionId); return $this; } @@ -93,7 +101,7 @@ public function setTransactionId($transactionId) */ public function getUniqueId() { - return $this->getData('uniqeid'); + return $this->getData(self::UNIQUE_ID); } /** @@ -102,7 +110,7 @@ public function getUniqueId() */ public function setUniqueId($uniqueId) { - $this->setData('uniqeid', $uniqueId); + $this->setData(self::UNIQUE_ID, $uniqueId); return $this; } @@ -111,7 +119,7 @@ public function setUniqueId($uniqueId) */ public function getShortId() { - return $this->getData('shortid'); + return $this->getData(self::SHORT_ID); } /** @@ -120,7 +128,7 @@ public function getShortId() */ public function setShortId($shortId) { - $this->setData('shortid', $shortId); + $this->setData(self::SHORT_ID, $shortId); return $this; } @@ -129,7 +137,7 @@ public function setShortId($shortId) */ public function getResult() { - return $this->getData('result'); + return $this->getData(self::RESULT); } /** @@ -138,7 +146,7 @@ public function getResult() */ public function setResult($result) { - $this->setData('result', $result); + $this->setData(self::RESULT, $result); return $this; } @@ -147,7 +155,7 @@ public function setResult($result) */ public function getStatusCode() { - return $this->getData('statuscode'); + return $this->getData(self::STATUS_CODE); } /** @@ -156,7 +164,7 @@ public function getStatusCode() */ public function setStatusCode($statusCode) { - $this->setData('statuscode', $statusCode); + $this->setData(self::STATUS_CODE, $statusCode); return $this; } @@ -165,7 +173,7 @@ public function setStatusCode($statusCode) */ public function getReturnMessage() { - return $this->getData('return'); + return $this->getData(self::RETURN_MSG); } /** @@ -174,7 +182,7 @@ public function getReturnMessage() */ public function setReturnMessage($returnMessage) { - $this->setData('return', $returnMessage); + $this->setData(self::RETURN_MSG, $returnMessage); return $this; } @@ -183,7 +191,7 @@ public function setReturnMessage($returnMessage) */ public function getReturnCode() { - return $this->getData('returncode'); + return $this->getData(self::RETURN_CODE); } /** @@ -192,7 +200,7 @@ public function getReturnCode() */ public function setReturnCode($returnCode) { - $this->setData('returncode', $returnCode); + $this->setData(self::RETURN_CODE, $returnCode); return $this; } @@ -201,7 +209,7 @@ public function setReturnCode($returnCode) */ public function getJsonResponse() { - return json_decode($this->getData('jsonresponse'), true); + return json_decode($this->getData(self::JSON_RESPONSE), true); } /** @@ -210,7 +218,7 @@ public function getJsonResponse() */ public function setJsonResponse($jsonResponse) { - $this->setData('jsonresponse', $jsonResponse); + $this->setData(self::JSON_RESPONSE, $jsonResponse); return $this; } @@ -219,7 +227,7 @@ public function setJsonResponse($jsonResponse) */ public function getDatetime() { - return $this->getData('datatime'); + return $this->getData(self::DATE_TIME); } /** @@ -227,7 +235,7 @@ public function getDatetime() */ public function getSource() { - return $this->getData('source'); + return $this->getData(self::SOURCE); } /** @@ -236,7 +244,7 @@ public function getSource() */ public function setSource($source) { - $this->setData('source', $source); + $this->setData(self::SOURCE, $source); return $this; } } diff --git a/Model/TransactionRepository.php b/Model/TransactionRepository.php old mode 100755 new mode 100644 index 79f2e2c1247..66f57b49093 --- a/Model/TransactionRepository.php +++ b/Model/TransactionRepository.php @@ -9,98 +9,164 @@ * * @author Simon Gabriel * - * @package heidelpay - * @subpackage magento2 - * @category magento2 + * @package heidelpay/magento2 */ namespace Heidelpay\Gateway\Model; -use Heidelpay\Gateway\Model\ResourceModel\Transaction as TransactionAlias; +use Exception; +use Heidelpay\Gateway\Api\Data\TransactionSearchResultInterface; +use Heidelpay\Gateway\Api\TransactionRepositoryInterface; +use Heidelpay\Gateway\Model\ResourceModel\Transaction as ResourceTransaction; +use Magento\Framework\Api\SearchCriteriaInterface; +use Magento\Framework\Api\SortOrder; +use Magento\Framework\Exception\CouldNotDeleteException; use Magento\Framework\Exception\NoSuchEntityException; +use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as TransactionCollectionFactory; +use Heidelpay\Gateway\Model\ResourceModel\Transaction\Collection; class TransactionRepository implements TransactionRepositoryInterface { - /** @var Transaction[] */ - protected $instances = []; + /** @var TransactionFactory */ + private $transactionFactory; - /** @var Transaction[] */ - protected $instancesByQuoteId = []; + /** @var TransactionCollectionFactory */ + private $transactionCollectionFactory; - /** @var TransactionAlias */ - protected $resourceModel; + /** @var TransactionSearchResultInterfaceFactory */ + private $searchResultFactory; - /** @var TransactionFactory */ - protected $transactionFactory; + /** @var ResourceTransaction */ + private $resource; /** + * TransactionRepository constructor. + * * @param TransactionFactory $transactionFactory - * @param TransactionAlias $resourceModel + * @param TransactionCollectionFactory $transactionCollectionFactory + * @param TransactionSearchResultInterfaceFactory $transactionSearchResultInterfaceFactory + * @param ResourceTransaction $resource */ public function __construct( TransactionFactory $transactionFactory, - ResourceModel\Transaction $resourceModel + TransactionCollectionFactory $transactionCollectionFactory, + TransactionSearchResultInterfaceFactory $transactionSearchResultInterfaceFactory, + ResourceTransaction $resource ) { - $this->transactionFactory = $transactionFactory; - $this->resourceModel = $resourceModel; + $this->transactionFactory = $transactionFactory; + $this->transactionCollectionFactory = $transactionCollectionFactory; + $this->searchResultFactory = $transactionSearchResultInterfaceFactory; + $this->resource = $resource; } - /** - * @param $id - * @param bool $forceReload - * @return mixed - * @throws NoSuchEntityException + * {@inheritDoc} */ - public function getById($id, $forceReload = false) + public function save(Transaction $transaction) { - $cacheKey = $this->getCacheKey([$id]); - if ($forceReload || !isset($this->instances[$id][$cacheKey])) { - $transaction = $this->transactionFactory->create(); + $this->resource->save($transaction); + return $transaction; + } - if (!$id) { - throw new NoSuchEntityException(__('Requested transaction does not exist')); - } + /** + * {@inheritDoc} + */ + public function getById($id) + { + /** @var Transaction $transaction */ + $transaction = $this->transactionFactory->create(); + $this->resource->load($transaction, $id); + if (! $transaction->getId()) { + throw new NoSuchEntityException(__('Unable to find transaction with ID "%1"', $id)); + } + return $transaction; + } - $transaction->load($id); - $this->instances[$id][$cacheKey] = $transaction; - $this->instancesByQuoteId[$transaction->getTransactionId()][$cacheKey] = $transaction; + /** + * {@inheritDoc} + */ + public function delete(Transaction $transaction) + { + try { + $this->resource->delete($transaction); + } catch (Exception $e) { + throw new CouldNotDeleteException(__('Could not delete the transaction: %1', $e->getMessage())); } + } + + /** + * {@inheritDoc} + */ + public function getList(SearchCriteriaInterface $searchCriteria) + { + $collection = $this->transactionCollectionFactory->create(); + + $this->addFiltersToCollection($searchCriteria, $collection); + $this->addSortOrdersToCollection($searchCriteria, $collection); + $this->addPagingToCollection($searchCriteria, $collection); + + $collection->load(); - return $this->instances[$id][$cacheKey]; + return $this->buildSearchResult($searchCriteria, $collection); } -// /** -// * Fetches a a list of transactions by qouteId. -// * -// * @param $quoteId -// * @param bool $forceReload -// */ -// public function getByQuoteId($quoteId, $forceReload = false) -// { -// $cacheKey = $this->getCacheKey([$quoteId]); -// if ($forceReload || !isset($this->instancesByQuoteId[$quoteId][$cacheKey])) { -// $transaction = $this->transactionFactory->create(); -// $transactionId = $this->resourceModel; -// } -// } + // /** - * Get key for cache - * - * @param array $data - * @return string + * @param SearchCriteriaInterface $searchCriteria + * @param Collection $collection */ - private function getCacheKey($data) + private function addFiltersToCollection(SearchCriteriaInterface $searchCriteria, Collection $collection) { - $serializeData = []; - foreach ($data as $key => $value) { - if (is_object($value)) { - $serializeData[$key] = $value->getId(); - } else { - $serializeData[$key] = $value; + foreach ($searchCriteria->getFilterGroups() as $filterGroup) { + $conditions = []; + $fields = []; + foreach ($filterGroup->getFilters() as $filter) { + $fields[] = $filter->getField(); + $conditions[] = [$filter->getConditionType() => $filter->getValue()]; } + $collection->addFieldToFilter($fields, $conditions); + } + } + + /** + * @param SearchCriteriaInterface $searchCriteria + * @param Collection $collection + */ + private function addSortOrdersToCollection(SearchCriteriaInterface $searchCriteria, Collection $collection) + { + foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) { + $direction = $sortOrder->getDirection() === SortOrder::SORT_ASC ? 'asc' : 'desc'; + $collection->addOrder($sortOrder->getField(), $direction); } + } + + /** + * @param SearchCriteriaInterface $searchCriteria + * @param Collection $collection + */ + private function addPagingToCollection(SearchCriteriaInterface $searchCriteria, Collection $collection) + { + $collection->setPageSize($searchCriteria->getPageSize()); + $collection->setCurPage($searchCriteria->getCurrentPage()); + } + + /** + * @param SearchCriteriaInterface $searchCriteria + * @param Collection $collection + * + * @return TransactionSearchResultInterface + */ + private function buildSearchResult(SearchCriteriaInterface $searchCriteria, Collection $collection) + { + /** @var TransactionSearchResultInterface $searchResults */ + $searchResults = $this->searchResultFactory->create(); - return md5(serialize($serializeData)); + $searchResults->setSearchCriteria($searchCriteria); + $searchResults->setItems($collection->getItems()); + $searchResults->setTotalCount($collection->getSize()); + + return $searchResults; } + + // } diff --git a/Model/TransactionRepositoryInterface.php b/Model/TransactionRepositoryInterface.php deleted file mode 100644 index bc1f1a3e478..00000000000 --- a/Model/TransactionRepositoryInterface.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * @package heidelpay/${Package} - */ - -namespace Heidelpay\Gateway\Model; - -use Magento\Framework\Exception\NoSuchEntityException; - -interface TransactionRepositoryInterface -{ - /** - * @param $id - * @param bool $forceReload - * @return mixed - * @throws NoSuchEntityException - */ - public function getById($id, $forceReload = false); -} \ No newline at end of file diff --git a/Model/TransactionSearchResult.php b/Model/TransactionSearchResult.php new file mode 100644 index 00000000000..5061e8f09ce --- /dev/null +++ b/Model/TransactionSearchResult.php @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/etc/webapi.xml b/etc/webapi.xml index 03ab7c3242d..0f16b3ebbc4 100644 --- a/etc/webapi.xml +++ b/etc/webapi.xml @@ -18,10 +18,10 @@ - + - + \ No newline at end of file From ab3705b788056dbb40b6f78c2220c91619d27d17 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 21 Jun 2019 14:24:03 +0200 Subject: [PATCH 068/114] [cleanup] Apply optimizations. --- Controller/Index/Response.php | 3 +-- Helper/Payment.php | 12 ++++++++---- .../method-renderer/hgw-santander-hire-purchase.js | 1 - 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Controller/Index/Response.php b/Controller/Index/Response.php index 47e5f9de3f0..d651f046096 100755 --- a/Controller/Index/Response.php +++ b/Controller/Index/Response.php @@ -8,7 +8,6 @@ use Heidelpay\Gateway\Model\PaymentInformation; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; -use Heidelpay\Gateway\Model\TransactionFactory; use Magento\Framework\Controller\Result\RawFactory; use Heidelpay\PhpPaymentApi\Constants\PaymentMethod; use Heidelpay\PhpPaymentApi\Exceptions\HashVerificationException; @@ -274,7 +273,7 @@ protected function handleOrderMail($order) if ($order && $order->getId()) { $this->_orderSender->send($order); } - } catch (\Exception $e) { + } catch (Exception $e) { $this->_logger->error( 'Heidelpay - Response: Cannot send order confirmation E-Mail. ' . $e->getMessage() ); diff --git a/Helper/Payment.php b/Helper/Payment.php index b7a9f89dc6e..fd8fd48942d 100755 --- a/Helper/Payment.php +++ b/Helper/Payment.php @@ -89,14 +89,16 @@ public function __construct( /** * Returns an array containing the payment method code and the transaction type code. * + * @param $paymentCode + * + * @return array + * * @see PaymentMethod * @see TransactionType - * @param $PAYMENT_CODE - * @return array */ - public function splitPaymentCode($PAYMENT_CODE) + public function splitPaymentCode($paymentCode) { - return explode('.', $PAYMENT_CODE); + return explode('.', $paymentCode); } /** @@ -273,6 +275,8 @@ public function isRefundable($paymentCode) * Saves a transaction by the given invoice. * * @param Invoice $invoice + * + * @throws Exception */ public function saveTransaction(Invoice $invoice) { diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js b/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js index d605b1900e7..4575d9855ad 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js @@ -50,7 +50,6 @@ define( return this; }, - getAdditionalPaymentInformation: function() { // recognition: only when there is a logged in customer if (customer.isLoggedIn()) { From 59ee4e761681496709ce94bed4f8478176e4fada Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 21 Jun 2019 14:25:15 +0200 Subject: [PATCH 069/114] [cleanup] Add `generated` folder to ignore list. --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3caf4b3c474..5465c3d8df8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ /composer.phar /composer.lock /auth.json -/.idea \ No newline at end of file +/.idea +/generated/ From 810b2cae97822c006813ca499cbd421deff744b1 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 21 Jun 2019 14:52:15 +0200 Subject: [PATCH 070/114] [feature] (MAGE2-175) SAN HP: Fix TransactionSearchResultInterfaceFactory namespace. --- Model/TransactionRepository.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Model/TransactionRepository.php b/Model/TransactionRepository.php index 66f57b49093..18b13c48f84 100644 --- a/Model/TransactionRepository.php +++ b/Model/TransactionRepository.php @@ -15,6 +15,7 @@ use Exception; use Heidelpay\Gateway\Api\Data\TransactionSearchResultInterface; +use Heidelpay\Gateway\Api\Data\TransactionSearchResultInterfaceFactory; use Heidelpay\Gateway\Api\TransactionRepositoryInterface; use Heidelpay\Gateway\Model\ResourceModel\Transaction as ResourceTransaction; use Magento\Framework\Api\SearchCriteriaInterface; From 1386e4fc73252b7521d3b65669f7b03c313595a2 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 21 Jun 2019 16:20:28 +0200 Subject: [PATCH 071/114] [feature] (MAGE2-175) SAN HP: Enable showing link to selected installment plan in checkout. --- .../hgw-santander-hire-purchase.js | 17 ++++++----------- .../heidelpay-santander-hire-purchase.html | 7 ++++--- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js b/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js index 4575d9855ad..1967f81704e 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js @@ -24,6 +24,7 @@ define( defaults: { template: 'Heidelpay_Gateway/payment/heidelpay-santander-hire-purchase', hgwInstallmentPlanUrl: '', + hgwInstallmentPlanVisible: false, hgwDobYear: '', hgwDobMonth: '', hgwDobDay: '', @@ -46,7 +47,7 @@ define( initObservable: function() { this._super() - .observe(['hgwSalutation', 'hgwDobYear', 'hgwDobMonth', 'hgwDobDay', 'years']); + .observe(['hgwSalutation', 'hgwDobYear', 'hgwDobMonth', 'hgwDobDay', 'years', 'hgwInstallmentPlanUrl', 'hgwInstallmentPlanVisible']); return this; }, @@ -140,27 +141,21 @@ define( paymentMethod: this.item.method }; - // todo: start spinner here - storage.post(serviceUrl, JSON.stringify(hgwPayload)).done( + storage.get(serviceUrl + '?quoteId=' + quote.getQuoteId() + '&paymentMethod=' + this.item.method, JSON.stringify(hgwPayload)).done( function(rawData) { var data = JSON.parse(rawData); // set link to installment plan if( data !== null ) { if (data.hasOwnProperty('hgw_installment_plan_url')) { - console.log('installment_plan_url: ' + data.hgw_installment_plan_url); - parent.hgwInstallmentPlanUrl = data.hgw_installment_plan_url; + parent.hgwInstallmentPlanUrl(data.hgw_installment_plan_url); + parent.hgwInstallmentPlanVisible(true); } } } ).fail( function(rawData) { - console.log('something went horribly wrong: ' + rawData); - } - ).always( - function(rawData) { - // todo stop spinner here - console.log('Whatever'); + parent.hgwInstallmentPlanVisible(false); } ); } diff --git a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html index b5b8ee126e4..964602aea90 100644 --- a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html +++ b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html @@ -31,10 +31,11 @@
-
- - - - - - - - - From a34d63b4e723c6d96f09c21882633bb508567a28 Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Sat, 29 Jun 2019 23:08:17 +0200 Subject: [PATCH 080/114] [feature] (MAGE2-175) SAN HP: Add PA to perform payment. --- Controller/Index/Index.php | 2 +- .../HeidelpayAbstractPaymentMethod.php | 10 +++--- .../HeidelpayCreditCardPaymentMethod.php | 4 +-- .../HeidelpayDebitCardPaymentMethod.php | 4 +-- .../HeidelpayDirectDebitPaymentMethod.php | 2 +- ...idelpayDirectDebitSecuredPaymentMethod.php | 2 +- .../HeidelpayGiropayPaymentMethod.php | 5 ++- .../HeidelpayIDealPaymentMethod.php | 2 +- .../HeidelpayInvoicePaymentMethod.php | 8 +++-- .../HeidelpayInvoiceSecuredPaymentMethod.php | 4 +-- .../HeidelpayPayPalPaymentMethod.php | 4 +-- .../HeidelpayPrepaymentPaymentMethod.php | 6 ++-- ...lpaySantanderHirePurchasePaymentMethod.php | 31 +++++-------------- .../HeidelpaySofortPaymentMethod.php | 4 ++- .../frontend/templates/installment_plan.phtml | 4 +-- 15 files changed, 43 insertions(+), 49 deletions(-) diff --git a/Controller/Index/Index.php b/Controller/Index/Index.php index 6baa4ff51bc..09684d2c9ce 100755 --- a/Controller/Index/Index.php +++ b/Controller/Index/Index.php @@ -103,7 +103,7 @@ public function execute() // get the response object from the initial request. /** @var HeidelpayResponse $response */ - $response = $payment->getHeidelpayUrl($quote); + $response = $payment->getHeidelpayUrl($quote, $this->getRequest()->getParams()); $this->_logger->debug('Heidelpay init response : ' . print_r($response, 1)); diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 79ea79f8c8c..44c8674969d 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -3,18 +3,20 @@ namespace Heidelpay\Gateway\PaymentMethods; use Exception; +use Heidelpay\Gateway\Block\Payment\HgwAbstract; use Heidelpay\Gateway\Gateway\Config\HgwBasePaymentConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; use Heidelpay\Gateway\Helper\BasketHelper; use Heidelpay\Gateway\Helper\Payment as PaymentHelper; use Heidelpay\Gateway\Model\Config\Source\BookingMode; -use Heidelpay\Gateway\Model\ResourceModel\Transaction\Collection as TransactionCollection; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; +use Heidelpay\Gateway\Model\ResourceModel\Transaction\Collection as TransactionCollection; use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; use Heidelpay\Gateway\Model\Transaction; use Heidelpay\Gateway\Model\TransactionFactory; use Heidelpay\PhpBasketApi\Exception\InvalidBasketitemPositionException; use Heidelpay\PhpPaymentApi\ParameterGroups\BasketParameterGroup; +use Heidelpay\PhpPaymentApi\PaymentMethods\PaymentMethodInterface; use Heidelpay\PhpPaymentApi\Response; use Magento\Framework\Api\AttributeValueFactory; use Magento\Framework\Api\ExtensionAttributesFactory; @@ -43,8 +45,6 @@ use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; use Magento\Sales\Model\Order\Payment; -use Heidelpay\Gateway\Block\Payment\HgwAbstract; -use Heidelpay\PhpPaymentApi\PaymentMethods\PaymentMethodInterface; use Magento\Store\Model\ScopeInterface; use RuntimeException; @@ -435,11 +435,11 @@ public function refund(InfoInterface $payment, $amount) /** * @param Quote $quote + * @param array $data * @throws InvalidBasketitemPositionException * @throws LocalizedException - * @throws Exception */ - public function getHeidelpayUrl($quote) + public function getHeidelpayUrl($quote, array $data = []) { $this->setupInitialRequest(); diff --git a/PaymentMethods/HeidelpayCreditCardPaymentMethod.php b/PaymentMethods/HeidelpayCreditCardPaymentMethod.php index 9e7e23e1d42..27686d51a81 100755 --- a/PaymentMethods/HeidelpayCreditCardPaymentMethod.php +++ b/PaymentMethods/HeidelpayCreditCardPaymentMethod.php @@ -13,8 +13,8 @@ */ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\PhpPaymentApi\PaymentMethods\CreditCardPaymentMethod; use Heidelpay\Gateway\Model\Config\Source\BookingMode; +use Heidelpay\PhpPaymentApi\PaymentMethods\CreditCardPaymentMethod; class HeidelpayCreditCardPaymentMethod extends HeidelpayAbstractPaymentMethod { @@ -44,7 +44,7 @@ protected function setup() * * @see \Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod::getHeidelpayUrl() */ - public function getHeidelpayUrl($quote) + public function getHeidelpayUrl($quote, array $data = []) { // set initial data for the request parent::getHeidelpayUrl($quote); diff --git a/PaymentMethods/HeidelpayDebitCardPaymentMethod.php b/PaymentMethods/HeidelpayDebitCardPaymentMethod.php index 3737c80bae8..df56837e554 100755 --- a/PaymentMethods/HeidelpayDebitCardPaymentMethod.php +++ b/PaymentMethods/HeidelpayDebitCardPaymentMethod.php @@ -13,8 +13,8 @@ */ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\PhpPaymentApi\PaymentMethods\DebitCardPaymentMethod; use Heidelpay\Gateway\Model\Config\Source\BookingMode; +use Heidelpay\PhpPaymentApi\PaymentMethods\DebitCardPaymentMethod; class HeidelpayDebitCardPaymentMethod extends HeidelpayAbstractPaymentMethod { @@ -44,7 +44,7 @@ protected function setup() * * @see \Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod::getHeidelpayUrl() */ - public function getHeidelpayUrl($quote) + public function getHeidelpayUrl($quote, array $data = []) { // set initial data for the request parent::getHeidelpayUrl($quote); diff --git a/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php b/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php index b265263dc79..b06062ed8ae 100755 --- a/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php +++ b/PaymentMethods/HeidelpayDirectDebitPaymentMethod.php @@ -53,7 +53,7 @@ protected function setup() * @throws UndefinedTransactionModeException * @throws LocalizedException */ - public function getHeidelpayUrl($quote) + public function getHeidelpayUrl($quote, array $data = []) { $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); diff --git a/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php b/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php index 9ef32dd9efd..095e0c5eaaa 100755 --- a/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayDirectDebitSecuredPaymentMethod.php @@ -40,7 +40,7 @@ protected function setup() /** * @inheritdoc */ - public function getHeidelpayUrl($quote) + public function getHeidelpayUrl($quote, array $data = []) { $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); diff --git a/PaymentMethods/HeidelpayGiropayPaymentMethod.php b/PaymentMethods/HeidelpayGiropayPaymentMethod.php index 3928171e6f3..53f836742c5 100755 --- a/PaymentMethods/HeidelpayGiropayPaymentMethod.php +++ b/PaymentMethods/HeidelpayGiropayPaymentMethod.php @@ -13,6 +13,7 @@ */ namespace Heidelpay\Gateway\PaymentMethods; +use Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException; use Heidelpay\PhpPaymentApi\PaymentMethods\GiropayPaymentMethod; class HeidelpayGiropayPaymentMethod extends HeidelpayAbstractPaymentMethod @@ -36,8 +37,10 @@ protected function setup() /** * @inheritdoc + * + * @throws UndefinedTransactionModeException */ - public function getHeidelpayUrl($quote) + public function getHeidelpayUrl($quote, array $data = []) { // set initial data for the request parent::getHeidelpayUrl($quote); diff --git a/PaymentMethods/HeidelpayIDealPaymentMethod.php b/PaymentMethods/HeidelpayIDealPaymentMethod.php index 7b554112760..355099c4609 100644 --- a/PaymentMethods/HeidelpayIDealPaymentMethod.php +++ b/PaymentMethods/HeidelpayIDealPaymentMethod.php @@ -61,7 +61,7 @@ public function prepareAdditionalFormData(Response $response) return $bankList; } - public function getHeidelpayUrl($quote) + public function getHeidelpayUrl($quote, array $data = []) { // create the collection factory $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); diff --git a/PaymentMethods/HeidelpayInvoicePaymentMethod.php b/PaymentMethods/HeidelpayInvoicePaymentMethod.php index 81b0bd7eaba..94a5efc5735 100755 --- a/PaymentMethods/HeidelpayInvoicePaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoicePaymentMethod.php @@ -13,8 +13,10 @@ */ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\PhpPaymentApi\PaymentMethods\InvoicePaymentMethod; +use Exception; use Heidelpay\Gateway\Block\Info\Invoice as InvoiceBlock; +use Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException; +use Heidelpay\PhpPaymentApi\PaymentMethods\InvoicePaymentMethod; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; use Magento\Sales\Model\Order\Payment\Transaction; @@ -42,9 +44,10 @@ protected function setup() /** * Initial Request to heidelpay payment server to get the form / iframe url * {@inheritDoc} + * @throws UndefinedTransactionModeException * @see \Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod::getHeidelpayUrl() */ - public function getHeidelpayUrl($quote) + public function getHeidelpayUrl($quote, array $data = []) { // set initial data for the request parent::getHeidelpayUrl($quote); @@ -76,6 +79,7 @@ public function additionalPaymentInformation($response) /** * @inheritdoc + * @throws Exception */ public function pendingTransactionProcessing($data, &$order, $message = null) { diff --git a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php index 2870364e919..613345c93ec 100755 --- a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php @@ -13,9 +13,9 @@ */ namespace Heidelpay\Gateway\PaymentMethods; +use Heidelpay\Gateway\Block\Info\InvoiceSecured; use Heidelpay\Gateway\Model\PaymentInformation; use Heidelpay\PhpPaymentApi\PaymentMethods\InvoiceB2CSecuredPaymentMethod; -use Heidelpay\Gateway\Block\Info\InvoiceSecured; use Magento\Quote\Api\Data\CartInterface; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; @@ -46,7 +46,7 @@ protected function setup() * @inheritDoc * @see \Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod::getHeidelpayUrl() */ - public function getHeidelpayUrl($quote) + public function getHeidelpayUrl($quote, array $data = []) { // create the collection factory $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); diff --git a/PaymentMethods/HeidelpayPayPalPaymentMethod.php b/PaymentMethods/HeidelpayPayPalPaymentMethod.php index 5d77ef513d0..a9f04a34de8 100755 --- a/PaymentMethods/HeidelpayPayPalPaymentMethod.php +++ b/PaymentMethods/HeidelpayPayPalPaymentMethod.php @@ -13,8 +13,8 @@ */ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\PhpPaymentApi\PaymentMethods\PayPalPaymentMethod; use Heidelpay\Gateway\Model\Config\Source\BookingMode; +use Heidelpay\PhpPaymentApi\PaymentMethods\PayPalPaymentMethod; class HeidelpayPayPalPaymentMethod extends HeidelpayAbstractPaymentMethod { @@ -42,7 +42,7 @@ protected function setup() * {@inheritDoc} * @see \Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod::getHeidelpayUrl() */ - public function getHeidelpayUrl($quote) + public function getHeidelpayUrl($quote, array $data = []) { // set initial data for the request parent::getHeidelpayUrl($quote); diff --git a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php index 2435f43f6e9..fbb5f78e1b3 100755 --- a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php +++ b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php @@ -13,8 +13,9 @@ */ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\PhpPaymentApi\PaymentMethods\PrepaymentPaymentMethod; use Heidelpay\Gateway\Block\Info\Prepayment; +use Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException; +use Heidelpay\PhpPaymentApi\PaymentMethods\PrepaymentPaymentMethod; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; use Magento\Sales\Model\Order\Payment\Transaction; @@ -42,9 +43,10 @@ protected function setup() /** * Initial Request to heidelpay payment server to get the form / iframe url * {@inheritDoc} + * @throws UndefinedTransactionModeException * @see \Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod::getHeidelpayUrl() */ - public function getHeidelpayUrl($quote) + public function getHeidelpayUrl($quote, array $data = []) { parent::getHeidelpayUrl($quote); diff --git a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php index 4cce9fdd1a4..6934eb6b33e 100755 --- a/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php +++ b/PaymentMethods/HeidelpaySantanderHirePurchasePaymentMethod.php @@ -15,14 +15,12 @@ */ namespace Heidelpay\Gateway\PaymentMethods; +use Exception; use Heidelpay\Gateway\Model\PaymentInformation; use Heidelpay\Gateway\Wrapper\CustomerWrapper; -use Heidelpay\PhpBasketApi\Exception\InvalidBasketitemPositionException; use Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException; use Heidelpay\PhpPaymentApi\PaymentMethods\SantanderHirePurchasePaymentMethod; -use Heidelpay\PhpPaymentApi\Response; use Magento\Framework\App\ObjectManager; -use Magento\Framework\Exception\LocalizedException; use Magento\Quote\Api\Data\CartInterface; /** @@ -57,7 +55,7 @@ public function isAvailable(CartInterface $quote = null) { // in B2C payment methods, we don't want companies to be involved. // so, if the address contains a company, return false. - if ($quote !== null && !empty($quote->getBillingAddress()->getCompany())) { + if ($quote !== null && $quote->getBillingAddress() === null && !empty($quote->getBillingAddress()->getCompany())) { return false; } @@ -69,26 +67,11 @@ public function isAvailable(CartInterface $quote = null) * Initial Request to heidelpay payment server to get the form url * {@inheritDoc} * - * @see \Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod::getHeidelpayUrl() - */ - public function getHeidelpayUrl($quote) - { - return $this->performTransaction($quote); - } - - /** - * Performs the transaction, either IN if no HP.IN reference Id exists. - * - * @param $quote - * @param mixed $referenceId - * - * @return Response - * - * @throws InvalidBasketitemPositionException - * @throws LocalizedException * @throws UndefinedTransactionModeException + * @throws Exception + * @see \Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod::getHeidelpayUrl() */ - private function performTransaction($quote, $referenceId = null) + public function getHeidelpayUrl($quote, array $data = []) { // create the collection factory $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); @@ -123,8 +106,8 @@ private function performTransaction($quote, $referenceId = null) ->setCustomerOrderCount($customer->numberOfOrders()) ->setCustomerSince($customer->customerSince()); - if ($referenceId !== null) { - $this->_heidelpayPaymentMethod->authorizeOnRegistration($referenceId); + if (isset($data['referenceId']) && !empty($data['referenceId'])) { + $this->_heidelpayPaymentMethod->authorizeOnRegistration($data['referenceId']); } else { $this->_heidelpayPaymentMethod->initialize(); } diff --git a/PaymentMethods/HeidelpaySofortPaymentMethod.php b/PaymentMethods/HeidelpaySofortPaymentMethod.php index e2dc012253c..2c6d40b7b0e 100755 --- a/PaymentMethods/HeidelpaySofortPaymentMethod.php +++ b/PaymentMethods/HeidelpaySofortPaymentMethod.php @@ -13,6 +13,7 @@ */ namespace Heidelpay\Gateway\PaymentMethods; +use Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException; use Heidelpay\PhpPaymentApi\PaymentMethods\SofortPaymentMethod; class HeidelpaySofortPaymentMethod extends HeidelpayAbstractPaymentMethod @@ -37,9 +38,10 @@ protected function setup() /** * Initial Request to heidelpay payment server to get the form / iframe url * {@inheritDoc} + * @throws UndefinedTransactionModeException * @see \Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod::getHeidelpayUrl() */ - public function getHeidelpayUrl($quote) + public function getHeidelpayUrl($quote, array $data = []) { // set initial data for the request parent::getHeidelpayUrl($quote); diff --git a/view/frontend/templates/installment_plan.phtml b/view/frontend/templates/installment_plan.phtml index 55b64cfa16b..a3f107e581f 100644 --- a/view/frontend/templates/installment_plan.phtml +++ b/view/frontend/templates/installment_plan.phtml @@ -17,14 +17,14 @@ use Heidelpay\Gateway\Block\Hgw;
- + Santander Logo



-
+
diff --git a/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html b/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html index e0b6da27048..b79f8626235 100644 --- a/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html +++ b/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html @@ -144,6 +144,7 @@
diff --git a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html index fb352e93a1c..dd9363149fb 100644 --- a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html +++ b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html @@ -136,7 +136,7 @@
From 8f106d5c540ea5d2bcd2d3d0fca43254dc06f3fe Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Fri, 19 Jul 2019 11:02:03 +0200 Subject: [PATCH 106/114] (MAGE2-204) fix code style. --- PaymentMethods/HeidelpayInvoicePaymentMethod.php | 2 +- PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php | 6 +++--- PaymentMethods/HeidelpayPrepaymentPaymentMethod.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/PaymentMethods/HeidelpayInvoicePaymentMethod.php b/PaymentMethods/HeidelpayInvoicePaymentMethod.php index 42c4e3d32d0..227cfd850b9 100755 --- a/PaymentMethods/HeidelpayInvoicePaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoicePaymentMethod.php @@ -40,7 +40,7 @@ protected function setup() $this->_canRefund = true; $this->_canRefundInvoicePartial = true; $this->_formBlockType = InvoiceBlock::class; - $this->_infoBlockType = 'Heidelpay\Gateway\Block\Info\Invoice'; + $this->_infoBlockType = InvoiceBlock::class; } /** diff --git a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php index f0a7e04b738..d842a283138 100755 --- a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php @@ -13,7 +13,7 @@ */ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Block\Info\InvoiceSecured; +use Heidelpay\Gateway\Block\Info\InvoiceSecured as InvoiceSecuredBlock; use Heidelpay\Gateway\Model\PaymentInformation; use Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException; use Heidelpay\PhpPaymentApi\PaymentMethods\InvoiceB2CSecuredPaymentMethod; @@ -41,8 +41,8 @@ protected function setup() $this->_canRefund = true; $this->_canRefundInvoicePartial = true; $this->_usingBasket = true; - $this->_formBlockType = InvoiceSecured::class; - $this->_infoBlockType = InvoiceSecured::class; + $this->_formBlockType = InvoiceSecuredBlock::class; + $this->_infoBlockType = InvoiceSecuredBlock::class; $this->useShippingAddressAsBillingAddress = true; } diff --git a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php index 465c8a1467e..f4cd959ee7a 100755 --- a/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php +++ b/PaymentMethods/HeidelpayPrepaymentPaymentMethod.php @@ -14,7 +14,7 @@ namespace Heidelpay\Gateway\PaymentMethods; use Exception; -use Heidelpay\Gateway\Block\Info\Prepayment; +use Heidelpay\Gateway\Block\Info\Prepayment as PrepaymentBlock; use Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException; use Heidelpay\PhpPaymentApi\PaymentMethods\PrepaymentPaymentMethod; use Magento\Sales\Model\Order; @@ -39,8 +39,8 @@ protected function setup() $this->_canAuthorize = true; $this->_canRefund = true; $this->_canRefundInvoicePartial = true; - $this->_formBlockType = Prepayment::class; - $this->_infoBlockType = Prepayment::class; + $this->_formBlockType = PrepaymentBlock::class; + $this->_infoBlockType = PrepaymentBlock::class; } /** From dc0db2a387887f9e4b29ff6822962187a85d4b56 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Fri, 19 Jul 2019 12:40:40 +0200 Subject: [PATCH 107/114] (MAGE2-204) optimize form validation. --- .../web/js/view/payment/method-renderer/hgw-abstract.js | 1 - .../view/payment/method-renderer/hgw-directdebitsecured.js | 2 +- .../js/view/payment/method-renderer/hgw-invoicesecured.js | 2 +- .../payment/method-renderer/hgw-santander-hire-purchase.js | 5 +++-- .../template/payment/heidelpay-directdebit-secured-form.html | 4 ++-- .../web/template/payment/heidelpay-invoice-secured-form.html | 2 +- .../template/payment/heidelpay-santander-hire-purchase.html | 3 ++- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js b/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js index abf8ab343aa..888022f61e5 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js @@ -23,7 +23,6 @@ define( $.validator.addMethod( 'valid-date', function (date){ - console.log(date); return !(date == false); }, $.mage.__('Invalid date.') ); diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-directdebitsecured.js b/view/frontend/web/js/view/payment/method-renderer/hgw-directdebitsecured.js index ad5e6684714..8c3baa13591 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-directdebitsecured.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-directdebitsecured.js @@ -128,7 +128,7 @@ define( /** * Returns the birthdate in ISO 8601 format. * - * @returns {string} + * @returns {string|null} */ getBirthdate: function () { var day = this.hgwDobDay(); diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-invoicesecured.js b/view/frontend/web/js/view/payment/method-renderer/hgw-invoicesecured.js index e915274d913..2f627c5eaed 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-invoicesecured.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-invoicesecured.js @@ -110,7 +110,7 @@ define( /** * Returns the birthdate in ISO 8601 format. * - * @returns {string} + * @returns {string|null} */ getBirthdate: function () { var day = this.hgwDobDay(); diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js b/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js index c7e3caba4b8..f346b212061 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js @@ -108,14 +108,15 @@ define( /** * Returns the birthdate in ISO 8601 format. * - * @returns {string} + * @returns {string|null} */ getBirthdate: function () { var day = this.hgwDobDay(); var date = new Date(this.hgwDobYear(), this.hgwDobMonth(), day); // checks whether created date is same as input and return null if not. - return !(Boolean(+date) && date.getDate() == day) ? null : moment(date).format('YYYY-MM-DD'); + if(!(Boolean(+date) && date.getDate() == day)) {return null;} + return moment(date).format('YYYY-MM-DD'); }, /** diff --git a/view/frontend/web/template/payment/heidelpay-directdebit-secured-form.html b/view/frontend/web/template/payment/heidelpay-directdebit-secured-form.html index ac012e124fe..f2180aa2d17 100644 --- a/view/frontend/web/template/payment/heidelpay-directdebit-secured-form.html +++ b/view/frontend/web/template/payment/heidelpay-directdebit-secured-form.html @@ -166,8 +166,8 @@
diff --git a/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html b/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html index b79f8626235..9811661c363 100644 --- a/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html +++ b/view/frontend/web/template/payment/heidelpay-invoice-secured-form.html @@ -144,7 +144,7 @@ diff --git a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html index dd9363149fb..43abc1b5f65 100644 --- a/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html +++ b/view/frontend/web/template/payment/heidelpay-santander-hire-purchase.html @@ -136,7 +136,7 @@ @@ -146,6 +146,7 @@ From 5d4024a0753e47a61440b61014289914b62b90ad Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Fri, 19 Jul 2019 12:47:15 +0200 Subject: [PATCH 108/114] (MAGE2-204) refactor address validation. --- Controller/Index/Index.php | 12 ------ .../HeidelpayAbstractPaymentMethod.php | 42 +++++++++++++++++++ .../HeidelpayInvoiceSecuredPaymentMethod.php | 11 +---- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/Controller/Index/Index.php b/Controller/Index/Index.php index 7e62d14a137..8bf0171689a 100755 --- a/Controller/Index/Index.php +++ b/Controller/Index/Index.php @@ -103,18 +103,6 @@ public function execute() /** @var HeidelpayAbstractPaymentMethod $payment */ $payment = $quote->getPayment()->getMethodInstance(); - if($payment->getUseShippingAddressAsBillingAddress()) { - try { - $payment->validateEqualAddress($quote); - } catch (CheckoutValidationException $exception) { - $this->messageManager->addErrorMessage($exception->getMessage()); - return $this->_redirect('checkout/cart/', ['_secure' => true]); - } catch (\Exception $exception) { - $this->messageManager->addErrorMessage($errorMessage); - return $this->_redirect('checkout/cart/', ['_secure' => true]); - } - } - // get the response object from the initial request. /** @var HeidelpayResponse $response */ $response = $payment->getHeidelpayUrl($quote, $this->getRequest()->getParams()); diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 4a5f88229eb..60219307c2e 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -9,6 +9,7 @@ use Heidelpay\Gateway\Helper\BasketHelper; use Heidelpay\Gateway\Helper\Payment as PaymentHelper; use Heidelpay\Gateway\Model\Config\Source\BookingMode; +use Heidelpay\Gateway\Model\PaymentInformation; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\Transaction\Collection as TransactionCollection; use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; @@ -238,6 +239,28 @@ protected function setup() $this->useShippingAddressAsBillingAddress = false; } + /** + * @return $this|HeidelpayAbstractPaymentMethod + * @throws CheckoutValidationException + * @throws \Magento\Framework\Exception\LocalizedException + */ + public function validate() + { + parent::validate(); + $paymentInfo = $this->getInfoInstance(); + /** @var Quote $quote */ + $quote = $paymentInfo->getQuote(); + + if($quote === null || $quote->isEmpty() || !($quote->getPayment()->getMethodInstance() instanceof HeidelpayAbstractPaymentMethod)) { + return $this; + } + + if($this->useShippingAddressAsBillingAddress) { + $this->validateEqualAddress($quote); + } + return $this; + } + /** * Active redirect * @@ -841,4 +864,23 @@ public function getUseShippingAddressAsBillingAddress() { return $this->useShippingAddressAsBillingAddress; } + + /** + * @param $quote + * @return PaymentInformation + */ + protected function getPaymentInfo($quote) + { + // create the collection factory + $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); + + // load the payment information by store id, customer email address and payment method + /** @var PaymentInformation $paymentInfo */ + $paymentInfo = $paymentInfoCollection->loadByCustomerInformation( + $quote->getStoreId(), + $quote->getBillingAddress()->getEmail(), + $quote->getPayment()->getMethod() + ); + return $paymentInfo; + } } diff --git a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php index d842a283138..962a631c490 100755 --- a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php @@ -53,16 +53,7 @@ protected function setup() */ public function getHeidelpayUrl($quote, array $data = []) { - // create the collection factory - $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); - - // load the payment information by store id, customer email address and payment method - /** @var PaymentInformation $paymentInfo */ - $paymentInfo = $paymentInfoCollection->loadByCustomerInformation( - $quote->getStoreId(), - $quote->getBillingAddress()->getEmail(), - $quote->getPayment()->getMethod() - ); + $paymentInfo = $this->getPaymentInfo($quote); // set initial data for the request parent::getHeidelpayUrl($quote); From e50d2638fa41bc28a352a21f3c8993c4ef7cf8f3 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Fri, 19 Jul 2019 19:45:46 +0200 Subject: [PATCH 109/114] (MAGE2-204) removed redundancy. --- .../HeidelpayAbstractPaymentMethod.php | 12 +++++----- .../payment/method-renderer/hgw-abstract.js | 23 ++++++++++++++++--- .../method-renderer/hgw-directdebitsecured.js | 18 --------------- .../method-renderer/hgw-invoicesecured.js | 18 --------------- .../hgw-santander-hire-purchase.js | 18 --------------- 5 files changed, 26 insertions(+), 63 deletions(-) diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 60219307c2e..96364b094e0 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -242,7 +242,7 @@ protected function setup() /** * @return $this|HeidelpayAbstractPaymentMethod * @throws CheckoutValidationException - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function validate() { @@ -251,7 +251,7 @@ public function validate() /** @var Quote $quote */ $quote = $paymentInfo->getQuote(); - if($quote === null || $quote->isEmpty() || !($quote->getPayment()->getMethodInstance() instanceof HeidelpayAbstractPaymentMethod)) { + if($quote === null || $quote->isEmpty()) { return $this; } @@ -866,15 +866,15 @@ public function getUseShippingAddressAsBillingAddress() } /** - * @param $quote + * Load the payment information by store id, customer email address and payment method of the quote. + * @param Quote $quote * @return PaymentInformation */ - protected function getPaymentInfo($quote) + protected function getPaymentInfo(Quote $quote) { - // create the collection factory + // create the collection $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); - // load the payment information by store id, customer email address and payment method /** @var PaymentInformation $paymentInfo */ $paymentInfo = $paymentInfoCollection->loadByCustomerInformation( $quote->getStoreId(), diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js b/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js index 888022f61e5..837f8a08419 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js @@ -10,7 +10,7 @@ define( 'Magento_Checkout/js/action/select-billing-address', 'moment' ], - function ($, Component, placeOrderAction, additionalValidators, selectPaymentMethodAction, checkoutData, quote, selectBillingAddress) { + function ($, Component, placeOrderAction, additionalValidators, selectPaymentMethodAction, checkoutData, quote, selectBillingAddress, moment) { 'use strict'; // add IBAN validator @@ -23,6 +23,7 @@ define( $.validator.addMethod( 'valid-date', function (date){ + console.log(date); return !(date == false); }, $.mage.__('Invalid date.') ); @@ -50,7 +51,11 @@ define( defaults: { template: 'Heidelpay_Gateway/payment/heidelpay-form', - useShippingAddressAsBillingAddress: false + useShippingAddressAsBillingAddress: false, + hgwDobYear: '', + hgwDobMonth: '', + hgwDobDay: '', + hgwSalutation: '' }, /** @@ -76,7 +81,19 @@ define( * * This method needs to be overloaded by the payment renderer component, if needed. */ - getBirthdate: function() {}, + getBirthdate: function() { + var day = this.hgwDobDay(); + var year = this.hgwDobYear(); + var month = this.hgwDobMonth(); + + if (day === null || year === null || day === null) {return null;} + var date = new Date(year, month, day); + + // checks whether created date is same as input and return null if not. + if(!(Boolean(+date) && date.getDate() == day)) {return null;} + console.log('date is valid.'); + return moment(date).format('YYYY-MM-DD'); + }, /** * Function to receive the customer's full name. diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-directdebitsecured.js b/view/frontend/web/js/view/payment/method-renderer/hgw-directdebitsecured.js index 8c3baa13591..804f745b015 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-directdebitsecured.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-directdebitsecured.js @@ -25,10 +25,6 @@ define( template: 'Heidelpay_Gateway/payment/heidelpay-directdebit-secured-form', hgwIban: '', hgwHolder: '', - hgwSalutation: '', - hgwDobYear: '', - hgwDobMonth: '', - hgwDobDay: '', years: [null], useShippingAddressAsBillingAddress: true }, @@ -125,20 +121,6 @@ define( }; }, - /** - * Returns the birthdate in ISO 8601 format. - * - * @returns {string|null} - */ - getBirthdate: function () { - var day = this.hgwDobDay(); - var date = new Date(this.hgwDobYear(), this.hgwDobMonth(), day); - - // checks whether created date is same as input and return null if not. - if(!(Boolean(+date) && date.getDate() == day)) {return null;} - return moment(date).format('YYYY-MM-DD'); - }, - validate: function () { var form = $('#hgw-directdebit-secured-form'); diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-invoicesecured.js b/view/frontend/web/js/view/payment/method-renderer/hgw-invoicesecured.js index 2f627c5eaed..e72c1b02f3e 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-invoicesecured.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-invoicesecured.js @@ -23,10 +23,6 @@ define( defaults: { template: 'Heidelpay_Gateway/payment/heidelpay-invoice-secured-form', - hgwDobYear: '', - hgwDobMonth: '', - hgwDobDay: '', - hgwSalutation: '', years: [null], useShippingAddressAsBillingAddress: true }, @@ -107,20 +103,6 @@ define( }; }, - /** - * Returns the birthdate in ISO 8601 format. - * - * @returns {string|null} - */ - getBirthdate: function () { - var day = this.hgwDobDay(); - var date = new Date(this.hgwDobYear(), this.hgwDobMonth(), day); - - // checks whether created date is same as input and return null if not. - if(!(Boolean(+date) && date.getDate() == day)) {return null;} - return moment(date).format('YYYY-MM-DD'); - }, - validate: function() { var form = $('#hgw-invoice-secured-form'); diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js b/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js index f346b212061..495712b66af 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-santander-hire-purchase.js @@ -23,10 +23,6 @@ define( defaults: { template: 'Heidelpay_Gateway/payment/heidelpay-santander-hire-purchase', - hgwDobYear: '', - hgwDobMonth: '', - hgwDobDay: '', - hgwSalutation: '', years: [null], useShippingAddressAsBillingAddress: true }, @@ -105,20 +101,6 @@ define( }; }, - /** - * Returns the birthdate in ISO 8601 format. - * - * @returns {string|null} - */ - getBirthdate: function () { - var day = this.hgwDobDay(); - var date = new Date(this.hgwDobYear(), this.hgwDobMonth(), day); - - // checks whether created date is same as input and return null if not. - if(!(Boolean(+date) && date.getDate() == day)) {return null;} - return moment(date).format('YYYY-MM-DD'); - }, - /** * Returns true if validation succeeded * From 3caf0433188b14dc8f66c63140ab5138ff947466 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Fri, 19 Jul 2019 19:46:29 +0200 Subject: [PATCH 110/114] (MAGE2-204) change warning log level in redirect to error --- Controller/Index/Redirect.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Controller/Index/Redirect.php b/Controller/Index/Redirect.php index d8ed3f4b565..c08c4227145 100755 --- a/Controller/Index/Redirect.php +++ b/Controller/Index/Redirect.php @@ -109,8 +109,7 @@ public function execute() $quoteId = $session->getQuoteId(); if (empty($quoteId)) { - $this->_logger->warning('Heidelpay - Redirect: Called with empty quoteId'); - + $this->_logger->error('Heidelpay - Redirect: Called with empty quoteId'); return $this->_redirect('checkout/cart/', ['_secure' => true]); } From e99bb05c240c3a0403dcafc721fa21762d92b92e Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Fri, 19 Jul 2019 19:59:26 +0200 Subject: [PATCH 111/114] (MAGE2-204) cleanup code. --- .../web/js/view/payment/method-renderer/hgw-abstract.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js b/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js index 837f8a08419..920346b19c5 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js @@ -23,7 +23,6 @@ define( $.validator.addMethod( 'valid-date', function (date){ - console.log(date); return !(date == false); }, $.mage.__('Invalid date.') ); @@ -83,15 +82,10 @@ define( */ getBirthdate: function() { var day = this.hgwDobDay(); - var year = this.hgwDobYear(); - var month = this.hgwDobMonth(); - - if (day === null || year === null || day === null) {return null;} - var date = new Date(year, month, day); + var date = new Date(this.hgwDobYear(), this.hgwDobMonth(), day); // checks whether created date is same as input and return null if not. if(!(Boolean(+date) && date.getDate() == day)) {return null;} - console.log('date is valid.'); return moment(date).format('YYYY-MM-DD'); }, From f64d40bdc404da7b129ed5601fb89d8c6edb54d3 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 22 Jul 2019 11:33:15 +0200 Subject: [PATCH 112/114] (MAGE2-204) Change date validation. --- .../web/js/view/payment/method-renderer/hgw-abstract.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js b/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js index 920346b19c5..6fa269b01f1 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-abstract.js @@ -23,7 +23,7 @@ define( $.validator.addMethod( 'valid-date', function (date){ - return !(date == false); + return (date); }, $.mage.__('Invalid date.') ); $.validator.addMethod( From b89403a578efd408d3f698c12b72027403337259 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 22 Jul 2019 14:44:43 +0200 Subject: [PATCH 113/114] (MAGE2-204) Change: Adjustments for production mode. --- PaymentMethods/HeidelpayAbstractPaymentMethod.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 96364b094e0..fdc58e70186 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -833,20 +833,28 @@ protected function billingAddressEqualsShippingAddress($quote) $shippingAddress = $quote->getShippingAddress(); $billingAddress = $quote->getBillingAddress(); + $billingCompany = $billingAddress->getCompany(); + $shippingCompany = $shippingAddress->getCompany(); + + //Address should also be valid if both companies are empty + $equalCompany = ($billingCompany === $shippingCompany + || (empty($billingCompany)&& empty($shippingCompany)) + ); + return ($billingAddress->getFirstname() === $shippingAddress->getFirstname() && $billingAddress->getLastname() === $shippingAddress->getLastname() && $billingAddress->getStreet() === $shippingAddress->getStreet() && $billingAddress->getPostcode() === $shippingAddress->getPostcode() && $billingAddress->getCity() === $shippingAddress->getCity() && $billingAddress->getCountryId() === $shippingAddress->getCountryId() - && $billingAddress->getCompany() === $shippingAddress->getCompany() + && $equalCompany && $billingAddress->getTelephone() === $shippingAddress->getTelephone() ); } /** * @param Quote $quote - * @throws CheckoutValidationException + * @throws LocalizedException */ public function validateEqualAddress($quote) { @@ -854,7 +862,7 @@ public function validateEqualAddress($quote) $this->_logger->debug('isEqualAddress: ' . ($isEqualAddress ? 'Yes' : 'NO')); if (!$isEqualAddress) { - throw new CheckoutValidationException( + throw new LocalizedException( __('Billing address should be same as shipping address.') ); } From 747ab7f0aebff096c091c038005c591438a8fdd9 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Thu, 25 Jul 2019 16:00:01 +0200 Subject: [PATCH 114/114] (MAGE2-187) Change: update module version and changelog --- CHANGELOG.md | 4 +++- etc/module.xml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a07db3ca25..c1a632718cb 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,15 +3,17 @@ ## Versioning This project does not follow a versioning standard. Versions are crafted after the dates; for example, the version 17.7.25 was released on July, 25th in 2017 -## X.X.X +## 19.7.29 ### Added - Santander hire purchase payment method. +- Check whether customer is already 18 if payment method requires it. ### Fixed - A problem where a transaction was processed a second time via push when using "sofort". That caused the paid amount to be displayed incorrectly. - A problem which led to a missing error message for the customer. +- An issue with basket calculation when order has a discount. ### Changed - Refactored paymentMethods. Simplify configuration and reduce duplicate code in payment methods. diff --git a/etc/module.xml b/etc/module.xml index af07672a047..7f66e537471 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,5 +1,5 @@ - +