Files
tbbank-new/app/Modules/OnlinePayment/Repositories/OnlinePaymentRepository.php

158 lines
3.6 KiB
PHP

<?php
namespace App\Modules\OnlinePayment\Repositories;
use App\Modules\AppHelpers\Contracts\HasOnlinePaymentStatusFields;
use App\Modules\CardOrder\Models\CardOrder;
use App\Modules\Makeable;
use App\Modules\OnlinePayment\Contracts\PaymentProviderContract;
use App\Modules\OnlinePayment\Models\OnlinePayment;
use Illuminate\Http\Client\Response;
class OnlinePaymentRepository implements HasOnlinePaymentStatusFields
{
use Makeable;
/**
* Pending online payments
*/
public const PENDING = 'pending';
/**
* Failed online payments
*/
public const FAILED = 'failed';
/**
* Paid online payments
*/
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
*
* @return array<null|string, string>
*/
public static function statusValues(): array
{
return [
null => '-',
self::PENDING => __('Pending'),
self::PAID => __('Paid'),
self::FAILED => __('Cancelled'),
];
}
/**
* Generate order number for payment
*/
public function generateOrderNumber(): string
{
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'],
// ];
// }
}