mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-22 00:50:54 +02:00
Added basic registrar deposit support for Adyen
This commit is contained in:
parent
94e0f2a445
commit
3884f480ad
3 changed files with 113 additions and 1 deletions
|
@ -8,6 +8,7 @@ use Psr\Container\ContainerInterface;
|
||||||
use Mpociot\VatCalculator\VatCalculator;
|
use Mpociot\VatCalculator\VatCalculator;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
|
use Ramsey\Uuid\Uuid;
|
||||||
|
|
||||||
class FinancialsController extends Controller
|
class FinancialsController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -233,6 +234,14 @@ class FinancialsController extends Controller
|
||||||
// Convert amount to cents
|
// Convert amount to cents
|
||||||
$amountInCents = $amount * 100;
|
$amountInCents = $amount * 100;
|
||||||
|
|
||||||
|
// Your registrar ID and unique identifier
|
||||||
|
$registrarId = $_SESSION['auth_registrar_id'];
|
||||||
|
$uniqueIdentifier = Uuid::uuid4()->toString(); // Generates a unique UUID
|
||||||
|
|
||||||
|
$delimiter = '|';
|
||||||
|
$combinedString = $registrarId . $delimiter . $uniqueIdentifier;
|
||||||
|
$merchantReference = bin2hex($combinedString);
|
||||||
|
|
||||||
$client = new \Adyen\Client();
|
$client = new \Adyen\Client();
|
||||||
$client->setApplicationName('Namingo');
|
$client->setApplicationName('Namingo');
|
||||||
$client->setEnvironment(\Adyen\Environment::TEST);
|
$client->setEnvironment(\Adyen\Environment::TEST);
|
||||||
|
@ -244,7 +253,7 @@ class FinancialsController extends Controller
|
||||||
'value' => $amountInCents
|
'value' => $amountInCents
|
||||||
),
|
),
|
||||||
'merchantAccount' => envi('ADYEN_MERCHANT_ID'),
|
'merchantAccount' => envi('ADYEN_MERCHANT_ID'),
|
||||||
'reference' => 'Registrar Balance Deposit',
|
'reference' => $merchantReference,
|
||||||
'returnUrl' => envi('APP_URL').'/payment-success-adyen',
|
'returnUrl' => envi('APP_URL').'/payment-success-adyen',
|
||||||
'mode' => 'hosted',
|
'mode' => 'hosted',
|
||||||
'themeId' => envi('ADYEN_THEME_ID')
|
'themeId' => envi('ADYEN_THEME_ID')
|
||||||
|
@ -368,6 +377,102 @@ class FinancialsController extends Controller
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function webhookAdyen(Request $request, Response $response)
|
||||||
|
{
|
||||||
|
$data = json_decode($request->getBody()->getContents(), true);
|
||||||
|
$db = $this->container->get('db');
|
||||||
|
|
||||||
|
foreach ($data['notificationItems'] as $item) {
|
||||||
|
$notificationRequestItem = $item['NotificationRequestItem'];
|
||||||
|
|
||||||
|
if (isset($notificationRequestItem['eventCode']) && $notificationRequestItem['eventCode'] == 'AUTHORISATION' && $notificationRequestItem['success'] == 'true') {
|
||||||
|
$merchantReference = $notificationRequestItem['merchantReference'] ?? null;
|
||||||
|
$paymentStatus = $notificationRequestItem['success'] ?? null;
|
||||||
|
|
||||||
|
if ($merchantReference && $paymentStatus) {
|
||||||
|
try {
|
||||||
|
$amountPaid = $notificationRequestItem['amount']['value']; // Amount paid, in cents
|
||||||
|
$amount = $amountPaid / 100;
|
||||||
|
$amountPaidFormatted = number_format($amount, 2, '.', '');
|
||||||
|
$paymentIntentId = $notificationRequestItem['reason'];
|
||||||
|
$merchantReference = hex2bin($merchantReference);
|
||||||
|
$delimiter = '|';
|
||||||
|
|
||||||
|
// Split to get the original components
|
||||||
|
list($registrarId, $uniqueIdentifier) = explode($delimiter, $merchantReference, 2);
|
||||||
|
|
||||||
|
$isPositiveNumberWithTwoDecimals = filter_var($amount, FILTER_VALIDATE_FLOAT) !== false && preg_match('/^\d+(\.\d{1,2})?$/', $amount);
|
||||||
|
|
||||||
|
if ($isPositiveNumberWithTwoDecimals) {
|
||||||
|
$db->beginTransaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$currentDateTime = new \DateTime();
|
||||||
|
$date = $currentDateTime->format('Y-m-d H:i:s.v');
|
||||||
|
$db->insert(
|
||||||
|
'statement',
|
||||||
|
[
|
||||||
|
'registrar_id' => $registrarId,
|
||||||
|
'date' => $date,
|
||||||
|
'command' => 'create',
|
||||||
|
'domain_name' => 'deposit',
|
||||||
|
'length_in_months' => 0,
|
||||||
|
'fromS' => $date,
|
||||||
|
'toS' => $date,
|
||||||
|
'amount' => $amount
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$db->insert(
|
||||||
|
'payment_history',
|
||||||
|
[
|
||||||
|
'registrar_id' => $registrarId,
|
||||||
|
'date' => $date,
|
||||||
|
'description' => 'registrar balance deposit via Adyen ('.$paymentIntentId.')',
|
||||||
|
'amount' => $amount
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$db->exec(
|
||||||
|
'UPDATE registrar SET accountBalance = (accountBalance + ?) WHERE id = ?',
|
||||||
|
[
|
||||||
|
$amount,
|
||||||
|
$registrarId,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$db->commit();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$response = $response->withStatus(500)->withHeader('Content-Type', 'application/json');
|
||||||
|
$response->getBody()->write(json_encode(['failure' => true]));
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response->getBody()->write(json_encode(['received' => true]));
|
||||||
|
return $response->withHeader('Content-Type', 'application/json');
|
||||||
|
} else {
|
||||||
|
$response = $response->withStatus(500)->withHeader('Content-Type', 'application/json');
|
||||||
|
$response->getBody()->write(json_encode(['failure' => true]));
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$response = $response->withStatus(500)->withHeader('Content-Type', 'application/json');
|
||||||
|
$response->getBody()->write(json_encode(['failure' => true]));
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response = $response->withStatus(500)->withHeader('Content-Type', 'application/json');
|
||||||
|
$response->getBody()->write(json_encode(['failure' => true]));
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $response->withStatus(500)->withHeader('Content-Type', 'application/json');
|
||||||
|
$response->getBody()->write(json_encode(['failure' => true]));
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
public function cancel(Request $request, Response $response)
|
public function cancel(Request $request, Response $response)
|
||||||
{
|
{
|
||||||
return view($response,'admin/financials/cancel.twig');
|
return view($response,'admin/financials/cancel.twig');
|
||||||
|
|
|
@ -231,6 +231,12 @@ $csrfMiddleware = function ($request, $handler) use ($container) {
|
||||||
if ($path && $path === '/application/deletehost') {
|
if ($path && $path === '/application/deletehost') {
|
||||||
return $handler->handle($request);
|
return $handler->handle($request);
|
||||||
}
|
}
|
||||||
|
if ($path && $path === '/webhook/adyen') {
|
||||||
|
return $handler->handle($request);
|
||||||
|
}
|
||||||
|
if ($path && $path === '/create-adyen-payment') {
|
||||||
|
return $handler->handle($request);
|
||||||
|
}
|
||||||
|
|
||||||
// If not skipped, apply the CSRF Guard
|
// If not skipped, apply the CSRF Guard
|
||||||
return $csrf->process($request, $handler);
|
return $csrf->process($request, $handler);
|
||||||
|
|
|
@ -34,6 +34,7 @@ $app->group('', function ($route) {
|
||||||
$route->get('/reset-password', PasswordController::class.':resetPassword')->setName('reset.password');
|
$route->get('/reset-password', PasswordController::class.':resetPassword')->setName('reset.password');
|
||||||
$route->get('/update-password', PasswordController::class.':createUpdatePassword')->setName('update.password');
|
$route->get('/update-password', PasswordController::class.':createUpdatePassword')->setName('update.password');
|
||||||
$route->post('/update-password', PasswordController::class.':updatePassword');
|
$route->post('/update-password', PasswordController::class.':updatePassword');
|
||||||
|
$route->post('/webhook/adyen', FinancialsController::class .':webhookAdyen')->setName('webhookAdyen');
|
||||||
})->add(new GuestMiddleware($container));
|
})->add(new GuestMiddleware($container));
|
||||||
|
|
||||||
$app->group('', function ($route) {
|
$app->group('', function ($route) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue