-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathTransactionCancel.php
More file actions
99 lines (88 loc) · 3.03 KB
/
TransactionCancel.php
File metadata and controls
99 lines (88 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2023 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Gateway\Http\Client;
use Adyen\AdyenException;
use Adyen\Client;
use Adyen\Model\Checkout\PaymentCancelRequest;
use Adyen\Payment\Helper\Data;
use Adyen\Payment\Helper\Idempotency;
use Adyen\Payment\Helper\PlatformInfo;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Payment\Gateway\Http\ClientInterface;
use Magento\Payment\Gateway\Http\TransferInterface;
class TransactionCancel implements ClientInterface
{
/**
* @var Data
*/
private Data $adyenHelper;
/**
* @var Idempotency
*/
private Idempotency $idempotencyHelper;
/**
* @var PlatformInfo
*/
private PlatformInfo $platformInfo;
/**
* @param Data $adyenHelper
* @param Idempotency $idempotencyHelper
* @param PlatformInfo $platformInfo
*/
public function __construct(
Data $adyenHelper,
Idempotency $idempotencyHelper,
PlatformInfo $platformInfo
) {
$this->adyenHelper = $adyenHelper;
$this->idempotencyHelper = $idempotencyHelper;
$this->platformInfo = $platformInfo;
}
/**
* @param TransferInterface $transferObject
* @return array
* @throws AdyenException
* @throws NoSuchEntityException
*/
public function placeRequest(TransferInterface $transferObject): array
{
$requests = $transferObject->getBody();
$headers = $transferObject->getHeaders();
$clientConfig = $transferObject->getClientConfig();
$client = $this->adyenHelper->initializeAdyenClientWithClientConfig($clientConfig);
$service = $this->adyenHelper->initializeModificationsApi($client);
$responseData = [];
foreach ($requests as $request) {
$idempotencyKey = $this->idempotencyHelper->generateIdempotencyKey(
$request,
$headers['idempotencyExtraData'] ?? null
);
$requestOptions['idempotencyKey'] = $idempotencyKey;
$requestOptions['headers'] = $headers;
$this->adyenHelper->logRequest($request, Client::API_CHECKOUT_VERSION, '/cancels');
$request['applicationInfo'] = $this->platformInfo->buildApplicationInfo($client);
$paymentCancelRequest = new PaymentCancelRequest($request);
try {
$response = $service->cancelAuthorisedPaymentByPspReference(
$request['paymentPspReference'],
$paymentCancelRequest,
$requestOptions
);
$responseData = $response->toArray();
$this->adyenHelper->logResponse($responseData);
} catch (AdyenException $e) {
$responseData['error'] = $e->getMessage();
$this->adyenHelper->logAdyenException($e);
}
}
return $responseData;
}
}