73 lines
2.6 KiB
PHP
73 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Payments;
|
|
|
|
use App\Enums\PaymentStatusEnum;
|
|
use App\Models\FibTransaction;
|
|
use App\Models\Payment;
|
|
use App\Models\Transaction;
|
|
use App\Services\FIB\FIBClient;
|
|
use App\Services\Payments\DTO\FIBPaymentCreateDTO;
|
|
use App\Services\Payments\DTO\PaymentCreateDTO;
|
|
|
|
class PaymentService
|
|
{
|
|
public $fib_client;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->fib_client = new FibClient();
|
|
}
|
|
|
|
public function createPayment(PaymentCreateDTO $dto)
|
|
{
|
|
try {
|
|
$payment = Payment::query()->create([
|
|
'user_id' => $dto->user_id,
|
|
'username' => $dto->username,
|
|
'track_id' => $dto->track_id,
|
|
'amount' => $dto->amount,
|
|
'currency' => $dto->currency,
|
|
'callback_url' => $dto->callback_url,
|
|
'status_id' => PaymentStatusEnum::Unpaid->value,
|
|
'status_name' => PaymentStatusEnum::Unpaid->name,
|
|
'ip' => $dto->ip,
|
|
'user_gateway_id' => $dto->user_gateway_id,
|
|
]);
|
|
|
|
$response = $this->fib_client->createPaymentService();
|
|
$fib_response_dto = FIBPaymentCreateDTO::fromResponse($response);
|
|
|
|
$transaction = Transaction::query()->create([
|
|
'user_id' => $payment->user_id,
|
|
'amount' => $payment->amount,
|
|
'currency' => $payment->currency,
|
|
'callback_url' => $payment->callback_url,
|
|
// 'description' => '',
|
|
// 'expires_in' => '',
|
|
'payment_id' => $payment->id,
|
|
'payment_track_id' => $payment->track_id,
|
|
'user_gateway_id' => $payment->user_gateway_id,
|
|
// 'status' => '',
|
|
]);
|
|
|
|
$fib_transactions = FibTransaction::query()->create([
|
|
'transaction_id' => $transaction->id,
|
|
'qrcode' => $fib_response_dto->qrCode,
|
|
'readable_code' => $fib_response_dto->readableCode,
|
|
'personalAppLink' => $fib_response_dto->personalAppLink,
|
|
'businessAppLink' => $fib_response_dto->businessAppLink,
|
|
'corporateAppLink' => $fib_response_dto->corporateAppLink,
|
|
'paymentId' => $fib_response_dto->paymentId,
|
|
'paymentMethod' => 'fib',
|
|
'validUntil' => $fib_response_dto->validUntil,
|
|
'status_id' => PaymentStatusEnum::Unpaid->value,
|
|
'status_name' => PaymentStatusEnum::Unpaid->name,
|
|
]);
|
|
return $payment;
|
|
} catch (\Exception $exception) {
|
|
throw new \Exception($exception->getMessage());
|
|
}
|
|
}
|
|
}
|