<?php
namespace App\Models\Admin;
use App\Constants\AdminRoleConst;
use App\Notifications\Admin\Auth\ResetPassword;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
class Admin extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
/**
* The attributes that are not assignable.
*
* @var array<int, string>
*/
protected $guarded = [
'id',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
protected $appends = [
'fullname',
'stringStatus',
'editData',
];
protected $with = [
'roles',
];
public function getFullnameAttribute() {
return $this->firstname . " " . $this->lastname;
}
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPassword($token));
}
public function getStringStatusAttribute() {
$status = [
true => __("Active"),
false => __("Banned"),
];
return $status[$this->status];
}
public function getEditDataAttribute() {
$data = [
'firstname' => $this->firstname,
'lastname' => $this->lastname,
'username' => $this->username,
'email' => $this->email,
'phone' => $this->phone,
'image' => $this->image,
'roles' => $this->roles,
];
return json_encode($data);
}
public function roles() {
return $this->hasMany(AdminHasRole::class,"admin_id");
}
public function getRolesCollection() {
$roles = $this->roles;
$roles_array = [];
foreach($roles as $item) {
$roles_array[] = $item->role->name;
}
return $roles_array;
}
public function getRolesString() {
$roles = $this->getRolesCollection();
return implode(" | ",$roles);
}
public function isSuperAdmin() {
$roles = $this->getRolesCollection();
if(in_array(AdminRoleConst::SUPER_ADMIN,$roles)) {
return true;
}
return false;
}
public function scopeNotAuth($query) {
return $query->whereNot("id",auth()->user()->id);
}
public function scopeSearch($query,$data) {
return $query->where(function($q) use ($data) {
$q->where("username","like","%".$data."%");
})->orWhere("email","like","%".$data."%")->orWhere("phone","like","%".$data."%");
}
}
Initiates a new payment transaction.
create-order
| Parameter | Type | Details |
|---|---|---|
| amount | decimal | Your Amount , Must be rounded at 2 precision. |
| currency | string | Currency Code, Must be in Upper Case (Alpha-3 code) |
| success_url | string | Enter your return or success URL |
| cancel_url | string (optional) | Enter your cancel or failed URL |
Request Example (guzzle)
<?php
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', $base_url.'create-order', [
'headers' => [
'Authorization' => 'Bearer '. $authorizationToken,
'accept' => 'application/json',
'content-type' => 'application/json',
],
'form_params' => [
'amount' => '$amount',
'currency' => 'currency',
'success_url' => 'success_url',
'cancel_url' => 'cancel_url',
],
]);
echo $response->getBody();
**Response: SUCCESS (200 OK)**
{
"message": {
"success": [
"Order created successfully."
]
},
"data": {
"redirect_url":"https://example.com/login/OISADFDFSDFSF",
"order_details":{
"amount" : "10",
"fixed_charge" : 2,
"percent_charge" : 1,
"total_charge" : 3,
"total_payable" : 13,
"currency" : "USD",
"expiry_time": "2024-04-25T06:48:35.984285Z",
"success_url": "http://127.0.0.1/nfcpay/user/transaction/success",
"cancel_url": "http://127.0.0.1/nfcpay/user/transaction/cancel"
}
},
"type": "success"
}
**Response: ERROR (400 FAILED)**
{
"message": {
"error": [
"Invalid token."
]
},
"data": null,
"type": "error"
}