online payments for card order
This commit is contained in:
@@ -3,10 +3,11 @@
|
||||
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\HasOnlinePayments;
|
||||
use App\Modules\OnlinePayment\Contracts\PaymentProviderContract;
|
||||
use App\Modules\OnlinePayment\Models\OnlinePayment;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Client\Response;
|
||||
|
||||
class OnlinePaymentRepository implements HasOnlinePaymentStatusFields
|
||||
@@ -28,6 +29,11 @@ class OnlinePaymentRepository implements HasOnlinePaymentStatusFields
|
||||
*/
|
||||
public const PAID = 'paid';
|
||||
|
||||
/**
|
||||
* Related model
|
||||
*/
|
||||
protected ?Model $relatedModel;
|
||||
|
||||
/**
|
||||
* Payment provider
|
||||
*/
|
||||
@@ -48,11 +54,21 @@ class OnlinePaymentRepository implements HasOnlinePaymentStatusFields
|
||||
*/
|
||||
protected bool $failed;
|
||||
|
||||
/**
|
||||
* Payment order id
|
||||
*/
|
||||
protected string $orderId;
|
||||
|
||||
/**
|
||||
* Online payment link
|
||||
*/
|
||||
protected string $paymentLink;
|
||||
|
||||
public function __construct(?Model $relatedModel)
|
||||
{
|
||||
$this->relatedModel = $relatedModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Status Values
|
||||
*
|
||||
@@ -102,17 +118,35 @@ class OnlinePaymentRepository implements HasOnlinePaymentStatusFields
|
||||
return $this->failed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set respond results
|
||||
*/
|
||||
public function setResponseResults(bool $result): void
|
||||
{
|
||||
$this->successful = $result;
|
||||
$this->failed = ! $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send request via provider
|
||||
*/
|
||||
public function sendRequest(): self
|
||||
{
|
||||
$response = $this->provider->sendRequest();
|
||||
$this->response = $this->provider->sendRequest();
|
||||
|
||||
$this->failed = $response->failed();
|
||||
$this->successful = $response->successful();
|
||||
$this->failed = $this->response->failed();
|
||||
$this->successful = $this->response->successful();
|
||||
|
||||
$this->response = $response;
|
||||
if ($this->response['errorCode'] != 0) {
|
||||
$this->setResponseResults(false);
|
||||
}
|
||||
|
||||
if ($this->successful) {
|
||||
$this->orderId = string($this->response['orderId']);
|
||||
$this->paymentLink = string($this->response['formUrl']);
|
||||
|
||||
$this->createHistory();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -125,33 +159,28 @@ class OnlinePaymentRepository implements HasOnlinePaymentStatusFields
|
||||
return $this->paymentLink;
|
||||
}
|
||||
|
||||
// public function payCardOrder()
|
||||
// {
|
||||
// if ($paymentResponse->failed()) {
|
||||
// return [
|
||||
// 'status' => 'failed',
|
||||
// 'url' => '',
|
||||
// ];
|
||||
// }
|
||||
/**
|
||||
* Create online payment history
|
||||
*/
|
||||
public function createHistory(): void
|
||||
{
|
||||
$data = [
|
||||
'amount' => $this->provider->amount(),
|
||||
'orderNumber' => $this->provider->orderNumber(),
|
||||
'description' => $this->provider->description(),
|
||||
'orderId' => $this->orderId,
|
||||
'formUrl' => $this->paymentLink,
|
||||
'successUrl' => $this->provider->returnUrl(),
|
||||
'errorUrl' => $this->provider->returnUrl(),
|
||||
'username' => $this->provider->username(),
|
||||
'paymentStatus' => self::PENDING,
|
||||
];
|
||||
|
||||
// $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();
|
||||
if ($this->relatedModel) {
|
||||
$data['online_paymantable_id'] = $this->relatedModel->id; // @phpstan-ignore-line
|
||||
$data['online_paymantable_type'] = $this->relatedModel::class;
|
||||
}
|
||||
|
||||
// return [
|
||||
// 'status' => 'success',
|
||||
// 'url' => $paymentResponse['formUrl'],
|
||||
// ];
|
||||
// }
|
||||
OnlinePayment::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user