Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F94051090
PhortuneAccountBillingController.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Dec 3, 12:45
Size
4 KB
Mime Type
text/x-php
Expires
Thu, Dec 5, 12:45 (2 d)
Engine
blob
Format
Raw Data
Handle
22724092
Attached To
rPH Phabricator
PhortuneAccountBillingController.php
View Options
<?php
final
class
PhortuneAccountBillingController
extends
PhortuneAccountProfileController
{
public
function
handleRequest
(
AphrontRequest
$request
)
{
$response
=
$this
->
loadAccount
();
if
(
$response
)
{
return
$response
;
}
$account
=
$this
->
getAccount
();
$title
=
$account
->
getName
();
$crumbs
=
$this
->
buildApplicationCrumbs
();
$crumbs
->
addTextCrumb
(
pht
(
'Billing'
));
$header
=
$this
->
buildHeaderView
();
$methods
=
$this
->
buildPaymentMethodsSection
(
$account
);
$charge_history
=
$this
->
buildChargeHistorySection
(
$account
);
$view
=
id
(
new
PHUITwoColumnView
())
->
setHeader
(
$header
)
->
setFooter
(
array
(
$methods
,
$charge_history
,
));
$navigation
=
$this
->
buildSideNavView
(
'billing'
);
return
$this
->
newPage
()
->
setTitle
(
$title
)
->
setCrumbs
(
$crumbs
)
->
setNavigation
(
$navigation
)
->
appendChild
(
$view
);
}
private
function
buildPaymentMethodsSection
(
PhortuneAccount
$account
)
{
$viewer
=
$this
->
getViewer
();
$can_edit
=
PhabricatorPolicyFilter
::
hasCapability
(
$viewer
,
$account
,
PhabricatorPolicyCapability
::
CAN_EDIT
);
$id
=
$account
->
getID
();
// TODO: Allow adding a card here directly
$add
=
id
(
new
PHUIButtonView
())
->
setTag
(
'a'
)
->
setText
(
pht
(
'New Payment Method'
))
->
setIcon
(
'fa-plus'
)
->
setHref
(
$this
->
getApplicationURI
(
"{$id}/card/new/"
));
$header
=
id
(
new
PHUIHeaderView
())
->
setHeader
(
pht
(
'Payment Methods'
));
$list
=
id
(
new
PHUIObjectItemListView
())
->
setUser
(
$viewer
)
->
setFlush
(
true
)
->
setNoDataString
(
pht
(
'No payment methods associated with this account.'
));
$methods
=
id
(
new
PhortunePaymentMethodQuery
())
->
setViewer
(
$viewer
)
->
withAccountPHIDs
(
array
(
$account
->
getPHID
()))
->
withStatuses
(
array
(
PhortunePaymentMethod
::
STATUS_ACTIVE
,
))
->
execute
();
foreach
(
$methods
as
$method
)
{
$id
=
$method
->
getID
();
$item
=
new
PHUIObjectItemView
();
$item
->
setHeader
(
$method
->
getFullDisplayName
());
switch
(
$method
->
getStatus
())
{
case
PhortunePaymentMethod
::
STATUS_ACTIVE
:
$item
->
setStatusIcon
(
'fa-check green'
);
$disable_uri
=
$this
->
getApplicationURI
(
'card/'
.
$id
.
'/disable/'
);
$item
->
addAction
(
id
(
new
PHUIListItemView
())
->
setIcon
(
'fa-times'
)
->
setHref
(
$disable_uri
)
->
setDisabled
(!
$can_edit
)
->
setWorkflow
(
true
));
break
;
case
PhortunePaymentMethod
::
STATUS_DISABLED
:
$item
->
setStatusIcon
(
'fa-ban lightbluetext'
);
$item
->
setDisabled
(
true
);
break
;
}
$provider
=
$method
->
buildPaymentProvider
();
$item
->
addAttribute
(
$provider
->
getPaymentMethodProviderDescription
());
$edit_uri
=
$this
->
getApplicationURI
(
'card/'
.
$id
.
'/edit/'
);
$item
->
addAction
(
id
(
new
PHUIListItemView
())
->
setIcon
(
'fa-pencil'
)
->
setHref
(
$edit_uri
)
->
setDisabled
(!
$can_edit
)
->
setWorkflow
(!
$can_edit
));
$list
->
addItem
(
$item
);
}
return
id
(
new
PHUIObjectBoxView
())
->
setHeader
(
$header
)
->
setBackground
(
PHUIObjectBoxView
::
BLUE_PROPERTY
)
->
setObjectList
(
$list
);
}
private
function
buildChargeHistorySection
(
PhortuneAccount
$account
)
{
$viewer
=
$this
->
getViewer
();
$charges
=
id
(
new
PhortuneChargeQuery
())
->
setViewer
(
$viewer
)
->
withAccountPHIDs
(
array
(
$account
->
getPHID
()))
->
needCarts
(
true
)
->
setLimit
(
10
)
->
execute
();
$phids
=
array
();
foreach
(
$charges
as
$charge
)
{
$phids
[]
=
$charge
->
getProviderPHID
();
$phids
[]
=
$charge
->
getCartPHID
();
$phids
[]
=
$charge
->
getMerchantPHID
();
$phids
[]
=
$charge
->
getPaymentMethodPHID
();
}
$handles
=
$this
->
loadViewerHandles
(
$phids
);
$charges_uri
=
$this
->
getApplicationURI
(
$account
->
getID
().
'/charge/'
);
$table
=
id
(
new
PhortuneChargeTableView
())
->
setUser
(
$viewer
)
->
setCharges
(
$charges
)
->
setHandles
(
$handles
);
$header
=
id
(
new
PHUIHeaderView
())
->
setHeader
(
pht
(
'Charge History'
))
->
addActionLink
(
id
(
new
PHUIButtonView
())
->
setTag
(
'a'
)
->
setIcon
(
'fa-list'
)
->
setHref
(
$charges_uri
)
->
setText
(
pht
(
'View All Charges'
)));
return
id
(
new
PHUIObjectBoxView
())
->
setHeader
(
$header
)
->
setBackground
(
PHUIObjectBoxView
::
BLUE_PROPERTY
)
->
setTable
(
$table
);
}
}
Event Timeline
Log In to Comment