@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 PhortuneCartUpdateController
4 extends PhortuneCartController {
5
6 protected function shouldRequireAccountAuthority() {
7 return false;
8 }
9
10 protected function shouldRequireMerchantAuthority() {
11 return false;
12 }
13
14 protected function handleCartRequest(AphrontRequest $request) {
15 $viewer = $request->getViewer();
16 $id = $request->getURIData('id');
17
18 $cart = $this->getCart();
19 $authority = $this->getMerchantAuthority();
20
21 $charges = id(new PhortuneChargeQuery())
22 ->setViewer($viewer)
23 ->withCartPHIDs(array($cart->getPHID()))
24 ->needCarts(true)
25 ->withStatuses(
26 array(
27 PhortuneCharge::STATUS_HOLD,
28 PhortuneCharge::STATUS_CHARGED,
29 ))
30 ->execute();
31
32 if ($charges) {
33 $providers = id(new PhortunePaymentProviderConfigQuery())
34 ->setViewer($viewer)
35 ->withPHIDs(mpull($charges, 'getProviderPHID'))
36 ->execute();
37 $providers = mpull($providers, null, 'getPHID');
38 } else {
39 $providers = array();
40 }
41
42 foreach ($charges as $charge) {
43 if ($charge->isRefund()) {
44 // Don't update refunds.
45 continue;
46 }
47
48 $provider_config = idx($providers, $charge->getProviderPHID());
49 if (!$provider_config) {
50 throw new Exception(pht('Unable to load provider for charge!'));
51 }
52
53 $provider = $provider_config->buildProvider();
54 $provider->updateCharge($charge);
55 }
56
57 return id(new AphrontRedirectResponse())
58 ->setURI($cart->getDetailURI());
59 }
60
61}