Skip to content

Commit bc96fae

Browse files
committed
Initial commit
0 parents  commit bc96fae

26 files changed

+1069
-0
lines changed

.gitignore

Whitespace-only changes.

Api/AdyenRedirectInterface.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jh\AdyenPayment\Api;
6+
7+
use Jh\AdyenPayment\Api\Data\RedirectResponseInterface;
8+
9+
interface AdyenRedirectInterface
10+
{
11+
/**
12+
* @param int $orderId
13+
* @return \Jh\AdyenPayment\Api\Data\RedirectResponseInterface
14+
*/
15+
public function execute(int $orderId): RedirectResponseInterface;
16+
}

Api/AdyenResultInterface.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jh\AdyenPayment\Api;
6+
7+
use Jh\AdyenPayment\Api\Data\ResultResponseInterface;
8+
9+
interface AdyenResultInterface
10+
{
11+
/**
12+
* @param int $orderId
13+
* @param string $response
14+
* @param string $resultCode
15+
* @return \Jh\AdyenPayment\Api\Data\ResultResponseInterface
16+
*/
17+
public function execute(int $orderId, string $response, string $resultCode = null): ResultResponseInterface;
18+
}

Api/AdyenThreeDS1ProcessInterface.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Jh\AdyenPayment\Api;
5+
6+
use Magento\Framework\Exception\LocalizedException;
7+
8+
interface AdyenThreeDS1ProcessInterface
9+
{
10+
/**
11+
* @param int $orderId
12+
* @param string $md
13+
* @param string $paReq
14+
* @return void
15+
* @throws LocalizedException
16+
*/
17+
public function authorise(int $orderId, string $md, string $paReq): void;
18+
19+
/**
20+
* @param object $payment
21+
* @param string $md
22+
* @param string $paRes
23+
* @return void
24+
*/
25+
public function authorisePayment($payment, string $md, $paRes): void;
26+
}

