mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-23 02:56:02 +02:00
Security updates for Adyen module
This commit is contained in:
parent
3884f480ad
commit
6ba1fe92d5
2 changed files with 23 additions and 1 deletions
|
@ -382,6 +382,25 @@ class FinancialsController extends Controller
|
|||
$data = json_decode($request->getBody()->getContents(), true);
|
||||
$db = $this->container->get('db');
|
||||
|
||||
// Basic auth credentials
|
||||
$username = envi('ADYEN_BASIC_AUTH_USER');
|
||||
$password = envi('ADYEN_BASIC_AUTH_PASS');
|
||||
|
||||
// Check for basic auth header
|
||||
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
||||
return $response->withStatus(401)->withHeader('WWW-Authenticate', 'Basic realm="MyRealm"');
|
||||
}
|
||||
|
||||
// Validate username and password
|
||||
if ($_SERVER['PHP_AUTH_USER'] != $username || $_SERVER['PHP_AUTH_PW'] != $password) {
|
||||
$response = $response->withStatus(403)->withHeader('Content-Type', 'application/json');
|
||||
$response->getBody()->write(json_encode(['forbidden' => true]));
|
||||
return $response;
|
||||
}
|
||||
|
||||
$hmac = new \Adyen\Util\HmacSignature();
|
||||
$hmacKey = envi('ADYEN_HMAC_KEY');
|
||||
|
||||
foreach ($data['notificationItems'] as $item) {
|
||||
$notificationRequestItem = $item['NotificationRequestItem'];
|
||||
|
||||
|
@ -389,7 +408,7 @@ class FinancialsController extends Controller
|
|||
$merchantReference = $notificationRequestItem['merchantReference'] ?? null;
|
||||
$paymentStatus = $notificationRequestItem['success'] ?? null;
|
||||
|
||||
if ($merchantReference && $paymentStatus) {
|
||||
if ($merchantReference && $paymentStatus && $hmac->isValidNotificationHMAC($hmacKey, $notificationRequestItem)) {
|
||||
try {
|
||||
$amountPaid = $notificationRequestItem['amount']['value']; // Amount paid, in cents
|
||||
$amount = $amountPaid / 100;
|
||||
|
|
|
@ -31,5 +31,8 @@ ADYEN_API_KEY='adyen-api-key'
|
|||
ADYEN_MERCHANT_ID='adyen-merchant-id'
|
||||
ADYEN_THEME_ID='adyen-theme-id'
|
||||
ADYEN_BASE_URI='https://checkout-test.adyen.com/v70/'
|
||||
ADYEN_BASIC_AUTH_USER='adyen-basic-auth-user'
|
||||
ADYEN_BASIC_AUTH_PASS='adyen-basic-auth-pass'
|
||||
ADYEN_HMAC_KEY='adyen-hmac-key'
|
||||
|
||||
TEST_TLDS=.test,.com.test
|
Loading…
Add table
Add a link
Reference in a new issue