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

Commit

Permalink
Merge pull request #19 from heidelpay/develop
Browse files Browse the repository at this point in the history
17.3.28
  • Loading branch information
devheidelpay authored Mar 28, 2017
2 parents 1d21495 + cff6b1e commit 8ce35eb
Show file tree
Hide file tree
Showing 39 changed files with 1,476 additions and 707 deletions.
170 changes: 97 additions & 73 deletions Api/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ public function __construct(
) {
$this->quoteRepository = $quoteRepository;
$this->quoteIdMaskFactory = $quoteIdMaskFactory;

$this->paymentInformationFactory = $paymentInformationFactory;
$this->paymentInformationCollectionFactory = $paymentInformationCollectionFactory;

$this->encryptor = $encryptor;
$this->logger = $logger;
$this->scopeConfig = $scopeConfig;
Expand All @@ -92,7 +94,7 @@ public function getAdditionalPaymentInformation($quoteId, $paymentMethod)

// if recognition is set to 'never', we don't return any data.
if ($allowRecognition == Recognition::RECOGNITION_NEVER) {
$result = null;
return json_encode(null);
}

// get the customer payment information by given data from the request.
Expand Down Expand Up @@ -120,11 +122,10 @@ public function getAdditionalPaymentInformation($quoteId, $paymentMethod)
}
}

// if we have no data at all, set the account owner to the billing address name.
// if we have no data at all, set additional data that could be making it
// a bit easier for the customer, by helping him to fill some fields.
if ($result === null) {
$result = [
'hgw_holder' => $quote->getBillingAddress()->getName()
];
$result = $this->getAdditionalDataForPaymentMethod($paymentMethod, $quote);
}

return json_encode($result);
Expand All @@ -133,58 +134,32 @@ public function getAdditionalPaymentInformation($quoteId, $paymentMethod)
/**
* @inheritdoc
*/
public function saveDirectDebitInfo($cartId, $hgwIban, $hgwHolder)
public function saveAdditionalPaymentInfo($cartId, $method, $additionalData)
{
$additionalData = [
'hgw_iban' => $hgwIban,
'hgw_holder' => $hgwHolder
];

// get the quote information by cart id
$quote = $this->quoteRepository->get($cartId);

// create a new instance for the payment information collection.
$paymentInfoCollection = $this->paymentInformationCollectionFactory->create();

// load payment information by the customer's quote.
/** @var \Heidelpay\Gateway\Model\PaymentInformation $paymentInfo */
$paymentInfo = $paymentInfoCollection->loadByCustomerInformation(
$quote->getStoreId(),
$quote->getCustomerEmail(),
$quote->getPayment()->getMethod()
);

// if there is no payment information data set, we create a new one...
if ($paymentInfo->isEmpty()) {
// create a new instance for the payment information data.
$paymentInfoFactory = $this->paymentInformationFactory->create();

// save the payment information
if ($this->savePaymentInformation($paymentInfoFactory, $quote, $additionalData)) {
return true;
}

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);
}

// ... else, we update the data and save the model.
if ($this->savePaymentInformation($paymentInfo, $quote, $additionalData)) {
return true;
// 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);
}

return false;
// ... if it was successful, we return true.
return json_encode(true);
}

/**
* @inheritdoc
*/
public function saveGuestDirectDebitInfo($cartId, $hgwIban, $hgwHolder)
public function saveGuestAdditionalPaymentInfo($cartId, $method, $additionalData)
{
$additionalData = [
'hgw_iban' => $hgwIban,
'hgw_holder' => $hgwHolder
];

// get the real quote id by guest cart id (masked random string serves as guest cart id)
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
Expand All @@ -193,36 +168,21 @@ public function saveGuestDirectDebitInfo($cartId, $hgwIban, $hgwHolder)
// get the quote information by cart id
$quote = $this->quoteRepository->get($quoteId);

// create a new instance for the payment information collection.
$paymentInfoCollection = $this->paymentInformationCollectionFactory->create();

// load payment information by the customer's quote.
/** @var \Heidelpay\Gateway\Model\PaymentInformation $paymentInfo */
$paymentInfo = $paymentInfoCollection->loadByCustomerInformation(
$quote->getStoreId(),
$quote->getCustomerEmail(),
$quote->getPayment()->getMethod()
);

// if there is no payment information data set, we create a new one...
if ($paymentInfo->isEmpty()) {
// create a new instance for the payment information data.
$paymentInfoFactory = $this->paymentInformationFactory->create();

// save the payment information
if ($this->savePaymentInformation($paymentInfoFactory, $quote, $additionalData)) {
return true;
}

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);
}

// ... else, we update the data and save the model.
if ($this->savePaymentInformation($paymentInfo, $quote, $additionalData)) {
return true;
// 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);
}

return false;
// ... if it was successful, we return true.
return json_encode(true);
}

/**
Expand All @@ -245,21 +205,85 @@ private function createShippingHash(\Magento\Quote\Model\Quote\Address $address)
);
}

/**
* Returns information for a given payment method, if there is
* no additional data stored yet. This is just for making it
* the customer a bit easier, because he is not in need
* of entering every needed data again for a given
* payment method.
* For example, the bank account holder in Direct Debits
* tends to be the same person as the one mentioned in
* the Billing address.
*
* @param string $method
* @param \Magento\Quote\Model\Quote $quote
* @return array|null
*/
private function getAdditionalDataForPaymentMethod($method, $quote)
{
$result = [];

switch ($method) {
case 'hgwdd':
$result['hgw_holder'] = $quote->getBillingAddress()->getName(); // full billing name
break;

case 'hgwdds':
$result['hgw_birthdate'] = $quote->getCustomer()->getDob(); // date of birth
$result['hgw_holder'] = $quote->getBillingAddress()->getName(); // full billing name
break;

default:
$result = null;
break;
}

return $result;
}

