Refactor payment processing: update method names for clarity, enhance VisaMasterPaymentOrderRepository with payment validation logic, and improve Turkish translations for payment notifications.

This commit is contained in:
2025-11-15 18:51:40 +05:00
parent 8637c22ed7
commit c24f7cbac6
9 changed files with 333 additions and 22 deletions

View File

@@ -2,9 +2,115 @@
namespace App\Modules\VisaMasterPaymentOrder\Repositories;
use App\Modules\HalkbankOnlinePayment\Repositories\HalkbankOnlinePaymentRepository;
use App\Modules\Makeable;
use App\Modules\OnlinePayment\Repositories\OnlinePaymentRepository;
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder;
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem;
use Illuminate\Support\Carbon;
class VisaMasterPaymentOrderRepository
{
use Makeable;
/**
* Bank fee
*/
public int|string|float $bankFee = 20;
/**
* Gbus fee
*/
public int|string|float $gbusFee = 3;
/**
* Bank fee
*/
public function bankFee(): int|string|float
{
return $this->bankFee;
}
/**
* Gbus fee
*/
public function gbusFee(): int|string|float
{
return $this->gbusFee;
}
/**
* Has been paid this month
*/
public function hasBeenPaidThisMonth(VisaMasterPaymentOrder $record, Carbon $today): bool
{
return $record->paymentItems->contains(
fn (VisaMasterPaymentOrderItem $item): bool => $item->paid && $item->created_at->format('m Y') === $today->format('m Y')
);
}
/**
* Is end of month
*/
public function isEndOfMonth(Carbon $today): bool
{
$lastDay = $today->copy()->endOfMonth();
$lastDayOfWeek = $lastDay->format('l');
$oneDayBefore = $lastDay->copy()->subDay(); // Saturday...
$twoDaysBefore = $lastDay->copy()->subDays(2); // Friday...
// Condition 1: Today is the last day
if ($today->isSameDay($lastDay)) {
return true;
}
// Condition 2: Last day is Sunday → forbid Friday & Saturday
if ($lastDayOfWeek === 'Sunday' && ($today->isSameDay($oneDayBefore) || $today->isSameDay($twoDaysBefore))) {
return true;
}
// Condition 3: Last day is Saturday → forbid Friday
if ($lastDayOfWeek === 'Saturday' && $today->isSameDay($oneDayBefore)) {
return true;
}
// Default: allow payment
return false;
}
/**
* Create online payment order
*/
public function createOnlinePaymentOrder(VisaMasterPaymentOrder $record, int|float|string $amount): OnlinePaymentRepository
{
/** @var \App\Modules\Branch\Models\Branch */
$branch = $record->branch;
return OnlinePaymentRepository::make(relatedModel: $record)
->setPaymentProvider(
HalkbankOnlinePaymentRepository::make(
username: $branch->billingUsername(),
password: $branch->billingPassword(),
amount: $amount,
returnUrl: route('halkbank-online-payment.store'),
description: 'Visa/Master tölegi'
)
)
->sendRequest();
}
/**
* Create payment record
*/
public function createPaymentRecord(VisaMasterPaymentOrder $record, OnlinePaymentRepository $onlinePaymentRepository, int|string|float $usdRate): void
{
VisaMasterPaymentOrderItem::create([
'visa_master_payment_order_id' => $record->id,
'online_payment_id' => $onlinePaymentRepository->onlinePayment()->id,
'payment_order_number' => $onlinePaymentRepository->onlinePayment()->orderNumber,
'tmt_payment_amount' => $onlinePaymentRepository->paymentProvider()->amount(),
'usd_payment_amount' => $usdRate,
]);
}
}