# Mobilní platby

# Content

# Usage

# Custom dispatcher

<?php declare(strict_types = 1);

namespace Your\App;

use Contributte\MobilniPlatby\IDispatcher;
use Contributte\MobilniPlatby\Request\AbstractRequest;
use Contributte\MobilniPlatby\Response\AbstractResponse;
use Contributte\MobilniPlatby\Response\Response;

class TestDispatcher implements IDispatcher
{

	public function dispatch(AbstractRequest $request): AbstractResponse
	{
		return new Response('This is super!');
	}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# Example presenter

<?php declare(strict_types = 1);

namespace Your\App\Presenters;

use Contributte\MobilniPlatby\Dispatcher\CallbackDispatcher;
use Contributte\MobilniPlatby\Request\ConfirmRequest;
use Contributte\MobilniPlatby\Request\RequestFactory;
use Contributte\MobilniPlatby\Request\SmsRequest;
use Contributte\MobilniPlatby\Response\AbstractResponse;
use Contributte\MobilniPlatby\Response\ConfirmResponse;
use Contributte\MobilniPlatby\Response\Response;
use Nette\Application\UI\Presenter;

class SmsPresenter extends Presenter
{

	public function actionSms1(): void
	{
		$requestFactory = new RequestFactory($this->getHttpRequest());

		$dispatcher = new TestDispatcher();

		$this->sendResponse($dispatcher->dispatch($requestFactory->create()));
	}

	public function actionSms2(): void
	{
		$requestFactory = new RequestFactory($this->getHttpRequest());

		$dispatcher = new CallbackDispatcher();

		$dispatcher->registerSmsCallback(function (SmsRequest $request, Response $response): AbstractResponse {
			return new Response('My response!');
		});

		$dispatcher->registerConfirmCallback(function (ConfirmRequest $request, ConfirmResponse $response) {
			return new ConfirmResponse();
		});
		$this->sendResponse($dispatcher->dispatch($requestFactory->create()));
	}

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43