|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace tuyakhov\braintree; |
|
4
|
|
|
|
|
5
|
|
|
use Yii; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class UrlManager. |
|
9
|
|
|
* Provides methods for creating of URLs to Braintree. |
|
10
|
|
|
* Usage: |
|
11
|
|
|
* |
|
12
|
|
|
* ```php |
|
13
|
|
|
* Yii::$app->braintree->urlManager->viewPlans(); |
|
14
|
|
|
* ``` |
|
15
|
|
|
* @package tuyakhov\braintree |
|
16
|
|
|
*/ |
|
17
|
|
|
class UrlManager |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var string base URL |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $baseUrl; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Get base URL. |
|
26
|
|
|
* @return string base URL. |
|
27
|
|
|
*/ |
|
28
|
1 |
|
public function getBaseUrl(): string |
|
29
|
|
|
{ |
|
30
|
1 |
|
if (!isset($this->baseUrl)) { |
|
31
|
|
|
/** @var Braintree $braintree */ |
|
32
|
1 |
|
$braintree = Yii::$app->get('braintree'); |
|
33
|
1 |
|
$domain = 'braintreegateway.com'; |
|
34
|
1 |
|
if ($braintree->environment === 'sandbox') { |
|
35
|
1 |
|
$domain = "sandbox.$domain"; |
|
36
|
|
|
} else { |
|
37
|
|
|
$domain = "www.$domain"; |
|
38
|
|
|
} |
|
39
|
1 |
|
$this->baseUrl = "https://$domain/merchants/$braintree->merchantId/"; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
return $this->baseUrl; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get URL of page on which user can view all plans. |
|
47
|
|
|
* @return string URL of page on which user can view all plans. |
|
48
|
|
|
*/ |
|
49
|
|
|
public function viewPlans(): string |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->getBaseUrl() . 'plans'; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get URL of page on which user can view specified plan. |
|
56
|
|
|
* @param string $planId plan id |
|
57
|
|
|
* @return string URL of page on which user can view specified plan. |
|
58
|
|
|
*/ |
|
59
|
|
|
public function viewPlan(string $planId): string |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->getBaseUrl() . "plans/$planId"; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get URL of page on which user can create plan. |
|
66
|
|
|
* @return string URL of page on which user can create plan. |
|
67
|
|
|
*/ |
|
68
|
|
|
public function createPlan(): string |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->getBaseUrl() . 'plans/new'; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get URL of page on which user can update plan. |
|
75
|
|
|
* @param string $planId plan id |
|
76
|
|
|
* @return string URL of page on which user can update plan. |
|
77
|
|
|
*/ |
|
78
|
1 |
|
public function updatePlan(string $planId): string |
|
79
|
|
|
{ |
|
80
|
1 |
|
return $this->getBaseUrl() . "plans/$planId/edit"; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|