Working on credit card
This commit is contained in:
36
app/Http/Controllers/OnlinePaymentController.php
Normal file
36
app/Http/Controllers/OnlinePaymentController.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class OnlinePaymentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Online pa
|
||||
* @param Request $request [description]
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
return $request->all();
|
||||
|
||||
// $response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
|
||||
// 'language' => 'ru',
|
||||
// 'orderId' => $request->orderId,
|
||||
// 'userName' => 301161000067,
|
||||
// 'password' => 'E3vb2SR3dgTPdff'
|
||||
// ]);
|
||||
|
||||
// if ($response['depositAmount'] > 0) {
|
||||
// $payment_history = OnlinePaymentHistory::where('orderId', $request->orderId)->first();
|
||||
|
||||
// $booking = Booking::where('id', $payment_history->online_paymantable_id)->update([
|
||||
// 'status' => Settings::PAID
|
||||
// ]);
|
||||
|
||||
// $payment_history->update([
|
||||
// 'paymentStatus' => Settings::PAID
|
||||
// ]);
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ class CardOrder extends Model
|
||||
'passport_two',
|
||||
'passport_three',
|
||||
'passport_four',
|
||||
'paid',
|
||||
'notes',
|
||||
'user_id',
|
||||
];
|
||||
@@ -101,6 +102,22 @@ class CardOrder extends Model
|
||||
parent::boot();
|
||||
|
||||
static::creating(CardOrderRepo::creating());
|
||||
static::created(CardOrderRepo::created());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if order is paid
|
||||
*/
|
||||
public function isPaid(): bool
|
||||
{
|
||||
return $this->paid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Price for order
|
||||
*/
|
||||
public function priceAmount(): float
|
||||
{
|
||||
return 1;
|
||||
// return floatval($this->cardType->price);
|
||||
}
|
||||
}
|
||||
|
||||
46
app/Models/Payment/OnlinePaymentHistory.php
Normal file
46
app/Models/Payment/OnlinePaymentHistory.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Payment;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OnlinePaymentHistory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'online_payment_histories';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'refunded_amount',
|
||||
'booking_number',
|
||||
'amount',
|
||||
'depositedAmount',
|
||||
'orderNumber',
|
||||
'description',
|
||||
'orderId',
|
||||
'cardholderName',
|
||||
'pan',
|
||||
'approvalCode',
|
||||
'expiration',
|
||||
'formUrl',
|
||||
'successUrl',
|
||||
'errorUrl',
|
||||
'api_client',
|
||||
'paymentStatus',
|
||||
'callbackStatus',
|
||||
'username',
|
||||
'online_paymantable_id',
|
||||
'online_paymantable_type',
|
||||
];
|
||||
}
|
||||
@@ -89,8 +89,9 @@ class Branch extends Resource
|
||||
Text::make(__('Billing username'), 'billing_username')
|
||||
->rules('nullable', 'string', 'max:255'),
|
||||
|
||||
Password::make(__('Billing password'), 'billing_password')
|
||||
->rules('nullable', 'string', 'max:255'),
|
||||
Text::make(__('Billing password'), 'billing_password')
|
||||
->rules('nullable', 'string', 'max:255')
|
||||
->hideFromIndex(),
|
||||
|
||||
Textarea::make(__('Address'), 'address'),
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\Nova\Forms\NovaForm;
|
||||
use App\Nova\Resource;
|
||||
use App\Nova\Resources\Order\Card\Concerns\CardOrderFieldsForDetail;
|
||||
use App\Nova\Resources\Order\Card\Concerns\CardOrderFieldsForIndex;
|
||||
use App\Repos\Order\Card\CardOrderRepo;
|
||||
use App\Repos\Order\Card\CardStateRepo;
|
||||
use App\Repos\Order\Card\CardTypeRepo;
|
||||
use App\Repos\Order\OrderRepo;
|
||||
@@ -20,6 +21,7 @@ use App\Repos\System\Settings\Legal\PassportRepo;
|
||||
use App\Repos\System\Settings\Location\RegionRepo;
|
||||
use App\Rules\DowranAgaAllowed;
|
||||
use App\Rules\OnlyLetters;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Nova\Fields\Date;
|
||||
@@ -125,6 +127,16 @@ class CardOrder extends Resource
|
||||
return $query->where('user_id', $request->user()->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* After resource created
|
||||
* @param Laravel\Nova\Http\Requests\NovaRequest $request
|
||||
* @param Illuminate\Database\Eloquent\Model $model
|
||||
*/
|
||||
public static function afterCreate(NovaRequest $request, Model $model): void
|
||||
{
|
||||
CardOrderRepo::created()($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the location to redirect the user after creation.
|
||||
*
|
||||
@@ -132,7 +144,11 @@ class CardOrder extends Resource
|
||||
*/
|
||||
public static function redirectAfterCreate(NovaRequest $request, $resource): URL|string
|
||||
{
|
||||
return URL::remote((new OnlinePaymentRepo())->payCardOrder($resource));
|
||||
$payment = (new OnlinePaymentRepo())->payCardOrder($resource);
|
||||
|
||||
return $payment['status'] === 'success'
|
||||
? URL::remote($payment['url'])
|
||||
: sprintf('resources/%s/%s', static::uriKey(), $resource->getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,10 +159,7 @@ class CardOrder extends Resource
|
||||
*/
|
||||
public static function redirectAfterUpdate(NovaRequest $request, $resource)
|
||||
{
|
||||
return URL::remote(
|
||||
(new OnlinePaymentRepo())
|
||||
->payCardOrder($resource),
|
||||
);
|
||||
return URL::remote((new OnlinePaymentRepo())->payCardOrder($resource));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,7 +346,7 @@ class CardOrder extends Resource
|
||||
->creationRules('required')
|
||||
->updateRules('nullable'),
|
||||
|
||||
NovaCustomHtml::make(__('Data'), 'ada')
|
||||
NovaCustomHtml::make(__('Data'), 'additional_data')
|
||||
->html(view('orders.cards.contract-agreement')->render())
|
||||
->fillUsing(NovaForm::fillEmpty()),
|
||||
]),
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
@@ -19,6 +20,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
Model::shouldBeStrict(! app()->isProduction());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,28 +3,71 @@
|
||||
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
|
||||
{
|
||||
public function payCardOrder($resource): string
|
||||
/**
|
||||
* Pay card order
|
||||
* @param [type] $resource
|
||||
*/
|
||||
public function payCardOrder($resource): array
|
||||
{
|
||||
$orderNumber = $this->generateOrderNumber($resource);
|
||||
|
||||
$response = Http::get('https://mpi.gov.tm/payment/rest/register.do', [
|
||||
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,
|
||||
'amount' => $booking->total_price.'00',
|
||||
'currency' => 934,
|
||||
'language' => 'ru',
|
||||
'userName' => 301161000067,
|
||||
'password' => 'E3vb2SR3dgTPdff',
|
||||
'returnUrl' => route('online-payment-store'),
|
||||
'failUrl' => route('online-payment-store'),
|
||||
'pageView' => 'DESKTOP',
|
||||
'description' => 'Sargyt',
|
||||
'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 'a';
|
||||
return [
|
||||
'status' => 'success',
|
||||
'url' => $paymentResponse['formUrl']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -126,6 +126,13 @@ return [
|
||||
'emergency' => [
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
],
|
||||
|
||||
'halkbank_payment_error' => [
|
||||
'driver' => 'single',
|
||||
'path' => storage_path('logs/halkbank_payment_error.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('card_orders', function (Blueprint $table) {
|
||||
$table->boolean('paid')->default(true);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('card_orders', function (Blueprint $table) {
|
||||
$table->dropColumn('paid');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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::create('online_payment_histories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->string('refunded_amount')->nullable();
|
||||
$table->string('booking_number')->nullable();
|
||||
$table->string('amount')->nullable();
|
||||
$table->string('depositedAmount')->nullable();
|
||||
$table->string('orderNumber')->nullable();
|
||||
$table->string('description')->nullable();
|
||||
$table->string('orderId')->nullable();
|
||||
$table->string('cardholderName')->nullable();
|
||||
$table->string('pan')->nullable();
|
||||
$table->boolean('approvalCode')->default(false);
|
||||
$table->string('expiration')->nullable();
|
||||
$table->string('formUrl')->nullable();
|
||||
$table->string('successUrl')->nullable();
|
||||
$table->string('errorUrl')->nullable();
|
||||
$table->string('api_client')->nullable();
|
||||
$table->string('paymentStatus')->nullable();
|
||||
$table->string('callbackStatus')->nullable();
|
||||
$table->string('username')->nullable();
|
||||
|
||||
$table->unsignedBigInteger('online_paymantable_id')->index()->nullable();
|
||||
$table->string('online_paymantable_type')->index()->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('online_payment_histories');
|
||||
}
|
||||
};
|
||||
@@ -3,6 +3,7 @@
|
||||
use App\Http\Controllers\Auth\LoginController;
|
||||
use App\Http\Controllers\Auth\RegisterController;
|
||||
use App\Http\Controllers\Auth\ResetPasswordController;
|
||||
use App\Http\Controllers\OnlinePaymentController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
/*
|
||||
@@ -32,4 +33,6 @@ Route::middleware(['auth', 'un_verified'])->group(function () {
|
||||
Route::post('sms-verification', [RegisterController::class, 'verifySmsCode']);
|
||||
});
|
||||
|
||||
Route::get('online-payment-store', [OnlinePaymentController::class, 'store'])->name('online-payment-store');
|
||||
|
||||
Route::redirect('/', config('nova.path'));
|
||||
|
||||
Reference in New Issue
Block a user