81 lines
2.6 KiB
PHP
81 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Repos\Payment;
|
|
|
|
use App\Models\Payment\ApiKeyHalkbank;
|
|
use App\Models\Payment\OnlinePaymentHistory;
|
|
use App\Repos\Order\OrderRepo;
|
|
use Exception;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class OnlinePaymentRepo
|
|
{
|
|
/**
|
|
* Pay card order
|
|
* @param [type] $resource
|
|
*/
|
|
public function payCardOrder($resource): array
|
|
{
|
|
$orderNumber = $this->generateOrderNumber($resource);
|
|
|
|
try {
|
|
$paymentResponse = Http::get('https://mpi.gov.tm/payment/rest/register.do', [
|
|
'orderNumber' => $orderNumber,
|
|
'amount' => "00" . $resource->priceAmount(),
|
|
'currency' => 934,
|
|
'language' => 'ru',
|
|
'userName' => $resource->branch->billing_username,
|
|
'password' => $resource->branch->billing_password,
|
|
'returnUrl' => urlencode(route('online-payment-store')),
|
|
'pageView' => 'DESKTOP',
|
|
'description' => urlencode('Kart tölegi'),
|
|
]);
|
|
} catch(Exception $exception) {
|
|
Log::channel('halkbank_payment_error')->error('Payment error', [
|
|
'response' => [
|
|
'body' => $paymentResponse->body(),
|
|
],
|
|
'exception' => [
|
|
'file' => $exception->getFile(),
|
|
'line' => $exception->getLine(),
|
|
'message' => $exception->getMessage(),
|
|
]
|
|
]);
|
|
|
|
return [
|
|
'status' => 'success',
|
|
'url' => ''
|
|
];
|
|
}
|
|
|
|
OnlinePaymentHistory::create([
|
|
'online_paymantable_id' => $resource->id,
|
|
'online_paymantable_type' => $resource::$model,
|
|
'amount' => $resource->priceAmount(),
|
|
'orderNumber' => $orderNumber,
|
|
'description' => 'Kart tölegi',
|
|
'orderId' => $paymentResponse['orderId'],
|
|
'formUrl' => $paymentResponse['formUrl'],
|
|
'successUrl' => route('online-payment-store'),
|
|
'errorUrl' => route('online-payment-store'),
|
|
'api_client' => config('app.url'),
|
|
'username' => $resource->branch->billing_username,
|
|
'paymentStatus' => OrderRepo::PENDING
|
|
]);
|
|
|
|
return [
|
|
'status' => 'success',
|
|
'url' => $paymentResponse['formUrl']
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Generate order number for payment
|
|
*/
|
|
public function generateOrderNumber($resource): int
|
|
{
|
|
return ApiKeyHalkbank::generateOrderNumber($resource);
|
|
}
|
|
}
|