payment providers and some stan

This commit is contained in:
2025-10-31 01:13:04 +05:00
parent 11f99caf42
commit 834527647d
11 changed files with 232 additions and 121 deletions

View File

@@ -2,14 +2,17 @@
namespace App\Modules\OnlinePayment\Repositories;
use App\Modules\AppHelpers\Contracts\HasOnlinePaymentStatusFields;
use App\Modules\CardOrder\Models\CardOrder;
use App\Modules\HalkbankOnlinePayment\Repositories\HalkbankOnlinePaymentRepository;
use App\Modules\Makeable;
use App\Modules\OnlinePayment\Contracts\PaymentProviderContract;
use App\Modules\OnlinePayment\Models\OnlinePayment;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Client\Response;
class OnlinePaymentRepository
class OnlinePaymentRepository implements HasOnlinePaymentStatusFields
{
use Makeable;
/**
* Pending online payments
*/
@@ -25,6 +28,31 @@ class OnlinePaymentRepository
*/
public const PAID = 'paid';
/**
* Payment provider
*/
protected PaymentProviderContract $provider;
/**
* Response
*/
protected Response $response;
/**
* If payment is successful
*/
protected bool $successful;
/**
* If payment has failed
*/
protected bool $failed;
/**
* Online payment link
*/
protected string $paymentLink;
/**
* Status Values
*
@@ -40,75 +68,6 @@ class OnlinePaymentRepository
];
}
/**
* Pay card order
*
* @param mixed $resource
* @return array<string, string>
*/
public function payCardOrder()
{
$orderNumber = $this->generateOrderNumber();
$response = HalkbankOnlinePaymentRepository::make()
->setUsername()
->setPassword()
->setAmount()
->setOrderNumber()
->returnUrl()
->description()
->onError()
->onResponseFail()
->onResponseSuccess()
->sendRequest();
// $paymentResponse = Http::get('https://mpi.gov.tm/payment/rest/register.do', [
// 'orderNumber' => $orderNumber,
// 'amount' => $this->getPrice($resource->priceAmount()),
// 'currency' => 934,
// 'language' => 'ru',
// 'userName' => $resource->branch->billing_username,
// 'password' => $resource->branch->billing_password,
// 'returnUrl' => route('online-payment-store'),
// 'pageView' => 'DESKTOP',
// 'description' => 'Kart 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 = new OnlinePayment;
// $onlinePaymentHistory->online_paymantable_id = $resource->really();
// $onlinePaymentHistory->online_paymantable_type = CardOrder::class;
// $onlinePaymentHistory->amount = $resource->priceAmount();
// $onlinePaymentHistory->orderNumber = $orderNumber;
// $onlinePaymentHistory->description = 'Kart tölegi';
// $onlinePaymentHistory->orderId = $paymentResponse['orderId'];
// $onlinePaymentHistory->formUrl = $paymentResponse['formUrl'];
// $onlinePaymentHistory->successUrl = route('online-payment-store');
// $onlinePaymentHistory->errorUrl = route('online-payment-store');
// $onlinePaymentHistory->api_client = 'billing_username';
// $onlinePaymentHistory->username = $resource->branch->billing_username;
// $onlinePaymentHistory->paymentStatus = self::PENDING;
// $onlinePaymentHistory->save();
// return [
// 'status' => 'success',
// 'url' => $paymentResponse['formUrl'],
// ];
}
/**
* Generate order number for payment
*/
@@ -116,4 +75,83 @@ class OnlinePaymentRepository
{
return date('dmyHis');
}
/**
* Payment provder
*/
public function paymentProvider(PaymentProviderContract $provider): self
{
$this->provider = $provider;
return $this;
}
/**
* If payment has been successfull
*/
public function successful(): bool
{
return $this->successful;
}
/**
* If payment has been a failure
*/
public function failed(): bool
{
return $this->failed;
}
/**
* Send request via provider
*/
public function sendRequest(): self
{
$response = $this->provider->sendRequest();
$this->failed = $response->failed();
$this->successful = $response->successful();
$this->response = $response;
return $this;
}
/**
* Payment link
*/
public function paymentLink(): string
{
return $this->paymentLink;
}
// public function payCardOrder()
// {
// if ($paymentResponse->failed()) {
// return [
// 'status' => 'failed',
// 'url' => '',
// ];
// }
// $onlinePaymentHistory = new OnlinePayment;
// $onlinePaymentHistory->online_paymantable_id = $resource->really();
// $onlinePaymentHistory->online_paymantable_type = CardOrder::class;
// $onlinePaymentHistory->amount = $resource->priceAmount();
// $onlinePaymentHistory->orderNumber = $orderNumber;
// $onlinePaymentHistory->description = 'Kart tölegi';
// $onlinePaymentHistory->orderId = $paymentResponse['orderId'];
// $onlinePaymentHistory->formUrl = $paymentResponse['formUrl'];
// $onlinePaymentHistory->successUrl = route('online-payment-store');
// $onlinePaymentHistory->errorUrl = route('online-payment-store');
// $onlinePaymentHistory->api_client = 'billing_username';
// $onlinePaymentHistory->username = $resource->branch->billing_username;
// $onlinePaymentHistory->paymentStatus = self::PENDING;
// $onlinePaymentHistory->save();
// return [
// 'status' => 'success',
// 'url' => $paymentResponse['formUrl'],
// ];
// }
}