payment providers and some stan
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\HalkbankOnlinePayment\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HalkbankOnlinePaymentController extends Controller
|
||||
{
|
||||
public function store(Request $request): View
|
||||
{
|
||||
$request->validate([
|
||||
'orderId' => ['required', 'string', 'max:50', 'exists:online_payment_histories,orderId'],
|
||||
]);
|
||||
|
||||
return view('welcome');
|
||||
}
|
||||
}
|
||||
@@ -3,26 +3,25 @@
|
||||
namespace App\Modules\HalkbankOnlinePayment\Repositories;
|
||||
|
||||
use App\Modules\Makeable;
|
||||
use Closure;
|
||||
use App\Modules\OnlinePayment\Contracts\PaymentProviderContract;
|
||||
use Exception;
|
||||
use GuzzleHttp\Psr7\Response as GuzzleResponse;
|
||||
use Illuminate\Http\Client\Response;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class HalkbankOnlinePaymentRepository
|
||||
class HalkbankOnlinePaymentRepository implements PaymentProviderContract
|
||||
{
|
||||
use Makeable;
|
||||
|
||||
public function __construct(
|
||||
protected string $username = '',
|
||||
protected string $password = '',
|
||||
protected string $amount = '',
|
||||
protected int|float|string $amount = '',
|
||||
protected int|string $orderNumber = '',
|
||||
protected string $returnUrl = '',
|
||||
protected string $description = '',
|
||||
protected ?Closure $onRequestError = null,
|
||||
protected ?Closure $onResponseFail = null,
|
||||
protected ?Closure $onResponseSuccess = null,
|
||||
) {
|
||||
$this->username = config()->string('module.halkbank-online-payment.username');
|
||||
$this->password = config()->string('module.halkbank-online-payment.password');
|
||||
@@ -33,7 +32,7 @@ class HalkbankOnlinePaymentRepository
|
||||
/**
|
||||
* Send request to gatewat
|
||||
*/
|
||||
public function sendRequest()
|
||||
public function sendRequest(): Response
|
||||
{
|
||||
try {
|
||||
$paymentResponse = Http::get('https://mpi.gov.tm/payment/rest/register.do', [
|
||||
@@ -62,7 +61,11 @@ class HalkbankOnlinePaymentRepository
|
||||
],
|
||||
]);
|
||||
|
||||
return emptyClass([]);
|
||||
return new Response(new GuzzleResponse(
|
||||
503,
|
||||
['Content-Type' => 'application/json'],
|
||||
sprintf('{"error":"Payment provider connection failed","exception_message":"%s"}', $e->getMessage())
|
||||
));
|
||||
}
|
||||
|
||||
return $paymentResponse;
|
||||
@@ -95,7 +98,7 @@ class HalkbankOnlinePaymentRepository
|
||||
/**
|
||||
* Get amount
|
||||
*/
|
||||
public function amount(): string
|
||||
public function amount(): int|float|string
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
@@ -147,7 +150,7 @@ class HalkbankOnlinePaymentRepository
|
||||
/**
|
||||
* Set amoutn
|
||||
*/
|
||||
public function setAmount(string $amount): self
|
||||
public function setAmount(int|float|string $amount): self
|
||||
{
|
||||
$this->amount = $amount;
|
||||
|
||||
@@ -184,36 +187,6 @@ class HalkbankOnlinePaymentRepository
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set callback on request error
|
||||
*/
|
||||
public function setOnRequestError(Closure $onRequestError): self
|
||||
{
|
||||
$this->onRequestError = $onRequestError;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set callback on Response Fail
|
||||
*/
|
||||
public function setOnResponseFail(Closure $onResponseFail): self
|
||||
{
|
||||
$this->onResponseFail = $onResponseFail;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set callback on Response Success
|
||||
*/
|
||||
public function setOnResponseSuccess(Closure $onResponseSuccess): self
|
||||
{
|
||||
$this->onResponseSuccess = $onResponseSuccess;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate order number for payment
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\HalkbankOnlinePayment\Controllers\HalkbankOnlinePaymentController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('halkbank-online-payment-store', [HalkbankOnlinePaymentController::class, 'store'])
|
||||
->name('halkbank-online-payment.store');
|
||||
Reference in New Issue
Block a user