Skip to content

AGS Platform - Line Item service server

How to use the line item service server handlers (with the core LtiServiceServer) to provide authenticated AGS endpoints for line item management as a platform.

Features

This library provides a set of line item service server handlers ready to be use with the core LtiServiceServer to handle line item management requests.

They allow you to provide line item management service endpoints as specified in AGS openapi documentation.

Usage

You can find below how to use each AGS service server request handlers to provide line item service endpoints.

Get line item service endpoint

First, you need to provide a LineItemRepositoryInterface implementation, in charge to handle line items, as explained in the interfaces library documentation.

Then:

<?php

use OAT\Library\Lti1p3Ags\Repository\LineItemRepositoryInterface;
use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\GetLineItemServiceServerRequestHandler;
use OAT\Library\Lti1p3Core\Registration\RegistrationRepositoryInterface;
use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidator;
use OAT\Library\Lti1p3Core\Service\Server\LtiServiceServer;
use Psr\Http\Message\ServerRequestInterface;

/** @var ServerRequestInterface $request */
$request = ...

/** @var RegistrationRepositoryInterface $registrationRepository */
$registrationRepository = ...

/** @var LineItemRepositoryInterface $lineItemRepository */
$lineItemRepository = ...

$validator = new RequestAccessTokenValidator($registrationRepository);

$handler = new GetLineItemServiceServerRequestHandler($lineItemRepository);

$server = new LtiServiceServer($validator, $handler);

// Generates an authenticated response containing the requested line item representation
$response = $server->handle($request);

List line items service endpoint

First, you need to provide a LineItemRepositoryInterface implementation, in charge to handle line items, as explained in the interfaces library documentation.

Then:

<?php

use OAT\Library\Lti1p3Ags\Repository\LineItemRepositoryInterface;
use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\ListLineItemsServiceServerRequestHandler;
use OAT\Library\Lti1p3Core\Registration\RegistrationRepositoryInterface;
use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidator;
use OAT\Library\Lti1p3Core\Service\Server\LtiServiceServer;
use Psr\Http\Message\ServerRequestInterface;

/** @var ServerRequestInterface $request */
$request = ...

/** @var RegistrationRepositoryInterface $registrationRepository */
$registrationRepository = ...

/** @var LineItemRepositoryInterface $lineItemRepository */
$lineItemRepository = ...

$validator = new RequestAccessTokenValidator($registrationRepository);

$handler = new ListLineItemsServiceServerRequestHandler($lineItemRepository);

$server = new LtiServiceServer($validator, $handler);

// Generates an authenticated response containing the requested line item list representation
$response = $server->handle($request);

Create line item service endpoint

First, you need to provide a LineItemRepositoryInterface implementation, in charge to handle line items, as explained in the interfaces library documentation.

Then:

<?php

use OAT\Library\Lti1p3Ags\Repository\LineItemRepositoryInterface;
use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\CreateLineItemServiceServerRequestHandler;
use OAT\Library\Lti1p3Core\Registration\RegistrationRepositoryInterface;
use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidator;
use OAT\Library\Lti1p3Core\Service\Server\LtiServiceServer;
use Psr\Http\Message\ServerRequestInterface;

/** @var ServerRequestInterface $request */
$request = ...

/** @var RegistrationRepositoryInterface $registrationRepository */
$registrationRepository = ...

/** @var LineItemRepositoryInterface $lineItemRepository */
$lineItemRepository = ...

$validator = new RequestAccessTokenValidator($registrationRepository);

$handler = new CreateLineItemServiceServerRequestHandler($lineItemRepository);

$server = new LtiServiceServer($validator, $handler);

// Generates an authenticated response containing the line item creation response
$response = $server->handle($request);

Update line item service endpoint

First, you need to provide a LineItemRepositoryInterface implementation, in charge to handle line items, as explained in the interfaces library documentation.

Then:

<?php

use OAT\Library\Lti1p3Ags\Repository\LineItemRepositoryInterface;
use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\UpdateLineItemServiceServerRequestHandler;
use OAT\Library\Lti1p3Core\Registration\RegistrationRepositoryInterface;
use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidator;
use OAT\Library\Lti1p3Core\Service\Server\LtiServiceServer;
use Psr\Http\Message\ServerRequestInterface;

/** @var ServerRequestInterface $request */
$request = ...

/** @var RegistrationRepositoryInterface $registrationRepository */
$registrationRepository = ...

/** @var LineItemRepositoryInterface $lineItemRepository */
$lineItemRepository = ...

$validator = new RequestAccessTokenValidator($registrationRepository);

$handler = new UpdateLineItemServiceServerRequestHandler($lineItemRepository);

$server = new LtiServiceServer($validator, $handler);

// Generates an authenticated response containing the line item update response
$response = $server->handle($request);

Delete line item service endpoint

First, you need to provide a LineItemRepositoryInterface implementation, in charge to handle line items, as explained in the interfaces library documentation.

Then:

<?php

use OAT\Library\Lti1p3Ags\Repository\LineItemRepositoryInterface;
use OAT\Library\Lti1p3Ags\Service\LineItem\Server\Handler\DeleteLineItemServiceServerRequestHandler;
use OAT\Library\Lti1p3Core\Registration\RegistrationRepositoryInterface;
use OAT\Library\Lti1p3Core\Security\OAuth2\Validator\RequestAccessTokenValidator;
use OAT\Library\Lti1p3Core\Service\Server\LtiServiceServer;
use Psr\Http\Message\ServerRequestInterface;

/** @var ServerRequestInterface $request */
$request = ...

/** @var RegistrationRepositoryInterface $registrationRepository */
$registrationRepository = ...

/** @var LineItemRepositoryInterface $lineItemRepository */
$lineItemRepository = ...

$validator = new RequestAccessTokenValidator($registrationRepository);

$handler = new DeleteLineItemServiceServerRequestHandler($lineItemRepository);

$server = new LtiServiceServer($validator, $handler);

// Generates an authenticated response containing the line item deletion response
$response = $server->handle($request);