Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
szreka committed Nov 10, 2020
0 parents commit bc96fae
Show file tree
Hide file tree
Showing 26 changed files with 1,069 additions and 0 deletions.
Empty file added .gitignore
Empty file.
16 changes: 16 additions & 0 deletions Api/AdyenRedirectInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Jh\AdyenPayment\Api;

use Jh\AdyenPayment\Api\Data\RedirectResponseInterface;

interface AdyenRedirectInterface
{
/**
* @param int $orderId
* @return \Jh\AdyenPayment\Api\Data\RedirectResponseInterface
*/
public function execute(int $orderId): RedirectResponseInterface;
}
18 changes: 18 additions & 0 deletions Api/AdyenResultInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Jh\AdyenPayment\Api;

use Jh\AdyenPayment\Api\Data\ResultResponseInterface;

interface AdyenResultInterface
{
/**
* @param int $orderId
* @param string $response
* @param string $resultCode
* @return \Jh\AdyenPayment\Api\Data\ResultResponseInterface
*/
public function execute(int $orderId, string $response, string $resultCode = null): ResultResponseInterface;
}
26 changes: 26 additions & 0 deletions Api/AdyenThreeDS1ProcessInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);

namespace Jh\AdyenPayment\Api;

use Magento\Framework\Exception\LocalizedException;

interface AdyenThreeDS1ProcessInterface
{
/**
* @param int $orderId
* @param string $md
* @param string $paReq
* @return void
* @throws LocalizedException
*/
public function authorise(int $orderId, string $md, string $paReq): void;

/**
* @param object $payment
* @param string $md
* @param string $paRes
* @return void
*/
public function authorisePayment($payment, string $md, $paRes): void;
}
16 changes: 16 additions & 0 deletions Api/AdyenThreeDSAbortInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);

namespace Jh\AdyenPayment\Api;

use Magento\Framework\Exception\LocalizedException;

interface AdyenThreeDSAbortInterface
{
/**
* @param int $orderId
* @return void
* @throws LocalizedException
*/
public function abort(int $orderId): void;
}
30 changes: 30 additions & 0 deletions Api/Data/RedirectResponseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Jh\AdyenPayment\Api\Data;

interface RedirectResponseInterface
{
/**
* @return int
*/
public function getOrderId(): int;

/**
* @param int $orderId
* @return void
*/
public function setOrderId(int $orderId): void;

/**
* @return string
*/
public function getRedirectUrl(): string;

/**
* @param string $orderId
* @return void
*/
public function setRedirectUrl(string $redirectUrl): void;
}
52 changes: 52 additions & 0 deletions Api/Data/ResultResponseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace Jh\AdyenPayment\Api\Data;

interface ResultResponseInterface
{
/**
* @return int
*/
public function getOrderId(): int;

/**
* @param int $orderId
* @return void
*/
public function setOrderId(int $orderId): void;

/**
* @return int
*/
public function getQuoteId(): int;

/**
* @param int $quoteId
* @return void
*/
public function setQuoteId(int $quoteId): void;

/**
* @return string
*/
public function getResponse(): string;

/**
* @param string $response
* @return void
*/
public function setResponse(string $response): void;

/**
* @return string
*/
public function getMessage(): string;

/**
* @param string $message
* @return void
*/
public function setMessage(string $message): void;
}
41 changes: 41 additions & 0 deletions Gateway/Request/CheckoutDataBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Jh\AdyenPayment\Gateway\Request;

use Adyen\Payment\Gateway\Request\CheckoutDataBuilder as OrigCheckoutDataBuilder;
use Adyen\Payment\Helper\Data;
use Adyen\Payment\Model\Gender;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Quote\Api\CartRepositoryInterface;

