120 lines
3.7 KiB
PHP
120 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\OnlinePayment\Repositories;
|
|
|
|
use App\Modules\CardOrder\Models\CardOrder;
|
|
use App\Modules\HalkbankOnlinePayment\Repositories\HalkbankOnlinePaymentRepository;
|
|
use App\Modules\OnlinePayment\Models\OnlinePayment;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class OnlinePaymentRepository
|
|
{
|
|
/**
|
|
* Pending online payments
|
|
*/
|
|
public const PENDING = 'pending';
|
|
|
|
/**
|
|
* Failed online payments
|
|
*/
|
|
public const FAILED = 'failed';
|
|
|
|
/**
|
|
* Paid online payments
|
|
*/
|
|
public const PAID = 'paid';
|
|
|
|
/**
|
|
* Status Values
|
|
*
|
|
* @return array<null|string, string>
|
|
*/
|
|
public static function statusValues(): array
|
|
{
|
|
return [
|
|
null => '-',
|
|
self::PENDING => __('Pending'),
|
|
self::PAID => __('Paid'),
|
|
self::FAILED => __('Cancelled'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
public function generateOrderNumber(): string
|
|
{
|
|
return date('dmyHis');
|
|
}
|
|
}
|