forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhortuneController.php
113 lines (90 loc) · 2.7 KB
/
PhortuneController.php
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
abstract class PhortuneController extends PhabricatorController {
protected function addAccountCrumb(
$crumbs,
PhortuneAccount $account,
$link = true) {
$name = $account->getName();
$href = null;
if ($link) {
$href = $this->getApplicationURI($account->getID().'/');
$crumbs->addTextCrumb($name, $href);
} else {
$crumbs->addTextCrumb($name);
}
}
protected function addMerchantCrumb(
$crumbs,
PhortuneMerchant $merchant,
$link = true) {
$name = $merchant->getName();
$href = null;
$crumbs->addTextCrumb(
pht('Merchants'),
$this->getApplicationURI('merchant/'));
if ($link) {
$href = $this->getApplicationURI('merchant/'.$merchant->getID().'/');
$crumbs->addTextCrumb($name, $href);
} else {
$crumbs->addTextCrumb($name);
}
}
private function loadEnabledProvidersForMerchant(PhortuneMerchant $merchant) {
$viewer = $this->getRequest()->getUser();
$provider_configs = id(new PhortunePaymentProviderConfigQuery())
->setViewer($viewer)
->withMerchantPHIDs(array($merchant->getPHID()))
->execute();
$providers = mpull($provider_configs, 'buildProvider', 'getID');
foreach ($providers as $key => $provider) {
if (!$provider->isEnabled()) {
unset($providers[$key]);
}
}
return $providers;
}
protected function loadCreatePaymentMethodProvidersForMerchant(
PhortuneMerchant $merchant) {
$providers = $this->loadEnabledProvidersForMerchant($merchant);
foreach ($providers as $key => $provider) {
if (!$provider->canCreatePaymentMethods()) {
unset($providers[$key]);
continue;
}
}
return $providers;
}
protected function loadOneTimePaymentProvidersForMerchant(
PhortuneMerchant $merchant) {
$providers = $this->loadEnabledProvidersForMerchant($merchant);
foreach ($providers as $key => $provider) {
if (!$provider->canProcessOneTimePayments()) {
unset($providers[$key]);
continue;
}
}
return $providers;
}
protected function loadMerchantAuthority() {
$request = $this->getRequest();
$viewer = $this->getViewer();
$is_merchant = (bool)$request->getURIData('merchantID');
if (!$is_merchant) {
return null;
}
$merchant = id(new PhortuneMerchantQuery())
->setViewer($viewer)
->withIDs(array($request->getURIData('merchantID')))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$merchant) {
return null;
}
$viewer->grantAuthority($merchant);
return $merchant;
}
}