sber payment
This commit is contained in:
@@ -46,8 +46,8 @@ class OnlinePaymentController extends Controller
|
||||
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
|
||||
'language' => 'ru',
|
||||
'orderId' => $request->orderId,
|
||||
'userName' => $resource->branch->billing_visa_master_username,
|
||||
'password' => $resource->branch->billing_visa_master_password,
|
||||
'userName' => $resource->branch->billing_username,
|
||||
'password' => $resource->branch->billing_password,
|
||||
]);
|
||||
|
||||
$payment_status = $response['ErrorCode'] == '0';
|
||||
@@ -112,8 +112,74 @@ class OnlinePaymentController extends Controller
|
||||
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
|
||||
'language' => 'ru',
|
||||
'orderId' => $request->orderId,
|
||||
'userName' => $resource->branch->billing_username,
|
||||
'password' => $resource->branch->billing_password,
|
||||
'userName' => $resource->branch->billing_visa_master_username,
|
||||
'password' => $resource->branch->billing_visa_master_password,
|
||||
]);
|
||||
|
||||
$payment_status = $response['ErrorCode'] == '0';
|
||||
|
||||
if ($payment_status) {
|
||||
$resource->update([
|
||||
'paid' => true,
|
||||
]);
|
||||
|
||||
$paymentHistory->update([
|
||||
'paymentStatus' => OnlinePaymentRepo::PAID,
|
||||
]);
|
||||
} else {
|
||||
$paymentHistory->update([
|
||||
'paymentStatus' => OnlinePaymentRepo::FAILED,
|
||||
]);
|
||||
}
|
||||
|
||||
return view(OnlinePaymentRepo::statusView(), [
|
||||
'success' => $payment_status,
|
||||
'title' => $payment_status ? __('Payment is successful') : __('Payment has failed'),
|
||||
'pnr' => $paymentHistory->orderNumber,
|
||||
'branch_name' => $resource->branch->name,
|
||||
'price_amount' => $paymentHistory->amount,
|
||||
'return_url' => $resource->panelUrl('index'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function sber(Request $request)
|
||||
{
|
||||
// Validate the order id
|
||||
if (
|
||||
validator(
|
||||
$request->all(),
|
||||
['orderId' => ['required', 'string', 'max:50', 'exists:online_payment_histories,orderId']]
|
||||
)->fails()
|
||||
) {
|
||||
return ['wrong order id'];
|
||||
}
|
||||
|
||||
// Find order from history
|
||||
$paymentHistory = OnlinePaymentHistory::where('orderId', $request->orderId)->first();
|
||||
|
||||
// Find related resource
|
||||
$resource = (new $paymentHistory->online_paymantable_type)->find(id: $paymentHistory->online_paymantable_id);
|
||||
|
||||
// If resource could not be found or does not exist, then inform it via logs
|
||||
if (! $resource) {
|
||||
Log::channel('halkbank_payment_check_error')
|
||||
->error('Related resource not found', [
|
||||
'orderId' => $request->orderId,
|
||||
'onlinePaymentHistory_id' => $paymentHistory->id,
|
||||
'related_resource' => [
|
||||
'type' => $paymentHistory->online_paymantable_type,
|
||||
'id' => $paymentHistory->online_paymantable_id,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$resource->load('branch');
|
||||
|
||||
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
|
||||
'language' => 'ru',
|
||||
'orderId' => $request->orderId,
|
||||
'userName' => $resource->branch->billing_sber_username,
|
||||
'password' => $resource->branch->billing_sber_password,
|
||||
]);
|
||||
|
||||
$payment_status = $response['ErrorCode'] == '0';
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Modules\SberPaymentOrder\Nova\Resources\Concerns;
|
||||
|
||||
use App\Modules\SberPaymentOrder\Nova\Resources\SberPaymentOrderFileFields;
|
||||
use App\Nova\Resources\Branch\Branch;
|
||||
use App\Repos\Order\OrderRepo;
|
||||
use App\Repos\System\Settings\Legal\PassportRepo;
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace App\Modules\SberPaymentOrder\Nova\Resources;
|
||||
use App\Models\Branch\Branch;
|
||||
use App\Modules\SberPaymentOrder\Nova\Resources\Concerns\SberPaymentOrderFieldsForDetail;
|
||||
use App\Modules\SberPaymentOrder\Nova\Resources\Concerns\SberPaymentOrderFieldsForIndex;
|
||||
use App\Nova\Actions\MakePaymentNovaVisaMaster;
|
||||
use App\Nova\Actions\MakeSberPaymentAction;
|
||||
use App\Nova\Resource;
|
||||
use App\Repos\Order\Card\CardOrderRepo;
|
||||
use App\Repos\Order\OrderRepo;
|
||||
@@ -325,9 +325,9 @@ class NovaSberPaymentOrder extends Resource
|
||||
public function actions(NovaRequest $request): array
|
||||
{
|
||||
return [
|
||||
MakePaymentNovaVisaMaster::make()
|
||||
MakeSberPaymentAction::make()
|
||||
->icon('credit-card')
|
||||
->sole()
|
||||
->sole(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,17 @@
|
||||
namespace App\Nova\Actions;
|
||||
|
||||
use App\Models\CurrencyRate;
|
||||
use App\Models\Payment\OnlinePaymentHistory;
|
||||
use App\Modules\SberPaymentOrder\Models\SberPaymentOrder;
|
||||
use App\Repos\Payment\OnlinePaymentRepo;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Laravel\Nova\Actions\Action;
|
||||
use Laravel\Nova\Actions\ActionResponse;
|
||||
use Laravel\Nova\Fields\ActionFields;
|
||||
use Laravel\Nova\Fields\Heading;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
@@ -27,7 +32,27 @@ class MakeSberPaymentAction extends Action
|
||||
*/
|
||||
public function handle(ActionFields $fields, Collection $models)
|
||||
{
|
||||
//
|
||||
$usd_to_tmt = CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'TMT')->first('value');
|
||||
|
||||
if (! $usd_to_tmt) {
|
||||
return ActionResponse::danger('Walýuta hasaby girizilmedik, operator bilen habarlaşmagyňyzy haýyş edýärin.');
|
||||
}
|
||||
|
||||
$resource = $models->first();
|
||||
|
||||
if (! $resource->branch || ! $resource->branch->billing_visa_master_username) {
|
||||
return ActionResponse::danger('Şahamça visa/master tölegi kabul edip bilmeýär.');
|
||||
}
|
||||
|
||||
$tvebTaxTMT = $usd_to_tmt->value * 18;
|
||||
$bankTax = 120.75;
|
||||
$total_amount = number_format($fields->payment_amount + $tvebTaxTMT + $bankTax, 2, '.', '');
|
||||
|
||||
$payment = $this->order($resource, $total_amount);
|
||||
|
||||
return $payment['status'] === 'success'
|
||||
? ActionResponse::openInNewTab($payment['url'])
|
||||
: ActionResponse::danger('Töleg ýerinde näsazlyk!');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,13 +69,19 @@ class MakeSberPaymentAction extends Action
|
||||
return [];
|
||||
}
|
||||
|
||||
$max_value = number_format($usd_to_tmt->value * 250, 2);
|
||||
$max_value = number_format(90.6 * 250 * 0.038611, 2, '.', '');
|
||||
$tvebTaxTMT = $usd_to_tmt->value * 18;
|
||||
$bankTax = 120.75;
|
||||
|
||||
return [
|
||||
Heading::make(Blade::render(<<<HTML
|
||||
<h3 class="uppercase tracking-wide font-bold text-xs" dusk="heading">1 USD = $usd_to_tmt->value TMT</h3>
|
||||
<h3 class="uppercase tracking-wide font-bold text-xs" dusk="heading">1 RUB = 0.038611 TMT</h3>
|
||||
<br>
|
||||
<h3 class="uppercase tracking-wide font-bold text-xs" dusk="heading">TVEB USD tutumy: 18 USD</h3>
|
||||
<h3 class="uppercase tracking-wide font-bold text-xs" dusk="heading">GBÜS tutumy: 3 TMT</h3>
|
||||
<h3 class="uppercase tracking-wide font-bold text-xs" dusk="heading">TVEB tutumy TMT = $tvebTaxTMT TMT</h3>
|
||||
<br>
|
||||
<h3 class="uppercase tracking-wide font-bold text-xs" dusk="heading">Bank tutumy: $bankTax TMT</h3>
|
||||
HTML))->asHtml(),
|
||||
|
||||
Text::make(sprintf('%s (%s)', __('Töleg möçberi'), __('TMT')), 'payment_amount')
|
||||
@@ -62,9 +93,11 @@ class MakeSberPaymentAction extends Action
|
||||
Text::make(__('USD ekwalendi'), 'usd_rate')
|
||||
->fullWidth()
|
||||
->readonly()
|
||||
->dependsOn('payment_amount', function ($field, $request, $formData) use ($usd_to_tmt) {
|
||||
->dependsOn('payment_amount', function ($field, $request, $formData) {
|
||||
if ($formData->payment_amount) {
|
||||
$field->setValue(number_format($formData->payment_amount / $usd_to_tmt->value, 2, '.', ''));
|
||||
$usdValue = number_format($formData->payment_amount / (90.6 * 0.038611), 2, '.', '');
|
||||
|
||||
$field->setValue($usdValue);
|
||||
} else {
|
||||
$field->setValue('');
|
||||
}
|
||||
@@ -73,10 +106,10 @@ class MakeSberPaymentAction extends Action
|
||||
Text::make(__('Jemi (TMT)'), 'total_amount')
|
||||
->fullWidth()
|
||||
->readonly()
|
||||
->dependsOn('payment_amount', function ($field, $request, $formData) {
|
||||
->dependsOn('payment_amount', function ($field, $request, $formData) use ($tvebTaxTMT, $bankTax) {
|
||||
if (is_numeric($formData->payment_amount)) {
|
||||
$field->setValue(
|
||||
floatval(number_format($formData->payment_amount, 2, '.', '')) + 23
|
||||
number_format($formData->payment_amount + $tvebTaxTMT + $bankTax, 2, '.', '')
|
||||
);
|
||||
} else {
|
||||
$field->setValue('');
|
||||
@@ -84,4 +117,60 @@ class MakeSberPaymentAction extends Action
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Order a payment page
|
||||
*/
|
||||
public function order($resource, $amount)
|
||||
{
|
||||
$onlinePaymentRepo = OnlinePaymentRepo::make();
|
||||
|
||||
$orderNumber = $onlinePaymentRepo->generateOrderNumber($resource);
|
||||
|
||||
$paymentResponse = Http::get('https://mpi.gov.tm/payment/rest/register.do', [
|
||||
'orderNumber' => $orderNumber,
|
||||
'amount' => number_format($amount, 2, '', ''),
|
||||
'currency' => 934,
|
||||
'language' => 'ru',
|
||||
'userName' => $resource->branch->billing_sber_username,
|
||||
'password' => $resource->branch->billing_visa_master_password,
|
||||
'returnUrl' => route('online-payment-store-sber'),
|
||||
'pageView' => 'DESKTOP',
|
||||
'description' => 'Sber tölegi',
|
||||
])->onError(function ($response) {
|
||||
Log::channel('halkbank_payment_error')
|
||||
->error('Payment error', [
|
||||
'response' => [
|
||||
'body' => $response->body(),
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
if ($paymentResponse->failed()) {
|
||||
return [
|
||||
'status' => 'failed',
|
||||
'url' => '',
|
||||
];
|
||||
}
|
||||
|
||||
OnlinePaymentHistory::create([
|
||||
'online_paymantable_id' => $resource->id,
|
||||
'online_paymantable_type' => SberPaymentOrder::class,
|
||||
'amount' => number_format($amount, 2, '', ''),
|
||||
'orderNumber' => $orderNumber,
|
||||
'description' => 'Sber tölegi',
|
||||
'orderId' => $paymentResponse['orderId'],
|
||||
'formUrl' => $paymentResponse['formUrl'],
|
||||
'successUrl' => route('online-payment-store-sber'),
|
||||
'errorUrl' => route('online-payment-store-sber'),
|
||||
'api_client' => 'billing_sber_username',
|
||||
'username' => $resource->branch->billing_sber_username,
|
||||
'paymentStatus' => OnlinePaymentRepo::PENDING,
|
||||
]);
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'url' => $paymentResponse['formUrl'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,5 +38,6 @@ Route::middleware(['auth', 'unVerified'])->group(function () {
|
||||
|
||||
Route::get('online-payment-store', [OnlinePaymentController::class, 'store'])->name('online-payment-store');
|
||||
Route::get('online-payment-store-visa-master', [OnlinePaymentController::class, 'visaMaster'])->name('online-payment-store-visa-master');
|
||||
Route::get('online-payment-store-sber', [OnlinePaymentController::class, 'sber'])->name('online-payment-store-sber');
|
||||
|
||||
Route::redirect('/', config('nova.path'));
|
||||
|
||||
Reference in New Issue
Block a user