wip
This commit is contained in:
@@ -5,6 +5,7 @@ use App\Models\Payment\OnlinePaymentHistory;
|
|||||||
use App\Models\System\Roles\Permission;
|
use App\Models\System\Roles\Permission;
|
||||||
use App\Models\System\Verification;
|
use App\Models\System\Verification;
|
||||||
use App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem;
|
use App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem;
|
||||||
|
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem;
|
||||||
use App\Nova\Resources\Order\Card\CardTransaction\Actions\DownloadCardTransaction;
|
use App\Nova\Resources\Order\Card\CardTransaction\Actions\DownloadCardTransaction;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Psr7\Request as GuzzleRequest;
|
use GuzzleHttp\Psr7\Request as GuzzleRequest;
|
||||||
@@ -521,7 +522,7 @@ function getSberCredentials(SberPaymentOrderItem $item): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
function syncWithAzatAPI(SberPaymentOrderItem $orderItem): array
|
function syncSberWithAzatAPI(SberPaymentOrderItem $orderItem): array
|
||||||
{
|
{
|
||||||
$result = getSberCredentials($orderItem);
|
$result = getSberCredentials($orderItem);
|
||||||
|
|
||||||
@@ -590,3 +591,116 @@ function syncWithAzatAPI(SberPaymentOrderItem $orderItem): array
|
|||||||
'type' => 'modal',
|
'type' => 'modal',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Sber credentials for a given payment item.
|
||||||
|
*
|
||||||
|
* @param SberPaymentOrderItem $item
|
||||||
|
* @return array{username?: string, password?: string, onlinePaymentResource?: OnlinePaymentHistory, relatedResource?: mixed, error?: string, type?: 'danger'|'modal'}
|
||||||
|
*/
|
||||||
|
function getVisaCredentials(VisaMasterPaymentOrderItem $item): array
|
||||||
|
{
|
||||||
|
/** @var \App\Models\Payment\OnlinePaymentHistory|null $onlinePaymentResource */
|
||||||
|
$onlinePaymentResource = OnlinePaymentHistory::find($item->online_payment_history_id);
|
||||||
|
|
||||||
|
if (! $onlinePaymentResource) {
|
||||||
|
return ['error' => 'Online payment resource tapylmady', 'type' => 'danger'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$relatedResource = (new $onlinePaymentResource->online_paymantable_type)
|
||||||
|
->find(id: $onlinePaymentResource->online_paymantable_id);
|
||||||
|
|
||||||
|
if (! $relatedResource) {
|
||||||
|
return ['error' => 'Bu resource tapylmady', 'type' => 'danger'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$relatedResource->loadMissing(['branch']);
|
||||||
|
|
||||||
|
if (! $relatedResource->branch) {
|
||||||
|
return ['error' => 'Şahamça bilen birikdirilmedik', 'type' => 'danger'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$username = $relatedResource->branch->billing_visa_master_username;
|
||||||
|
$password = $relatedResource->branch->billing_visa_master_password;
|
||||||
|
|
||||||
|
if (empty($username) || empty($password)) {
|
||||||
|
return ['error' => 'Ulanyjy ady bilen açar sözi gabat gelmedi', 'type' => 'modal'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'username' => $username,
|
||||||
|
'password' => $password,
|
||||||
|
'onlinePaymentResource' => $onlinePaymentResource,
|
||||||
|
'relatedResource' => $relatedResource,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncVisaWithAzatAPI(VisaMasterPaymentOrderItem $orderItem): array
|
||||||
|
{
|
||||||
|
$result = getVisaCredentials($orderItem);
|
||||||
|
|
||||||
|
if (isset($result['error'])) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \App\Models\Payment\OnlinePaymentHistory $onlinePaymentResource */
|
||||||
|
$onlinePaymentResource = $result['onlinePaymentResource'];
|
||||||
|
|
||||||
|
/** @var \App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder $sberPaymentOrder */
|
||||||
|
$visaPaymentOrder = $result['relatedResource'];
|
||||||
|
|
||||||
|
$response = checkOnlinePayment($onlinePaymentResource->orderId, $result['username'], $result['password']);
|
||||||
|
|
||||||
|
if ($response['errorCode'] != 0) {
|
||||||
|
return [
|
||||||
|
'error' => $response['errorMessage'],
|
||||||
|
'type' => 'modal',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$systemRawResponse = syncWithBankSystem(
|
||||||
|
online_payment_order_uuid: $onlinePaymentResource->orderId,
|
||||||
|
bank_unique_code: $visaPaymentOrder->branch->unique_code,
|
||||||
|
online_payment_terminal_id: $response['terminalId'],
|
||||||
|
user_deposit_account: number_format($visaPaymentOrder->sender_deposit_account, 0, '', ''),
|
||||||
|
online_payment_auth_ref_num: $response['authRefNum'],
|
||||||
|
online_payment_tmt_amount: $orderItem->tmt_payment_amount,
|
||||||
|
pay_purpose: $orderItem->created_at->translatedFormat('F').' '.$orderItem->created_at->format('Y')
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($systemRawResponse == null) {
|
||||||
|
return [
|
||||||
|
'error' => 'Connection issue to SYSTEM',
|
||||||
|
'type' => 'modal',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$systemResponse = json_decode($systemRawResponse);
|
||||||
|
|
||||||
|
$success = false;
|
||||||
|
if (is_object($systemResponse)) {
|
||||||
|
$success = $systemResponse->errCode == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $success) {
|
||||||
|
$message = 'Error';
|
||||||
|
|
||||||
|
if (isset($systemResponse->msgSys)) {
|
||||||
|
$message .= ' '.$systemResponse->msgSys;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'error' => $message,
|
||||||
|
'type' => 'modal',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$orderItem->update([
|
||||||
|
'synced_with_system' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'success' => true,
|
||||||
|
'type' => 'modal',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,18 +34,6 @@ class OnlinePaymentController extends Controller
|
|||||||
/** @var \App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem */
|
/** @var \App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem */
|
||||||
$resource = $data['resource'];
|
$resource = $data['resource'];
|
||||||
|
|
||||||
if ($data['success'] && $paymentHistory && is_array($paymentHistory->api_response)) {
|
|
||||||
info(OnlinePaymentRepo::syncWithBilling(
|
|
||||||
uuid: $paymentHistory->orderId,
|
|
||||||
bank_code: $bank->unique_code,
|
|
||||||
terminal_id: $paymentHistory->api_response['terminalId'],
|
|
||||||
account_number: $resource->parent->sender_datas[0]['deposit_account'],
|
|
||||||
rrn: $paymentHistory->api_response['authRefNum'],
|
|
||||||
amount: $resource->tmt_payment_amount,
|
|
||||||
pay_purpose: $resource->created_at->translatedFormat('F').' '.$resource->created_at->format('Y'),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
return view(OnlinePaymentRepo::statusView(), $data);
|
return view(OnlinePaymentRepo::statusView(), $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,12 +53,6 @@ class OnlinePaymentController extends Controller
|
|||||||
/** @var \App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem */
|
/** @var \App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem */
|
||||||
$resource = $data['resource'];
|
$resource = $data['resource'];
|
||||||
|
|
||||||
$response = $data['response'];
|
|
||||||
|
|
||||||
// if ($data['success'] && $paymentHistory) {
|
|
||||||
// $this->runActions($paymentHistory, $bank, $response, $resource);
|
|
||||||
// }
|
|
||||||
|
|
||||||
return view(OnlinePaymentRepo::statusView(), $data);
|
return view(OnlinePaymentRepo::statusView(), $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class SendSberToSystem implements ShouldQueue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = syncWithAzatAPI($orderItem);
|
$result = syncSberWithAzatAPI($orderItem);
|
||||||
|
|
||||||
if (isset($result['error'])) {
|
if (isset($result['error'])) {
|
||||||
Log::channel('sber_job')->error(json_encode([
|
Log::channel('sber_job')->error(json_encode([
|
||||||
|
|||||||
49
app/Jobs/SendVisaToSystem.php
Normal file
49
app/Jobs/SendVisaToSystem.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem;
|
||||||
|
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;
|
||||||
|
|
||||||
|
class SendVisaToSystem implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*/
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
$orderItem = VisaMasterPaymentOrderItem::query()
|
||||||
|
->where('paid', true)
|
||||||
|
->where('synced_with_system', false)
|
||||||
|
->whereDate('created_at', '>', '2025-09-05')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $orderItem) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = syncVisaWithAzatAPI($orderItem);
|
||||||
|
|
||||||
|
if (isset($result['error'])) {
|
||||||
|
Log::channel('visa_job')->error(json_encode([
|
||||||
|
'error' => $result['error'],
|
||||||
|
'orderItem' => $orderItem,
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,7 +34,7 @@ class SyncWithSystem extends Action
|
|||||||
/** @var \App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem $orderItem */
|
/** @var \App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem $orderItem */
|
||||||
$orderItem = $models->first();
|
$orderItem = $models->first();
|
||||||
|
|
||||||
$result = syncWithAzatAPI($orderItem);
|
$result = syncSberWithAzatAPI($orderItem);
|
||||||
|
|
||||||
if (isset($result['error'])) {
|
if (isset($result['error'])) {
|
||||||
return $this->handleError($result);
|
return $this->handleError($result);
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ trait HandlesVisaMasterPayments
|
|||||||
$payment_status = $response['paymentAmountInfo']['depositedAmount'] > 0;
|
$payment_status = $response['paymentAmountInfo']['depositedAmount'] > 0;
|
||||||
|
|
||||||
$cardholderName = $response['cardAuthInfo']['cardholderName'] ?? '-';
|
$cardholderName = $response['cardAuthInfo']['cardholderName'] ?? '-';
|
||||||
$cardPan = $response['cardAuthInfo']['Pan'] ?? '-';
|
$cardPan = $response['cardAuthInfo']['pan'] ?? '-';
|
||||||
|
|
||||||
if ($payment_status) {
|
if ($payment_status) {
|
||||||
$resource->update([
|
$resource->update([
|
||||||
|
|||||||
@@ -168,6 +168,13 @@ return [
|
|||||||
'level' => env('LOG_LEVEL', 'error'),
|
'level' => env('LOG_LEVEL', 'error'),
|
||||||
'replace_placeholders' => true,
|
'replace_placeholders' => true,
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'visa_job' => [
|
||||||
|
'driver' => 'single',
|
||||||
|
'path' => storage_path('logs/visa_job.log'),
|
||||||
|
'level' => env('LOG_LEVEL', 'error'),
|
||||||
|
'replace_placeholders' => true,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('visa_master_payment_order_items', function (Blueprint $table) {
|
||||||
|
$table->boolean('synced_with_system')->nullable()->default(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('visa_master_payment_order_items', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('synced_with_system');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user