wip
This commit is contained in:
@@ -4,6 +4,7 @@ use App\Events\EventType;
|
|||||||
use App\Models\Payment\OnlinePaymentHistory;
|
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\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;
|
||||||
@@ -401,7 +402,7 @@ function emptyClass(...$arguments): object
|
|||||||
* @param string $orderId
|
* @param string $orderId
|
||||||
* @param int|string $username
|
* @param int|string $username
|
||||||
* @param string $password
|
* @param string $password
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function checkOnlinePayment(string $orderId, int|string $username, string $password): mixed
|
function checkOnlinePayment(string $orderId, int|string $username, string $password): mixed
|
||||||
@@ -426,19 +427,18 @@ function checkOnlinePayment(string $orderId, int|string $username, string $passw
|
|||||||
* @param string $online_payment_auth_ref_num
|
* @param string $online_payment_auth_ref_num
|
||||||
* @param string $online_payment_tmt_amount
|
* @param string $online_payment_tmt_amount
|
||||||
* @param string $pay_purpose
|
* @param string $pay_purpose
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function syncWithBankSystem(
|
function syncWithBankSystem(
|
||||||
$online_payment_order_uuid,
|
$online_payment_order_uuid,
|
||||||
$bank_unique_code,
|
$bank_unique_code,
|
||||||
$online_payment_terminal_id,
|
$online_payment_terminal_id,
|
||||||
$user_deposit_account,
|
$user_deposit_account,
|
||||||
$online_payment_auth_ref_num,
|
$online_payment_auth_ref_num,
|
||||||
$online_payment_tmt_amount,
|
$online_payment_tmt_amount,
|
||||||
$pay_purpose
|
$pay_purpose
|
||||||
): mixed
|
): mixed {
|
||||||
{
|
|
||||||
$ecomId = $online_payment_order_uuid;
|
$ecomId = $online_payment_order_uuid;
|
||||||
$agentId = $bank_unique_code;
|
$agentId = $bank_unique_code;
|
||||||
$eposId = $online_payment_terminal_id;
|
$eposId = $online_payment_terminal_id;
|
||||||
@@ -479,3 +479,43 @@ function syncWithBankSystem(
|
|||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Sber credentials for a given payment item.
|
||||||
|
*
|
||||||
|
* @param SberPaymentOrderItem $item
|
||||||
|
* @return array{username?: string, password?: string, onlinePaymentResource?: OnlinePaymentHistory, error?: string, type?: 'danger'|'modal'}
|
||||||
|
*/
|
||||||
|
function getSberCredentials(SberPaymentOrderItem $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'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $relatedResource->branch) {
|
||||||
|
return ['error' => 'Şahamça bilen birikdirilmedik', 'type' => 'danger'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$username = $relatedResource->branch->billing_sber_username;
|
||||||
|
$password = $relatedResource->branch->billing_sber_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,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Nova\Actions\Sber;
|
namespace App\Nova\Actions\Sber;
|
||||||
|
|
||||||
use App\Models\Payment\OnlinePaymentHistory;
|
|
||||||
use App\Nova\Actions\CheckOnlinePayment;
|
use App\Nova\Actions\CheckOnlinePayment;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
@@ -36,35 +35,16 @@ class SyncWithSystem extends Action
|
|||||||
/** @var \App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem $item */
|
/** @var \App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem $item */
|
||||||
$item = $models->first();
|
$item = $models->first();
|
||||||
|
|
||||||
|
$result = getSberCredentials($item);
|
||||||
|
|
||||||
|
if (isset($result['error'])) {
|
||||||
|
$this->handleError($result);
|
||||||
|
}
|
||||||
|
|
||||||
/** @var \App\Models\Payment\OnlinePaymentHistory $onlinePaymentResource */
|
/** @var \App\Models\Payment\OnlinePaymentHistory $onlinePaymentResource */
|
||||||
$onlinePaymentResource = OnlinePaymentHistory::find($item->online_payment_history_id);
|
$onlinePaymentResource = $result['onlinePaymentResource'];
|
||||||
|
|
||||||
if (! $onlinePaymentResource) {
|
$response = checkOnlinePayment($onlinePaymentResource->orderId, $result['username'], $result['password']);
|
||||||
return ActionResponse::danger('Online payment resource tapylmady');
|
|
||||||
}
|
|
||||||
|
|
||||||
$relatedResource = (new $onlinePaymentResource->online_paymantable_type)
|
|
||||||
->find(id: $onlinePaymentResource->online_paymantable_id);
|
|
||||||
|
|
||||||
if (! $relatedResource) {
|
|
||||||
return ActionResponse::danger('Bu resource tapylmady');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $relatedResource->branch) {
|
|
||||||
return ActionResponse::danger('Şahamça bilen birikdirilmedik');
|
|
||||||
}
|
|
||||||
|
|
||||||
$username = $relatedResource->branch->billing_sber_username;
|
|
||||||
$password = $relatedResource->branch->billing_sber_password;
|
|
||||||
|
|
||||||
if ($username == '') {
|
|
||||||
return Action::modal('modal-response', [
|
|
||||||
'title' => 'HALKBANK API',
|
|
||||||
'body' => 'Ulanyjy ady bilen açar sözi gabat gelmedi',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = checkOnlinePayment($onlinePaymentResource->orderId, $username, $password);
|
|
||||||
|
|
||||||
// syncWithBankSystem();
|
// syncWithBankSystem();
|
||||||
|
|
||||||
@@ -84,4 +64,21 @@ class SyncWithSystem extends Action
|
|||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle error
|
||||||
|
*
|
||||||
|
* @param array $result
|
||||||
|
*/
|
||||||
|
private function handleError(array $result): mixed
|
||||||
|
{
|
||||||
|
if ($result['type'] === 'modal') {
|
||||||
|
return Action::modal('modal-response', [
|
||||||
|
'title' => 'HALKBANK API',
|
||||||
|
'body' => $result['error'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ActionResponse::danger($result['error']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user