Files
YeePay/lib/Service/TravelResources/TravelResourcesClientBuilder.php

74 lines
2.6 KiB
PHP

<?php
namespace Yeepay\Yop\Sdk\Service\TravelResources;
use Yeepay\Yop\Sdk\Auth\AuthorityReqRegistryImpl;
use Yeepay\Yop\Sdk\Auth\AuthorizationReqRegistry;
use Yeepay\Yop\Sdk\Auth\AuthorizationReqSupport;
use Yeepay\Yop\Sdk\Client\ClientParams;
use Yeepay\Yop\Sdk\Client\Support\ClientParamsSupport;
use Yeepay\Yop\Sdk\Config\AppSdkConfig;
use Yeepay\Yop\Sdk\Config\AppSdkConfigProvider;
use Yeepay\Yop\Sdk\Config\DefaultAppSdkConfigProvider;
use Yeepay\Yop\Sdk\Exception\YopClientException;
class TravelResourcesClientBuilder
{
/**
* @var AuthorizationReqRegistry
*/
private static $authorizationReqRegistry;
public static function __init()
{
self::$authorizationReqRegistry = new AuthorityReqRegistryImpl();
self::$authorizationReqRegistry->register('createOrder', AuthorizationReqSupport::getAuthorizationReq('YOP-RSA2048-SHA256'));
self::$authorizationReqRegistry->register('kfcOrder', AuthorizationReqSupport::getAuthorizationReq('YOP-RSA2048-SHA256'));
self::$authorizationReqRegistry->register('kfcOrder_0', AuthorizationReqSupport::getAuthorizationReq('YOP-RSA2048-SHA256'));
self::$authorizationReqRegistry->register('queryCinemaOrder', AuthorizationReqSupport::getAuthorizationReq('YOP-RSA2048-SHA256'));
self::$authorizationReqRegistry->register('queryKfcOrder', AuthorizationReqSupport::getAuthorizationReq('YOP-RSA2048-SHA256'));
self::$authorizationReqRegistry->register('queryOrder', AuthorizationReqSupport::getAuthorizationReq('YOP-RSA2048-SHA256'));
}
/**
* @var ClientParams
*/
private $clientParams;
/**
* TravelResourcesClientBuilder constructor.
* @param ClientParams $clientParams
*/
public function __construct(ClientParams $clientParams)
{
$this->clientParams = $clientParams;
}
public function build()
{
return new TravelResourcesClient($this->clientParams);
}
/**
* @param $config AppSdkConfig|array|AppSdkConfigProvider
* @return TravelResourcesClientBuilder
* @throws YopClientException
*/
public static function builder($config)
{
$appSdkConfigProvider = null;
if ($config instanceof AppSdkConfigProvider) {
$appSdkConfigProvider = $config;
} else {
$appSdkConfigProvider = new DefaultAppSdkConfigProvider($config);
}
$clientParams = ClientParamsSupport::generateClientParams($appSdkConfigProvider);
$clientParams->setAuthorizationReqRegistry(self::$authorizationReqRegistry);
return new TravelResourcesClientBuilder($clientParams);
}
}
TravelResourcesClientBuilder::__init();