src/UrlManager.php
<?php
namespace tuyakhov\braintree;
use Yii;
/**
* Class UrlManager.
* Provides methods for creating of URLs to Braintree.
* Usage:
*
* ```php
* Yii::$app->braintree->urlManager->viewPlans();
* ```
* @package tuyakhov\braintree
*/
class UrlManager
{
/**
* @var string base URL
*/
protected $baseUrl;
/**
* Get base URL.
* @return string base URL.
*/
public function getBaseUrl(): string
{
if (!isset($this->baseUrl)) {
/** @var Braintree $braintree */
$braintree = Yii::$app->get('braintree');
$domain = 'braintreegateway.com';
if ($braintree->environment === 'sandbox') {
$domain = "sandbox.$domain";
} else {
$domain = "www.$domain";
}
$this->baseUrl = "https://$domain/merchants/$braintree->merchantId/";
}
return $this->baseUrl;
}
/**
* Get URL of page on which user can view all plans.
* @return string URL of page on which user can view all plans.
*/
public function viewPlans(): string
{
return $this->getBaseUrl() . 'plans';
}
/**
* Get URL of page on which user can view specified plan.
* @param string $planId plan id
* @return string URL of page on which user can view specified plan.
*/
public function viewPlan(string $planId): string
{
return $this->getBaseUrl() . "plans/$planId";
}
/**
* Get URL of page on which user can create plan.
* @return string URL of page on which user can create plan.
*/
public function createPlan(): string
{
return $this->getBaseUrl() . 'plans/new';
}
/**
* Get URL of page on which user can update plan.
* @param string $planId plan id
* @return string URL of page on which user can update plan.
*/
public function updatePlan(string $planId): string
{
return $this->getBaseUrl() . "plans/$planId/edit";
}
}