update balance api - online payment, check online payment page unblocked
This commit is contained in:
parent
1aa4afcbf7
commit
14f234d427
|
|
@ -1,12 +1,12 @@
|
|||
<?php namespace AhmadFatoni\ApiGenerator\Controllers\API;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Cms\Classes\Controller;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use October\Rain\Support\Facades\Event;
|
||||
use TPS\Birzha\Classes\ErrorResponseApi;
|
||||
use TPS\Birzha\Models\Payment;
|
||||
use TPS\Birzha\Classes\Payment as PaymentAPI;
|
||||
use TPS\Birzha\Classes\TransactionResource;
|
||||
|
||||
class TransactionsApiController extends KabinetAPIController
|
||||
|
|
@ -45,6 +45,7 @@ class TransactionsApiController extends KabinetAPIController
|
|||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'type' => 'required|in:bank,online',
|
||||
'card_type' => 'required_if:type,online|in:halkbank,rysgal,senagat',
|
||||
'amount' => 'required_if:type,online|numeric|gt:0',
|
||||
'bank_file' => 'required_if:type,bank|mimes:pdf,jpg,png',
|
||||
]);
|
||||
|
|
@ -53,31 +54,35 @@ class TransactionsApiController extends KabinetAPIController
|
|||
return response()->json($validator->errors(), 400);
|
||||
}
|
||||
|
||||
$payment = $this->createNewPayment(false, $request->all());
|
||||
$formData = $request->all();
|
||||
|
||||
$payment = $this->createNewPayment(false, $formData);
|
||||
|
||||
if($payment->payment_type == 'online'){
|
||||
|
||||
$payment->amount = $request->get('amount');
|
||||
|
||||
$url = url('bank_result', ['payment_id' => $payment->id]);
|
||||
|
||||
try {
|
||||
$response = PaymentAPI::registerOrder($payment, $url);
|
||||
// Halkbank or Rysgal or Senagat
|
||||
$onlinePaymentClass = Config::get('bank.' . $formData['card_type'] . '.class');
|
||||
$onlinePayment = new $onlinePaymentClass;
|
||||
|
||||
$response = $onlinePayment->registerOrder($payment, $url);
|
||||
|
||||
$result = json_decode($response->body, true);
|
||||
|
||||
if($result['errorCode'] == 0) {
|
||||
$successfullyRegistered = $onlinePayment->checkRegisterOrderErrorCode($result);
|
||||
if($successfullyRegistered) {
|
||||
|
||||
$payment->order_id = $result['orderId'];
|
||||
|
||||
$payment->save();
|
||||
|
||||
return response()->json(['formUrl' => $result['formUrl']], 200);
|
||||
|
||||
} else {
|
||||
return response()->json(['error' => [
|
||||
'ru' => trans('validation.api.bank_services_unavailable', [], 'ru'),
|
||||
'en' => trans('validation.api.bank_services_unavailable', [], 'en'),
|
||||
'tm' => trans('validation.api.bank_services_unavailable', [], 'tm'),
|
||||
]], 200);
|
||||
|
||||
return response()->json(ErrorResponseApi::translateErrorMessage('api.bank_services_unavailable'), 200);
|
||||
}
|
||||
|
||||
} catch(\Throwable $th){
|
||||
|
|
@ -86,11 +91,7 @@ class TransactionsApiController extends KabinetAPIController
|
|||
|
||||
Log::info($th->getMessage());
|
||||
|
||||
return response()->json(['error' => [
|
||||
'ru' => trans('validation.api.online_payment_failed', [], 'ru'),
|
||||
'en' => trans('validation.api.online_payment_failed', [], 'en'),
|
||||
'tm' => trans('validation.api.online_payment_failed', [], 'tm'),
|
||||
]], 500);
|
||||
return response()->json(ErrorResponseApi::translateErrorMessage('api.online_payment_failed'), 200);
|
||||
}
|
||||
}
|
||||
elseif($payment->payment_type == 'bank'){
|
||||
|
|
@ -99,17 +100,9 @@ class TransactionsApiController extends KabinetAPIController
|
|||
|
||||
if($payment->save()){
|
||||
Event::fire('tps.payment.received',$payment);
|
||||
return response()->json(['success' => [
|
||||
'ru' => trans('validation.api.bank_payment_saved', [], 'ru'),
|
||||
'en' => trans('validation.api.bank_payment_saved', [], 'en'),
|
||||
'tm' => trans('validation.api.bank_payment_saved', [], 'tm'),
|
||||
]], 200);
|
||||
return response()->json(ErrorResponseApi::translateErrorMessage('api.bank_payment_saved'), 200);
|
||||
} else {
|
||||
return response()->json(['error' => [
|
||||
'ru' => trans('validation.api.bank_payment_failed', [], 'ru'),
|
||||
'en' => trans('validation.api.bank_payment_failed', [], 'en'),
|
||||
'tm' => trans('validation.api.bank_payment_failed', [], 'tm'),
|
||||
]], 500);
|
||||
return response()->json(ErrorResponseApi::translateErrorMessage('api.bank_payment_failed'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -123,6 +116,7 @@ class TransactionsApiController extends KabinetAPIController
|
|||
$newPayment->user_id = $this->user->id;
|
||||
$newPayment->amount = $formData['amount'] ?? 0;
|
||||
$newPayment->payment_type = $formData['type'];
|
||||
$newPayment->card_type = isset($formData['card_type']) ? $formData['card_type'] : null;
|
||||
$newPayment->save();
|
||||
|
||||
// attach file to payment
|
||||
|
|
|
|||
|
|
@ -47,6 +47,10 @@ class Halkbank extends Payment
|
|||
|
||||
public function checkReturnUrlParams($returnUrlParams, $payment)
|
||||
{
|
||||
if (!array_key_exists('status', $returnUrlParams)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($payment && $returnUrlParams['status'] === 'success' && $returnUrlParams['orderId'] === $payment->order_id) {
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ use Illuminate\Support\Facades\Config;
|
|||
use October\Rain\Exception\AjaxException;
|
||||
use October\Rain\Support\Facades\Event;
|
||||
use TPS\Birzha\Models\Payment;
|
||||
use TPS\Birzha\Classes\Payment as CardApi;
|
||||
|
||||
class Balance extends ComponentBase
|
||||
{
|
||||
|
|
@ -25,8 +24,7 @@ class Balance extends ComponentBase
|
|||
|
||||
$rules = [
|
||||
'amount' => 'required|numeric',
|
||||
'card_type' => 'required_if:payment_type,online',
|
||||
'card_type' => 'in:halkbank,rysgal,senagat'
|
||||
'card_type' => 'required_if:payment_type,online|in:halkbank,rysgal,senagat',
|
||||
];
|
||||
|
||||
$this->validateForm($data, $rules);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ class PaymentApi extends ComponentBase
|
|||
|
||||
if(is_null($payment)) {
|
||||
return Redirect::to('/404');
|
||||
} elseif($payment->payment_type == 'bank') {
|
||||
return Redirect::to('/404');
|
||||
}
|
||||
|
||||
$onlinePaymentClass = Config::get('bank.' . $payment->card_type . '.class');
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ localeUrl[en] = "/bank_result/:payment_id"
|
|||
localeUrl[ru] = "/bank_result/:payment_id"
|
||||
|
||||
[session]
|
||||
security = "user"
|
||||
security = "all"
|
||||
redirect = "vojti"
|
||||
|
||||
[paymentapi]
|
||||
|
|
|
|||
Loading…
Reference in New Issue