@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhortunePaymentMethodDisableController
4 extends PhortuneController {
5
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
8 $method_id = $request->getURIData('id');
9
10 $method = id(new PhortunePaymentMethodQuery())
11 ->setViewer($viewer)
12 ->withIDs(array($method_id))
13 ->requireCapabilities(
14 array(
15 PhabricatorPolicyCapability::CAN_VIEW,
16 PhabricatorPolicyCapability::CAN_EDIT,
17 ))
18 ->executeOne();
19 if (!$method) {
20 return new Aphront404Response();
21 }
22
23 if ($method->getStatus() == PhortunePaymentMethod::STATUS_DISABLED) {
24 return new Aphront400Response();
25 }
26
27 $subscription_id = $request->getInt('subscriptionID');
28 if ($subscription_id) {
29 $subscription = id(new PhortuneSubscriptionQuery())
30 ->setViewer($viewer)
31 ->withIDs(array($subscription_id))
32 ->withAccountPHIDs(array($method->getAccountPHID()))
33 ->withMerchantPHIDs(array($method->getMerchantPHID()))
34 ->executeOne();
35 if (!$subscription) {
36 return new Aphront404Response();
37 }
38 } else {
39 $subscription = null;
40 }
41
42 $account = $method->getAccount();
43 $account_id = $account->getID();
44 $account_uri = $account->getPaymentMethodsURI();
45
46 if ($request->isFormPost()) {
47 $xactions = array();
48
49 $xactions[] = $method->getApplicationTransactionTemplate()
50 ->setTransactionType(
51 PhortunePaymentMethodStatusTransaction::TRANSACTIONTYPE)
52 ->setNewValue(PhortunePaymentMethod::STATUS_DISABLED);
53
54 $editor = id(new PhortunePaymentMethodEditor())
55 ->setActor($viewer)
56 ->setContentSourceFromRequest($request)
57 ->setContinueOnNoEffect(true)
58 ->setContinueOnMissingFields(true);
59
60 $editor->applyTransactions($method, $xactions);
61
62 if ($subscription) {
63 $next_uri = $subscription->getURI();
64 } else {
65 $next_uri = $account_uri;
66 }
67
68 return id(new AphrontRedirectResponse())->setURI($next_uri);
69 }
70
71 $method_phid = $method->getPHID();
72 $handles = $viewer->loadHandles(
73 array(
74 $method_phid,
75 ));
76
77 $method_handle = $handles[$method_phid];
78 $method_display = $method_handle->renderLink();
79 $method_display = phutil_tag('strong', array(), $method_display);
80
81 return $this->newDialog()
82 ->setTitle(pht('Remove Payment Method'))
83 ->addHiddenInput('subscriptionID', $subscription_id)
84 ->appendParagraph(
85 pht(
86 'Remove the payment method %s from your account?',
87 $method_display))
88 ->appendParagraph(
89 pht(
90 'You will no longer be able to make payments using this payment '.
91 'method.'))
92 ->addCancelButton($account_uri)
93 ->addSubmitButton(pht('Remove Payment Method'));
94 }
95
96}