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 #84 from heidelpay/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Ryouzanpaku authored Oct 1, 2018
2 parents 74861a3 + 1334dfd commit 7437f1b
Show file tree
Hide file tree
Showing 18 changed files with 656 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/.project
/composer.phar
/composer.lock
/auth.json
/auth.json
/.idea
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

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

## 18.10.1

### Added
- payment method iDeal

## 18.9.20

### Fixed
Expand Down
140 changes: 140 additions & 0 deletions Controller/Index/InitializePayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php
/**
* This controller calls the initialization transaction if existing and necessary for the selected payment method.
*
* @license Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
* @copyright Copyright © 2016-present heidelpay GmbH. All rights reserved.
* @link https://dev.heidelpay.de/magento2
* @author David Owusu
*
* @package heidelpay
* @subpackage magento2
* @category magento2
*/

namespace Heidelpay\Gateway\Controller\Index;

use Magento\Checkout\Model\Session;
use Magento\Framework\App\Action\Action;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Escaper;
use Magento\Framework\Exception\NotFoundException;
use Magento\Framework\Phrase;
use Magento\Payment\Gateway\Command\CommandException;
use Psr\Log\LoggerInterface;
use Heidelpay\PhpPaymentApi\Response as PaymentApiResponse;

class InitializePayment extends Action
{
/**
* @var JsonFactory
*/
private $resultJsonFactory;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @var Session
*/
private $checkoutSession;

/**
* @var Escaper
*/
private $escaper;

/**
* InitializePayment constructor.
* @param Context $context
* @param JsonFactory $resultJsonFactory
* @param LoggerInterface $logger
* @param Session $checkoutSession
* @param Escaper $escaper
*/
public function __construct(
Context $context,
JsonFactory $resultJsonFactory,
LoggerInterface $logger,
Session $checkoutSession,
Escaper $escaper
) {
$this->resultJsonFactory = $resultJsonFactory;
$this->logger = $logger;
$this->checkoutSession = $checkoutSession;
$this->escaper = $escaper;
parent::__construct($context);
}

/**
* {@inheritDoc}
* @throws \Magento\Framework\Exception\NotFoundException
* @throws \RuntimeException
* @throws CommandException
*/
public function execute()
{
/** @noinspection PhpUndefinedFunctionInspection */
$error_message = __('An unexpected error occurred. Please contact us to get further information.');

$session = $this->getCheckoutSession();
$quote = $session->getQuote();

if (!$quote->getId()) {
$this->logger->error('Heidelpay: Quote not found in session.');
throw new NotFoundException(new Phrase($this->escaper->escapeHtml($error_message)));
}

// create result object for this request
$result = $this->resultJsonFactory->create();

// if there is no post request, just do nothing and return the redirectUrl instantly, so an
// error message can be shown to the customer (which will be created in the redirect controller)
if (!$this->getRequest()->isPost()) {
$this->logger->warning('Heidelpay - Response: Request is not POST.');

// return the result now, no further processing.
return $result;
}

$postData = $this->getRequest()->getParams();
$this->logger->debug('Heidelpay: postData - ' . print_r($postData, 1));

if (!isset($postData['method'])) {
throw new CommandException(new Phrase('Heidelpay: '));
}
$payment = $quote->getPayment()->setMethod($postData['method']);
$paymentMethodInstance = $payment->getMethodInstance();

// get the response object from the initial request.
try {
/** @var PaymentApiResponse $response */
$response = $paymentMethodInstance->initMethod($quote);
} catch (\Exception $e) {
$postData = [
$e->getLogMessage()
];
return $result->setData($postData)->setHttpResponseCode(500);
}

if ((!$response instanceof PaymentApiResponse || !$response->isSuccess())) {
$this->logger->error('Heidelpay: Initial request did not succeed.');
throw new \RuntimeException($this->escaper->escapeHtml($error_message));
}

$postData = $paymentMethodInstance->prepareAdditionalFormData($response);

return $result->setData(json_encode($postData));
}

/**
* @return Session
*/
private function getCheckoutSession()
{
return $this->checkoutSession;
}
}
19 changes: 19 additions & 0 deletions Gateway/Config/HgwIDealPaymentConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Payment config representation for iDeal injected for HgwIDealPaymentConfigInterface.
*
* @license Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
* @copyright Copyright © 2016-present heidelpay GmbH. All rights reserved.
*
* @link http://dev.heidelpay.com/
*
* @author David Owusu <development@heidelpay.com>
*
* @package heidelpay/magento2
*/

namespace Heidelpay\Gateway\Gateway\Config;

class HgwIDealPaymentConfig extends HgwBasePaymentConfig implements HgwIDealPaymentConfigInterface
{
}
19 changes: 19 additions & 0 deletions Gateway/Config/HgwIDealPaymentConfigInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Interface for payment config representation for iDeal.
*
* @license Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
* @copyright Copyright © 2016-present heidelpay GmbH. All rights reserved.
*
* @link http://dev.heidelpay.com/
*
* @author David Owusu <development@heidelpay.com>
*
* @package heidelpay/magento2
*/

namespace Heidelpay\Gateway\Gateway\Config;

interface HgwIDealPaymentConfigInterface extends HgwBasePaymentConfigInterface
{
}
42 changes: 34 additions & 8 deletions PaymentMethods/HeidelpayAbstractPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,7 @@ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
*/
public function getHeidelpayUrl($quote)
{
$this->performAuthentication();

$frontend = $this->getFrontend();

$this->_heidelpayPaymentMethod->getRequest()->async(
$frontend['LANGUAGE'], // Language code for the Frame
$frontend['RESPONSE_URL'] // Response url from your application
);
$this->setupInitialRequest();

$user = $this->getUser($quote);
$this->_heidelpayPaymentMethod->getRequest()->customerAddress(
Expand Down Expand Up @@ -776,6 +769,26 @@ private function performAuthentication()
);
}

/**
* Function to provide additional form data.
* Should be overwritten by child classes if needed.
* @param Response $response
* @return array
*/
public function prepareAdditionalFormData(Response $response)
{
return [];
}

/*
* Setup initialreques without customer data.
*/
public function setupInitialRequest()
{
$this->performAuthentication();
$this->setAsync();
}

/**
* will return the main configuration
*
Expand All @@ -795,4 +808,17 @@ public function getConfig()
{
return $this->paymentConfig;
}

/**
* Set the parameter for async modus.
*/
public function setAsync()
{
$frontend = $this->getFrontend();

$this->_heidelpayPaymentMethod->getRequest()->async(
$frontend['LANGUAGE'], // Language code for the Frame
$frontend['RESPONSE_URL'] // Response url from your application
);
}
}
Loading

0 comments on commit 7437f1b

Please sign in to comment.