Skip to content
Merged
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
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,11 @@ L5_SWAGGER_CONST_TOKEN_URL=${IDP_TOKEN_ENDPOINT}

MEMCACHED_SERVER_HOST=127.0.0.1
MEMCACHED_SERVER_PORT=11211

# PAYMENT SERVICE

PAYMENTS_SERVICE_BASE_URL=
# CLIENT SHOULD BE CONFIGURED with SECRET POST at IDP
PAYMENTS_SERVICE_OAUTH2_CLIENT_ID=
PAYMENTS_SERVICE_OAUTH2_CLIENT_SECRET=
PAYMENTS_SERVICE_OAUTH2_SCOPES=payment-profile/read
114 changes: 114 additions & 0 deletions app/Console/Commands/SetupPaymentServiceMessageBrokerCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php namespace App\Console\Commands;
/*
* Copyright 2025 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Jobs\Payments\EventTypes;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use PhpAmqpLib\Connection\AMQPStreamConnection;

/**
* Class SetupSponsorServiceMessageBrokerCommand
* @package App\Console\Commands
*/
final class SetupPaymentServiceMessageBrokerCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = "setup_payment_service_message_broker";

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = "mq:setup_payment_service_message_broker {exchange_name} {exchange_type}";

/**
* The console command description.
*
* @var string
*/
protected $description = "Set up Payment Service rabbitmq exchange, queue and bindings";

/**
* Execute the console command.
*
* @return void
*/
public function handle(): void
{
$host_settings_path = "queue.connections.message_broker.hosts.0";
$queue_settings_path = "queue.connections.payments_sync_consumer";
$host_settings = Config::get($host_settings_path);

$exchange_name = $this->argument('exchange_name');

if (empty($exchange_name))
throw new \InvalidArgumentException("exchange_name is required");

$exchange_type = $this->argument('exchange_type');

if (empty($exchange_type))
throw new \InvalidArgumentException("exchange_type is required");

if (!$host_settings) {
throw new \InvalidArgumentException("Host setting not found at {$host_settings_path}");
}
$queue_settings = Config::get($queue_settings_path);

$host = $host_settings['host'];
$port = $host_settings['port'];
$user = $host_settings['user'];
$password = $host_settings['password'];
$vhost = $host_settings['vhost'];

$queue = $queue_settings['queue'];

$routingKeys = [
EventTypes::PAYMENT_PROFILE_UPDATED,
EventTypes::PAYMENT_PROFILE_CREATED,
EventTypes::PAYMENT_PROFILE_DELETED,
];

try {
$connection = new AMQPStreamConnection($host, $port, $user, $password, $vhost);
$channel = $connection->channel();

// Exchange
$channel->exchange_declare($exchange_name, $exchange_type, false, true, false);

// Queue
$channel->queue_declare($queue, false, true, false, false);

// Bindings
foreach ($routingKeys as $key) {
$channel->queue_bind($queue, $exchange_name, $key);
echo "Binding created: $queue ← $exchange_name ($key)\n";
}

$channel->close();
$connection->close();
echo "Done.\n";

} catch (Exception $ex) {
echo "Error: " . $ex->getMessage() . "\n";
Log::error($ex);
exit(1);
}
}
}
3 changes: 2 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Kernel extends ConsoleKernel
\App\Console\Commands\PurgeSummitsMarkAsDeletedCommand::class,
\App\Console\Commands\IngestSummitOrderPaymentInfoCommand::class,
\App\Console\Commands\SetupSponsorServiceMessageBrokerCommand::class,
\App\Console\Commands\SetupPaymentServiceMessageBrokerCommand::class,
];

/**
Expand Down Expand Up @@ -112,4 +113,4 @@ protected function schedule(Schedule $schedule)
$schedule->command('summit:registration-orders-payment-info-ingest')->everySixHours()->withoutOverlapping()->onOneServer();

}
}
}
85 changes: 85 additions & 0 deletions app/Jobs/Payments/CreatePaymentProfileMQJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php namespace App\Jobs\Payments;
/*
* Copyright 2025 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use App\Services\Apis\IPaymentsApi;
use App\Services\Model\Imp\PaymentGatewayProfileService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use models\summit\IPaymentConstants;
use models\summit\ISummitRepository;
use models\summit\Summit;

class CreatePaymentProfileMQJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public int $tries = 3;

private PaymentGatewayProfileService $service;

private IPaymentsApi $payments_api;

private ISummitRepository $summit_repository;


/**
* @param ISummitRepository $summit_repository
* @param PaymentGatewayProfileService $service
* @param IPaymentsApi $payments_api
*/
public function __construct
(
ISummitRepository $summit_repository,
PaymentGatewayProfileService $service,
IPaymentsApi $payments_api
){
$this->summit_repository = $summit_repository;
$this->service = $service;
$this->payments_api = $payments_api;
}

