<?php
namespace App\Models\Admin;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Currency extends Model
{
use HasFactory;
protected $guarded = ['id'];
protected $appends = [
'both',
'senderCurrency',
'receiverCurrency',
'editData',
];
protected $casts = [
'admin_id' => 'integer',
'country' => 'string',
'name' => 'string',
'code' => 'string',
'symbol' => 'string',
'flag' => 'string',
'rate' => 'decimal:16',
'sender' => 'integer',
'receiver' => 'integer',
'default' => 'integer',
'status' => 'integer',
'created_at' => 'date:Y-m-d',
'updated_at' => 'date:Y-m-d',
];
public function getBothAttribute() {
if($this->sender == true && $this->receiver == true) {
return true;
}
return false;
}
public function getSenderCurrencyAttribute() {
if($this->sender == true) {
return true;
}
return false;
}
public function getReceiverCurrencyAttribute() {
if($this->receiver == true) {
return true;
}
return false;
}
public function getEditDataAttribute() {
$role = "";
if($this->sender == true && $this->receiver == true) {
$role = "both";
}else if($this->sender == true && $this->receiver == false) {
$role = "sender";
}else if($this->receiver == true && $this->sender == false) {
$role = "receiver";
}
$data = [
'name' => $this->name,
'code' => $this->code,
'flag' => $this->flag,
'role' => $role,
'option' => ($this->default == true) ? 1 : 0,
'symbol' => $this->symbol,
'type' => $this->type,
'rate' => get_amount($this->rate),
'country' => $this->country,
];
return json_encode($data);
}
public function scopeDefault() {
return $this->where('default',true)->first() ?? false;
}
public function isDefault() {
if($this->default == true) return true;
return false;
}
public function scopeSearch($query,$text) {
$query->where(function($q) use ($text) {
$q->where("country","like","%".$text."%");
})->orWhere("name","like","%".$text."%")->orWhere("code","like","%".$text."%");
}
public function scopeActive($query) {
return $query->where("status",true);
}
public function scopeSender($query) {
return $query->where("sender",true);
}
public function scopeReceiver($query) {
return $query->where("receiver",true);
}
public function scopeRoleBoth($query) {
return $query->where("sender",true)->where('receiver',true);
}
public function scopeRoleHasOne($query) {
return $query->where(function($q) {
$q->where('sender',true);
})->orWhere('receiver',true);
}
public function getCurrencyCodeAttribute() {
return $this->code;
}
}
Get access token to initiates payment transaction.
generate-token
| Parameter | Type | Comments |
|---|---|---|
| client_id | string | Enter merchant API client/primary key |
| secret_id | string | Enter merchant API secret key |
| env | string | Enter merchant API environment |
| merchant_id | string | Enter merchant API merchant id |
Request Example (guzzle)
<?php
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', $base_url. 'v1/generate-token', [
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
],
'form_params' => [
'client_id' => '$client_id',
'secret_id' => 'secret_id',
'env' => 'env',
'merchant_id' => 'merchant_id',
],
]);
echo $response->getBody();
**Response: SUCCESS (200 OK)**
{
"message": {
"success": [
"Successfully token is generated"
]
},
"data": {
"token":"eyJpdiI6InpkczhjTjhQdVhUL2lKQ0pSUUx6aUE9PSIsInZhbHVlIjoiVGVBTVBDTXltbjNZcEIvdEJveGpTSno3TU5NRUtnVkhCZ1pHTFNCUnZGQ2UxMnYxN202cEE1YVRDTEFsc0ZERExoTjdtL0dTL2xoU3QzeUJJOExiMUx5T0w1L0llUXhTUkU1cWVLWEdEbEplb0dKNXcwbTNRM0VxdkUwYzZuNFdtNkhMQ0pRZysyNWkvdzBxSlBoSVBSOGFTekNnR2RXNHVtcG9lMGZOTmNCcm1hR3c5Sk9KTnB4Y3ltZDl6cm90MThrR21Ca3B1azc3bXRiQ0J6SW96UVo1elNkU1ZqeE05bTcwWGp1MEUxWlJFdnNWTmpSbnVpeW92b2U4dXZkUGgyb1VmK0luaGdyaFlsVTZlcVpVRnZlTG1DeFF6Ykk2T2h6Z3JzbnIyNHpNdHowSE5JdDR0Y0pZT20zUm1XYW8iLCJtYWMiOiJlY2M4NGE1OGUzYzkzYzk0YzljNmVmNjE0YWI0ZDIwOGI3NDQ2YWEyY2ZhNzc0NzE4ZmY1ZmYyMz
IyZmQzNDY1IiwidGFnIjoiIn0=",
},
"type": "success"
}
**Response: ERROR (400 FAILED)**
{
"message": {
"error": [
"Invalid credentials."
]
},
"data": null,
"type": "error"
}