/**
* Saves the payment information into the database.
*
* @param \Heidelpay\Gateway\Model\PaymentInformation $paymentInformation
* 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 string $method
* @param string $email
* @param array $additionalData
* @param string $paymentRef
* @return \Heidelpay\Gateway\Api\Data\PaymentInformationInterface
*/
private function savePaymentInformation($paymentInformation, $quote, $additionalData, $paymentRef = null)
private function savePaymentInformation($quote, $method, $email, $additionalData, $paymentRef = null)
{
// make some additional data changes, if neccessary
array_walk($additionalData, function (&$value, $key) {
// if somehow the country code in the IBAN is lowercase, convert it to uppercase.
if ($key == 'hgw_iban') {
$value = strtoupper($value);
}
});

// create a new instance for the payment information collection.
$paymentInfoCollection = $this->paymentInformationCollectionFactory->create();

// load payment information by the customer's quote.
/** @var \Heidelpay\Gateway\Model\PaymentInformation $paymentInfo */
$paymentInformation = $paymentInfoCollection->loadByCustomerInformation(
$quote->getStoreId(),
$email,
$method
);

// if there is no payment information data set, we create a new one...
if ($paymentInformation->isEmpty()) {
$paymentInformation = $this->paymentInformationFactory->create();
}

return $paymentInformation
->setStoreId($quote->getStoreId())
->setCustomerEmail($quote->getCustomer()->getEmail())
->setPaymentMethod($quote->getPayment()->getMethod())
->setCustomerEmail($email)
->setPaymentMethod($method)
->setShippingHash($this->createShippingHash($quote->getShippingAddress()))
->setAdditionalData($additionalData)
->setHeidelpayPaymentReference($paymentRef)
Expand Down
20 changes: 10 additions & 10 deletions Api/PaymentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ interface PaymentInterface
public function getAdditionalPaymentInformation($quoteId, $paymentMethod);

/**
* Method for storing additional payment data for customers
* Method for storing additional payment data for customers.
*
* @param int $cartId
* @param string $hgwIban
* @param string $hgwOwner
* @return boolean
* @param string $method The payment method code
* @param mixed $additionalData
* @return string
*/
public function saveDirectDebitInfo($cartId, $hgwIban, $hgwOwner);
public function saveAdditionalPaymentInfo($cartId, $method, $additionalData);

/**
* Method for storing additional payment data for guest customers
* Method for storing additional payment data for guest customers.
*
* @param string $cartId
* @param string $hgwIban
* @param string $hgwOwner
* @return boolean
* @param string $method The payment method code
* @param mixed $additionalData
* @return string
*/
public function saveGuestDirectDebitInfo($cartId, $hgwIban, $hgwOwner);
public function saveGuestAdditionalPaymentInfo($cartId, $method, $additionalData);
}
20 changes: 12 additions & 8 deletions Block/Checkout/Success.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
<?php
<?php

namespace Heidelpay\Gateway\Block\Checkout;

/**
* Add payment information to the checkout success block
*
*
* @license Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
* @copyright Copyright © 2016-present Heidelberger Payment GmbH. All rights reserved.
*
* @link https://dev.heidelpay.de/magento
* @link https://dev.heidelpay.de/magento
*
* @author Jens Richter
* @author Jens Richter
*
* @package Heidelpay
* @subpackage Magento2
* @category Magento2
* @package heidelpay
* @subpackage magento2
* @category magento2
*/
class Success extends \Magento\Checkout\Block\Onepage\Success
{
public function getHeidelpayInfo()
{
$info = ($this->_checkoutSession->getHeidelpayInfo() !== false) ? $this->_checkoutSession->getHeidelpayInfo() : false;
$info = ($this->_checkoutSession->getHeidelpayInfo() !== false)
? $this->_checkoutSession->getHeidelpayInfo()
: false;

$this->_checkoutSession->setHeidelpayInfo(false);

return $info;
}
}
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Release Notes - heidelpay Payment Gateway for Magento 2

## v17.3.28

### Added
- Direct Debit Secured (B2C) Payment method (DE, AT, CH)
- Enabled Min/Max Total Order sum configurations for every available payment method

### Changed
- Input fields for heidelpay payment methods will now be validated before placing the order.
- B2C payment methods cannot be used when a company is given.
- Replaced the in-module result code mapping with the [heidelpay php-customer-messages package](https://github.com/heidelpay/php-customer-messages)

### Fixed
- Fixed issue #11: heidelpay Payment Gateway now uses the currency from the customer quote instead of the system default.

## v17.3.13

### Added
Expand Down
2 changes: 1 addition & 1 deletion Controller/HgwAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ abstract class HgwAbstract extends \Magento\Framework\App\Action\Action
protected $_quoteObject;

/**
* @var \Magento\Quote\Api\CartManagementInterface
* @var \Magento\Quote\Model\QuoteManagement
*/
protected $_cartManagement;

Expand Down
Loading

0 comments on commit 8ce35eb

Please sign in to comment.