public function handle(PaymentsMQJob $job): void{
try {
$payload = $job->payload();
$json = json_encode($payload);
Log::debug("CreatePaymentProfileMQJob::handle", ['payload' => $json ]);
$data = $payload['data'];
$id = intval($data['id']);
$summit_id = intval($data['summit_id']);
$application_type = $data['application_type'];
if(!in_array($application_type, IPaymentConstants::ValidApplicationTypes)){
Log::warning("CreatePaymentProfileMQJob::handle Application Type $application_type is not valid.");
return;
}
$response = $this->payments_api->getPaymentProfile($summit_id, $id);
Log::debug("CreatePaymentProfileMQJob::handle", ['response' => $response]);
$summit = $this->summit_repository->getById($summit_id);
if($summit instanceof Summit) {
// mappings
$response['external_id'] = $id;
$response['active'] = $response['is_active'] ?? false;
Log::debug("CreatePaymentProfileMQJob::handle creating payment profile", ['response' => $response ]);
$this->service->addPaymentProfile($summit, $response);
}
$job->delete();
} catch (\Exception $ex) {
Log::error($ex);
throw $ex;
}
}
}
82 changes: 82 additions & 0 deletions app/Jobs/Payments/DeletePaymentProfileMQJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php namespace App\Jobs\Payments;
/*
* Copyright 2025 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use App\Models\Foundation\Summit\Repositories\IPaymentGatewayProfileRepository;
use App\Services\Model\Imp\PaymentGatewayProfileService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use models\summit\IPaymentConstants;
use models\summit\ISummitRepository;
use models\summit\PaymentGatewayProfile;
use models\summit\Summit;

class DeletePaymentProfileMQJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public int $tries = 3;

private PaymentGatewayProfileService $service;

private ISummitRepository $summit_repository;

private IPaymentGatewayProfileRepository $payment_gateway_profile_repository;

public function __construct
(
ISummitRepository $summit_repository,
IPaymentGatewayProfileRepository $payment_gateway_profile_repository,
PaymentGatewayProfileService $service
){
$this->summit_repository = $summit_repository;
$this->payment_gateway_profile_repository = $payment_gateway_profile_repository;
$this->service = $service;
}

public function handle(PaymentsMQJob $job): void{
try {
$payload = $job->payload();
$json = json_encode($payload);
Log::debug("DeletePaymentProfileMQJob::handle", ['payload' => $json ]);

$data = $payload['data'];

$id = intval($data['id']);
$summit_id = intval($data['summit_id']);
$application_type = $data['application_type'];
if(!in_array($application_type, IPaymentConstants::ValidApplicationTypes)){
Log::warning("DeletePaymentProfileMQJob::handle Application Type $application_type is not valid.");
return;
}

$summit = $this->summit_repository->getById($summit_id);
$local_payment_profile = $this->payment_gateway_profile_repository->getByExternalId($id);

if($summit instanceof Summit && $local_payment_profile instanceof PaymentGatewayProfile){
$local_payment_profile_id = $local_payment_profile->getId();
Log::warning("DeletePaymentProfileMQJob::handle deleting payment profile", ['local_payment_profile_id' => $local_payment_profile_id ]);
$this->service->deletePaymentProfile($summit, $local_payment_profile_id);
}
$job->delete();
} catch (\Exception $ex) {
Log::error($ex);
throw $ex;
}
}
}

24 changes: 24 additions & 0 deletions app/Jobs/Payments/EventTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php namespace App\Jobs\Payments;
/*
* Copyright 2025 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

/**
* Class EventTypes
* @package App\Jobs\SponsorServices
*/
final class EventTypes
{
const string PAYMENT_PROFILE_CREATED = 'payment_profile_created';
const string PAYMENT_PROFILE_UPDATED = 'payment_profile_updated';
const string PAYMENT_PROFILE_DELETED = 'payment_profile_deleted';
}
50 changes: 50 additions & 0 deletions app/Jobs/Payments/PaymentsMQJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php namespace App\Jobs\Payments;
/**
* Copyright 2025 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use Illuminate\Support\Facades\Log;
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob as BaseJob;

class PaymentsMQJob extends BaseJob
{
public int $tries = 1;

/**
* Get the decoded body of the job.
*
* @return array
*/
public function payload(): array
{
$routing_key = $this->getRabbitMQMessage()->getRoutingKey();
Log::debug("PaymentsMQJob::payload processing job", ['routing_key' => $routing_key]);
switch ($routing_key) {
case EventTypes::PAYMENT_PROFILE_CREATED:
$job = 'App\Jobs\Payments\CreatePaymentProfileMQJob@handle';
break;
case EventTypes::PAYMENT_PROFILE_UPDATED:
$job = 'App\Jobs\Payments\UpdatePaymentProfileMQJob@handle';
break;
case EventTypes::PAYMENT_PROFILE_DELETED:
$job = 'App\Jobs\Payments\DeletePaymentProfileMQJob@handle';
break;
default:
Log::warning('Received an unknown routing key', ['routing_key' => $routing_key, 'message' => $this->getRawBody()]);
return [];
}
return [
'job' => $job,
'data' => json_decode($this->getRawBody(), true)
];
}
}
Loading