class CheckoutDataBuilder extends OrigCheckoutDataBuilder
{
private $adyenHelper;

public function __construct(
Data $adyenHelper,
StoreManagerInterface $storeManager,
CartRepositoryInterface $cartRepository,
Gender $gender
) {
parent::__construct($adyenHelper, $storeManager, $cartRepository, $gender);

$this->adyenHelper = $adyenHelper;
}

public function build(array $buildSubject)
{
$request = parent::build($buildSubject);

$customOrigin = $this->adyenHelper->getAdyenAbstractConfigData('origin_key_domain');
if ($customOrigin) {
$customPath = $this->adyenHelper->getAdyenAbstractConfigData('pwa_return_path');
$path = $customPath ?? 'adyen/process/result';
$request['body']['returnUrl'] = sprintf('%s/%s', $customOrigin, $path);
}

return $request;
}
}
33 changes: 33 additions & 0 deletions Model/RedirectResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Jh\AdyenPayment\Model;

use Jh\AdyenPayment\Api\Data\RedirectResponseInterface;

class RedirectResponse implements RedirectResponseInterface
{
private $orderId;
private $redirectUrl;

public function getOrderId(): int
{
return $this->orderId;
}

public function setOrderId(int $orderId): void
{
$this->orderId = $orderId;
}

public function getRedirectUrl(): string
{
return $this->redirectUrl;
}

public function setRedirectUrl(string $redirectUrl): void
{
$this->redirectUrl = $redirectUrl;
}
}
55 changes: 55 additions & 0 deletions Model/ResultResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Jh\AdyenPayment\Model;

use Jh\AdyenPayment\Api\Data\ResultResponseInterface;

class ResultResponse implements ResultResponseInterface
{
private $orderId;
private $quoteId;
private $response;
private $message;

public function getOrderId(): int
{
return $this->orderId;
}

public function setOrderId(int $orderId): void
{
$this->orderId = $orderId;
}

public function getQuoteId(): int
{
return $this->quoteId;
}

public function setQuoteId(int $quoteId): void
{
$this->quoteId = $quoteId;
}

public function getResponse(): string
{
return $this->response;
}

public function setResponse(string $response): void
{
$this->response = $response;
}

public function getMessage(): string
{
return $this->message;
}

public function setMessage(string $message): void
{
$this->message = $message;
}
}
18 changes: 18 additions & 0 deletions Plugin/CustomOriginPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Jh\AdyenPayment\Plugin;

use Adyen\Payment\Helper\Data as Subject;

class CustomOriginPlugin
{
public function aroundGetOrigin(Subject $subject, callable $proceed)
{
if ($customOrigin = $subject->getAdyenAbstractConfigData('origin_key_domain')) {
return $customOrigin;
}
return $proceed();
}
}
55 changes: 55 additions & 0 deletions Plugin/ThreeDS1RedirectPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Jh\AdyenPayment\Plugin;

use Adyen\Payment\Model\AdyenOrderPaymentStatus;
use Adyen\Payment\Model\Ui\AdyenCcConfigProvider;
use Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider;
use Magento\Sales\Api\OrderRepositoryInterface;

class ThreeDS1RedirectPlugin
{
private $orderRepository;

public function __construct(OrderRepositoryInterface $orderRepository)
{
$this->orderRepository = $orderRepository;
}

public function afterGetOrderPaymentStatus(AdyenOrderPaymentStatus $adyenOrderPaymentStatus, $response, $orderId)
{
if (!is_string($response)) {
return $response;
}

$payment = $this->orderRepository->get($orderId)->getPayment();

if ($payment->getMethod() === AdyenCcConfigProvider::CODE ||
$payment->getMethod() === AdyenOneclickConfigProvider::CODE
) {
$response = json_decode($response, true);

if (($response['threeDS2'] ?? false) === false && ($response['type'] ?? '') === 'RedirectShopper') {
$additionalInformation = $payment->getAdditionalInformation();

$response = array_merge($response, [
'redirect' => [
'data' => [
'PaReq' => $additionalInformation['paRequest'] ?? null,
'MD' => $additionalInformation['md'] ?? null,
'TermUrl' => null
],
'method' => $additionalInformation['redirectMethod'] ?? 'POST',
'url' => $additionalInformation['redirectUrl'] ?? null
]
]);
}

return json_encode($response);
}

return $response;
}
}
Loading

0 comments on commit bc96fae

Please sign in to comment.