Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PAYSHIP-3020] Added negative testing headers #1272

Open
wants to merge 1 commit into
base: prestashop/8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/http-clients.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
public: true
arguments:
- "@ps_checkout.http.client"
- '@PrestaShop\Module\PrestashopCheckout\Configuration\PrestaShopConfiguration'

PrestaShop\Module\PrestashopCheckout\Http\CheckoutHttpClient:
class: 'PrestaShop\Module\PrestashopCheckout\Http\CheckoutHttpClient'
Expand Down
58 changes: 40 additions & 18 deletions src/Http/MaaslandHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Http\Client\Exception\NetworkException;
use Http\Client\Exception\RequestException;
use Http\Client\Exception\TransferException;
use PrestaShop\Module\PrestashopCheckout\Configuration\PrestaShopConfiguration;
use PrestaShop\Module\PrestashopCheckout\Exception\HttpTimeoutException;
use PrestaShop\Module\PrestashopCheckout\Exception\PayPalException;
use PrestaShop\Module\PrestashopCheckout\PayPalError;
Expand All @@ -37,15 +38,20 @@ class MaaslandHttpClient implements HttpClientInterface
* @var HttpClientInterface
*/
private $httpClient;
/**
* @var PrestaShopConfiguration
*/
private $configuration;

public function __construct(HttpClientInterface $httpClient)
public function __construct(HttpClientInterface $httpClient, PrestaShopConfiguration $configuration)
{
$this->httpClient = $httpClient;
$this->configuration = $configuration;
}

/**
* @param array $payload
* @param array $options
* @param array $headers
*
* @return ResponseInterface
*
Expand All @@ -56,14 +62,18 @@ public function __construct(HttpClientInterface $httpClient)
* @throws PayPalException
* @throws HttpTimeoutException
*/
public function createOrder(array $payload, array $options = [])
public function createOrder(array $payload, array $headers = [])
{
return $this->sendRequest(new Request('POST', '/payments/order/create', $options, json_encode($payload)));
if ($ntHeader = $this->configuration->get('PS_CHECKOUT_NT_CREATE_ORDER')) {
$headers['NT-PayPalOrderCreate'] = $ntHeader;
}

return $this->sendRequest(new Request('POST', '/payments/order/create', $headers, json_encode($payload)));
}

/**
* @param array $payload
* @param array $options
* @param array $headers
*
* @return ResponseInterface
*
Expand All @@ -74,14 +84,18 @@ public function createOrder(array $payload, array $options = [])
* @throws PayPalException
* @throws HttpTimeoutException
*/
public function updateOrder(array $payload, array $options = [])
public function updateOrder(array $payload, array $headers = [])
{
return $this->sendRequest(new Request('POST', '/payments/order/update', $options, json_encode($payload)));
if ($ntHeader = $this->configuration->get('PS_CHECKOUT_NT_UPDATE_ORDER')) {
$headers['NT-PayPalOrderUpdate'] = $ntHeader;
}

return $this->sendRequest(new Request('POST', '/payments/order/update', $headers, json_encode($payload)));
}

/**
* @param array $payload
* @param array $options
* @param array $headers
*
* @return ResponseInterface
*
Expand All @@ -92,14 +106,18 @@ public function updateOrder(array $payload, array $options = [])
* @throws PayPalException
* @throws HttpTimeoutException
*/
public function fetchOrder(array $payload, array $options = [])
public function fetchOrder(array $payload, array $headers = [])
{
return $this->sendRequest(new Request('POST', '/payments/order/fetch', $options, json_encode($payload)));
if ($ntHeader = $this->configuration->get('PS_CHECKOUT_NT_FETCH_ORDER')) {
$headers['NT-PayPalOrderFetch'] = $ntHeader;
}

return $this->sendRequest(new Request('POST', '/payments/order/fetch', $headers, json_encode($payload)));
}

/**
* @param array $payload
* @param array $options
* @param array $headers
*
* @return ResponseInterface
*
Expand All @@ -110,14 +128,18 @@ public function fetchOrder(array $payload, array $options = [])
* @throws PayPalException
* @throws HttpTimeoutException
*/
public function captureOrder(array $payload, array $options = [])
public function captureOrder(array $payload, array $headers = [])
{
return $this->sendRequest(new Request('POST', '/payments/order/capture', $options, json_encode($payload)));
if ($ntHeader = $this->configuration->get('PS_CHECKOUT_NT_CAPTURE_ORDER')) {
$headers['NT-PayPalOrderCapture'] = $ntHeader;
}

return $this->sendRequest(new Request('POST', '/payments/order/capture', $headers, json_encode($payload)));
}

/**
* @param array $payload
* @param array $options
* @param array $headers
*
* @return ResponseInterface
*
Expand All @@ -128,9 +150,9 @@ public function captureOrder(array $payload, array $options = [])
* @throws PayPalException
* @throws HttpTimeoutException
*/
public function refundOrder(array $payload, array $options = [])
public function refundOrder(array $payload, array $headers = [])
{
return $this->sendRequest(new Request('POST', '/payments/order/refund', $options, json_encode($payload)));
return $this->sendRequest(new Request('POST', '/payments/order/refund', $headers, json_encode($payload)));
}

/**
Expand Down Expand Up @@ -202,9 +224,9 @@ private function extractMessage(array $body)
*
* @return array
*/
public function getShopSignature(array $payload, array $options = [])
public function getShopSignature(array $payload, array $headers = [])
{
$response = $this->sendRequest(new Request('POST', '/payments/shop/verify_webhook_signature', $options, json_encode($payload)));
$response = $this->sendRequest(new Request('POST', '/payments/shop/verify_webhook_signature', $headers, json_encode($payload)));

return json_decode($response->getBody(), true);
}
Expand Down