Api/AdyenThreeDSAbortInterface.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Jh\AdyenPayment\Api;
5+
6+
use Magento\Framework\Exception\LocalizedException;
7+
8+
interface AdyenThreeDSAbortInterface
9+
{
10+
/**
11+
* @param int $orderId
12+
* @return void
13+
* @throws LocalizedException
14+
*/
15+
public function abort(int $orderId): void;
16+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jh\AdyenPayment\Api\Data;
6+
7+
interface RedirectResponseInterface
8+
{
9+
/**
10+
* @return int
11+
*/
12+
public function getOrderId(): int;
13+
14+
/**
15+
* @param int $orderId
16+
* @return void
17+
*/
18+
public function setOrderId(int $orderId): void;
19+
20+
/**
21+
* @return string
22+
*/
23+
public function getRedirectUrl(): string;
24+
25+
/**
26+
* @param string $orderId
27+
* @return void
28+
*/
29+
public function setRedirectUrl(string $redirectUrl): void;
30+
}

Api/Data/ResultResponseInterface.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jh\AdyenPayment\Api\Data;
6+
7+
interface ResultResponseInterface
8+
{
9+
/**
10+
* @return int
11+
*/
12+
public function getOrderId(): int;
13+
14+
/**
15+
* @param int $orderId
16+
* @return void
17+
*/
18+
public function setOrderId(int $orderId): void;
19+
20+
/**
21+
* @return int
22+
*/
23+
public function getQuoteId(): int;
24+
25+
/**
26+
* @param int $quoteId
27+
* @return void
28+
*/
29+
public function setQuoteId(int $quoteId): void;
30+
31+
/**
32+
* @return string
33+
*/
34+
public function getResponse(): string;
35+
36+
/**
37+
* @param string $response
38+
* @return void
39+
*/
40+
public function setResponse(string $response): void;
41+
42+
/**
43+
* @return string
44+
*/
45+
public function getMessage(): string;
46+
47+
/**
48+
* @param string $message
49+
* @return void
50+
*/
51+
public function setMessage(string $message): void;
52+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jh\AdyenPayment\Gateway\Request;
6+
7+
use Adyen\Payment\Gateway\Request\CheckoutDataBuilder as OrigCheckoutDataBuilder;
8+
use Adyen\Payment\Helper\Data;
9+
use Adyen\Payment\Model\Gender;
10+
use Magento\Store\Model\StoreManagerInterface;
11+
use Magento\Quote\Api\CartRepositoryInterface;
12+
13+
class CheckoutDataBuilder extends OrigCheckoutDataBuilder
14+
{
15+
private $adyenHelper;
16+
17+
public function __construct(
18+
Data $adyenHelper,
19+
StoreManagerInterface $storeManager,
20+
CartRepositoryInterface $cartRepository,
21+
Gender $gender
22+
) {
23+
parent::__construct($adyenHelper, $storeManager, $cartRepository, $gender);
24+
25+
$this->adyenHelper = $adyenHelper;
26+
}
27+
28+
public function build(array $buildSubject)
29+
{
30+
$request = parent::build($buildSubject);
31+
32+
$customOrigin = $this->adyenHelper->getAdyenAbstractConfigData('origin_key_domain');
33+
if ($customOrigin) {
34+
$customPath = $this->adyenHelper->getAdyenAbstractConfigData('pwa_return_path');
35+
$path = $customPath ?? 'adyen/process/result';
36+
$request['body']['returnUrl'] = sprintf('%s/%s', $customOrigin, $path);
37+
}
38+
39+
return $request;
40+
}
41+
}

Model/RedirectResponse.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jh\AdyenPayment\Model;
6+
7+
use Jh\AdyenPayment\Api\Data\RedirectResponseInterface;
8+
9+
class RedirectResponse implements RedirectResponseInterface
10+
{
11+
private $orderId;
12+
private $redirectUrl;
13+
14+
public function getOrderId(): int
15+
{
16+
return $this->orderId;
17+
}
18+
19+
public function setOrderId(int $orderId): void
20+
{
21+
$this->orderId = $orderId;
22+
}
23+
24+
public function getRedirectUrl(): string
25+
{
26+
return $this->redirectUrl;
27+
}
28+
29+
public function setRedirectUrl(string $redirectUrl): void
30+
{
31+
$this->redirectUrl = $redirectUrl;
32+
}
33+
}

Model/ResultResponse.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jh\AdyenPayment\Model;
6+
7+
use Jh\AdyenPayment\Api\Data\ResultResponseInterface;
8+
9+
class ResultResponse implements ResultResponseInterface
10+
{
11+
private $orderId;
12+
private $quoteId;
13+
private $response;
14+
private $message;
15+
16+
public function getOrderId(): int
17+
{
18+
return $this->orderId;
19+
}
20+
21+
public function setOrderId(int $orderId): void
22+
{
23+
$this->orderId = $orderId;
24+
}
25+
26+
public function getQuoteId(): int
27+
{
28+
return $this->quoteId;
29+
}
30+
31+
public function setQuoteId(int $quoteId): void
32+
{
33+
$this->quoteId = $quoteId;
34+
}
35+
36+
public function getResponse(): string
37+
{
38+
return $this->response;
39+
}
40+
41+
public function setResponse(string $response): void
42+
{
43+
$this->response = $response;
44+
}
45+
46+
public function getMessage(): string
47+
{
48+
return $this->message;
49+
}
50+
51+
public function setMessage(string $message): void
52+
{
53+
$this->message = $message;
54+
}
55+
}

Plugin/CustomOriginPlugin.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jh\AdyenPayment\Plugin;
6+
7+
use Adyen\Payment\Helper\Data as Subject;
8+
9+
class CustomOriginPlugin
10+
{
11+
public function aroundGetOrigin(Subject $subject, callable $proceed)
12+
{
13+
if ($customOrigin = $subject->getAdyenAbstractConfigData('origin_key_domain')) {
14+
return $customOrigin;
15+
}
16+
return $proceed();
17+
}
18+
}

Plugin/ThreeDS1RedirectPlugin.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jh\AdyenPayment\Plugin;
6+
7+
use Adyen\Payment\Model\AdyenOrderPaymentStatus;
8+
use Adyen\Payment\Model\Ui\AdyenCcConfigProvider;
9+
use Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider;
10+
use Magento\Sales\Api\OrderRepositoryInterface;
11+
12+
class ThreeDS1RedirectPlugin
13+
{
14+
private $orderRepository;
15+
16+
public function __construct(OrderRepositoryInterface $orderRepository)
17+
{
18+
$this->orderRepository = $orderRepository;
19+
}
20+
21+
public function afterGetOrderPaymentStatus(AdyenOrderPaymentStatus $adyenOrderPaymentStatus, $response, $orderId)
22+
{
23+
if (!is_string($response)) {
24+
return $response;
25+
}
26+
27+
$payment = $this->orderRepository->get($orderId)->getPayment();
28+
29+
if ($payment->getMethod() === AdyenCcConfigProvider::CODE ||
30+
$payment->getMethod() === AdyenOneclickConfigProvider::CODE
31+
) {
32+
$response = json_decode($response, true);
33+
34+
if (($response['threeDS2'] ?? false) === false && ($response['type'] ?? '') === 'RedirectShopper') {
35+
$additionalInformation = $payment->getAdditionalInformation();
36+
37+
$response = array_merge($response, [
38+
'redirect' => [
39+
'data' => [
40+
'PaReq' => $additionalInformation['paRequest'] ?? null,
41+
'MD' => $additionalInformation['md'] ?? null,
42+
'TermUrl' => null
43+
],
44+
'method' => $additionalInformation['redirectMethod'] ?? 'POST',
45+
'url' => $additionalInformation['redirectUrl'] ?? null
46+
]
47+
]);
48+
}
49+
50+
return json_encode($response);
51+
}
52+
53+
return $response;
54+
}
55+
}

0 commit comments

Comments
 (0)