Skip to content

Commit 73f8817

Browse files
committed
Added negative testing headers
1 parent e556f20 commit 73f8817

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

src/Http/MaaslandHttpClient.php

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Http\Client\Exception\NetworkException;
2626
use Http\Client\Exception\RequestException;
2727
use Http\Client\Exception\TransferException;
28+
use PrestaShop\Module\PrestashopCheckout\Configuration\PrestaShopConfiguration;
2829
use PrestaShop\Module\PrestashopCheckout\Exception\HttpTimeoutException;
2930
use PrestaShop\Module\PrestashopCheckout\Exception\PayPalException;
3031
use PrestaShop\Module\PrestashopCheckout\PayPalError;
@@ -37,15 +38,20 @@ class MaaslandHttpClient implements HttpClientInterface
3738
* @var HttpClientInterface
3839
*/
3940
private $httpClient;
41+
/**
42+
* @var PrestaShopConfiguration
43+
*/
44+
private $configuration;
4045

41-
public function __construct(HttpClientInterface $httpClient)
46+
public function __construct(HttpClientInterface $httpClient, PrestaShopConfiguration $configuration)
4247
{
4348
$this->httpClient = $httpClient;
49+
$this->configuration = $configuration;
4450
}
4551

4652
/**
4753
* @param array $payload
48-
* @param array $options
54+
* @param array $headers
4955
*
5056
* @return ResponseInterface
5157
*
@@ -56,14 +62,18 @@ public function __construct(HttpClientInterface $httpClient)
5662
* @throws PayPalException
5763
* @throws HttpTimeoutException
5864
*/
59-
public function createOrder(array $payload, array $options = [])
65+
public function createOrder(array $payload, array $headers = [])
6066
{
61-
return $this->sendRequest(new Request('POST', '/payments/order/create', $options, json_encode($payload)));
67+
if ($ntHeader = $this->configuration->get('PS_CHECKOUT_NT_CREATE_ORDER')) {
68+
$headers['NT-PayPalOrderCreate'] = $ntHeader;
69+
}
70+
71+
return $this->sendRequest(new Request('POST', '/payments/order/create', $headers, json_encode($payload)));
6272
}
6373

6474
/**
6575
* @param array $payload
66-
* @param array $options
76+
* @param array $headers
6777
*
6878
* @return ResponseInterface
6979
*
@@ -74,14 +84,18 @@ public function createOrder(array $payload, array $options = [])
7484
* @throws PayPalException
7585
* @throws HttpTimeoutException
7686
*/
77-
public function updateOrder(array $payload, array $options = [])
87+
public function updateOrder(array $payload, array $headers = [])
7888
{
79-
return $this->sendRequest(new Request('POST', '/payments/order/update', $options, json_encode($payload)));
89+
if ($ntHeader = $this->configuration->get('PS_CHECKOUT_NT_UPDATE_ORDER')) {
90+
$headers['NT-PayPalOrderUpdate'] = $ntHeader;
91+
}
92+
93+
return $this->sendRequest(new Request('POST', '/payments/order/update', $headers, json_encode($payload)));
8094
}
8195

8296
/**
8397
* @param array $payload
84-
* @param array $options
98+
* @param array $headers
8599
*
86100
* @return ResponseInterface
87101
*
@@ -92,14 +106,18 @@ public function updateOrder(array $payload, array $options = [])
92106
* @throws PayPalException
93107
* @throws HttpTimeoutException
94108
*/
95-
public function fetchOrder(array $payload, array $options = [])
109+
public function fetchOrder(array $payload, array $headers = [])
96110
{
97-
return $this->sendRequest(new Request('POST', '/payments/order/fetch', $options, json_encode($payload)));
111+
if ($ntHeader = $this->configuration->get('PS_CHECKOUT_NT_FETCH_ORDER')) {
112+
$headers['NT-PayPalOrderFetch'] = $ntHeader;
113+
}
114+
115+
return $this->sendRequest(new Request('POST', '/payments/order/fetch', $headers, json_encode($payload)));
98116
}
99117

100118
/**
101119
* @param array $payload
102-
* @param array $options
120+
* @param array $headers
103121
*
104122
* @return ResponseInterface
105123
*
@@ -110,14 +128,18 @@ public function fetchOrder(array $payload, array $options = [])
110128
* @throws PayPalException
111129
* @throws HttpTimeoutException
112130
*/
113-
public function captureOrder(array $payload, array $options = [])
131+
public function captureOrder(array $payload, array $headers = [])
114132
{
115-
return $this->sendRequest(new Request('POST', '/payments/order/capture', $options, json_encode($payload)));
133+
if ($ntHeader = $this->configuration->get('PS_CHECKOUT_NT_CAPTURE_ORDER')) {
134+
$headers['NT-PayPalOrderCapture'] = $ntHeader;
135+
}
136+
137+
return $this->sendRequest(new Request('POST', '/payments/order/capture', $headers, json_encode($payload)));
116138
}
117139

118140
/**
119141
* @param array $payload
120-
* @param array $options
142+
* @param array $headers
121143
*
122144
* @return ResponseInterface
123145
*
@@ -128,9 +150,9 @@ public function captureOrder(array $payload, array $options = [])
128150
* @throws PayPalException
129151
* @throws HttpTimeoutException
130152
*/
131-
public function refundOrder(array $payload, array $options = [])
153+
public function refundOrder(array $payload, array $headers = [])
132154
{
133-
return $this->sendRequest(new Request('POST', '/payments/order/refund', $options, json_encode($payload)));
155+
return $this->sendRequest(new Request('POST', '/payments/order/refund', $headers, json_encode($payload)));
134156
}
135157

136158
/**
@@ -202,9 +224,9 @@ private function extractMessage(array $body)
202224
*
203225
* @return array
204226
*/
205-
public function getShopSignature(array $payload, array $options = [])
227+
public function getShopSignature(array $payload, array $headers = [])
206228
{
207-
$response = $this->sendRequest(new Request('POST', '/payments/shop/verify_webhook_signature', $options, json_encode($payload)));
229+
$response = $this->sendRequest(new Request('POST', '/payments/shop/verify_webhook_signature', $headers, json_encode($payload)));
208230

209231
return json_decode($response->getBody(), true);
210232
}

0 commit comments

Comments
 (0)