1. Go to this page and download the library: Download agro-zamin/integration library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Integration\Example\Request;
use AgroZamin\Integrations\RequestModel;
use App\Integration\Example\DTO\OrderDTO;
class GetOrder extends RequestModel {
private array $_queryParams = [];
/**
* @return string
*/
public function requestMethod(): string {
return 'GET';
}
/**
* @return string
*/
public function url(): string {
return 'https://example.com/api/get-order';
}
/**
* @return array
*/
public function queryParams(): array {
return $this->_queryParams;
}
/**
* @param array $data
*
* @return OrganizationDTO
*/
public function buildDto(array $data): OrderDTO {
return new OrderDTO($data['body']['Order']);
}
/**
* @param int $id
*
* @return $this
*/
public function byId(int $id): static {
$this->_queryParams['id'] = $id;
return $this;
}
}
namespace App\Integration\Example\DTO;
use AgroZamin\Integrations\DTO;
class OrderDTO extends DTO {
public int $id;
public float $amount;
public float $discount;
public array $products = [];
/**
* @return array[]
*/
protected function properties(): array {
return [
'products' => [[ProductDTO::class], 'products']
];
}
}
namespace App\Integration\Example\DTO;
use AgroZamin\Integrations\DTO;
class ProductDTO extends DTO {
public int $id;
public string $title;
public ImageDTO $cover;
public float $amount;
public string|null $description = null;
/**
* @return array[]
*/
protected function properties(): array {
return [
'cover' => [ImageDTO::class, 'cover']
];
}
}
namespace App\Integration\Example\DTO;
use AgroZamin\Integrations\DTO;
class ImageDTO extends DTO {
public string $thumbnail;
public string $original;
}
use App\Integration\Example\Example;
use App\Integration\Example\Request\GetOrder;
use App\Integration\Example\DTO\OrderDTO;
use GuzzleHttp\Client;
$exampleService = new Example('ABC...', new Client());
$orderId = 1872;
/** @var OrderDTO $orderDTO */
$orderDTO = $exampleService->requestModel((new GetOrder())->byId($orderId))->sendRequest();
// code
php composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.