@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

Disable Phortune Paypal payment provider

Summary:
Ref T2787. For test charges, Paypal is putting the charge in a "payment review" state. Dealing with this state requires way more infrastructure than other providers: we're supposed to pause delivery, then poll Paypal every 6 hours to see if the review has resolved.

Since I can't seem to generate normal test charges, I can't test Paypal for now. Disable it until we have more infrastructure.

(This diff gets us further along, up to the point where I hit this issue.)

Test Plan: Read documentation, rolled eyes.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2787

Differential Revision: https://secure.phabricator.com/D10644

+110 -20
+14
src/applications/phortune/controller/PhortuneProviderController.php
··· 71 71 ->executeOne(); 72 72 } 73 73 74 + public function loadActiveCharge(PhortuneCart $cart) { 75 + $request = $this->getRequest(); 76 + $viewer = $request->getUser(); 77 + 78 + return id(new PhortuneChargeQuery()) 79 + ->setViewer($viewer) 80 + ->withCartPHIDs(array($cart->getPHID())) 81 + ->withStatuses( 82 + array( 83 + PhortuneCharge::STATUS_CHARGING, 84 + )) 85 + ->executeOne(); 86 + } 87 + 74 88 }
+95 -11
src/applications/phortune/provider/PhortunePaypalPaymentProvider.php
··· 3 3 final class PhortunePaypalPaymentProvider extends PhortunePaymentProvider { 4 4 5 5 public function isEnabled() { 6 + // TODO: See note in processControllerRequest(). 7 + return false; 8 + 6 9 return $this->getPaypalAPIUsername() && 7 10 $this->getPaypalAPIPassword() && 8 11 $this->getPaypalAPISignature(); ··· 74 77 PhortuneProviderController $controller, 75 78 AphrontRequest $request) { 76 79 80 + $viewer = $request->getUser(); 81 + 77 82 $cart = $controller->loadCart($request->getInt('cartID')); 78 83 if (!$cart) { 79 84 return new Aphront404Response(); 80 85 } 81 86 87 + $charge = $controller->loadActiveCharge($cart); 88 + switch ($controller->getAction()) { 89 + case 'checkout': 90 + if ($charge) { 91 + throw new Exception(pht('Cart is already charging!')); 92 + } 93 + break; 94 + case 'charge': 95 + case 'cancel': 96 + if (!$charge) { 97 + throw new Exception(pht('Cart is not charging yet!')); 98 + } 99 + break; 100 + } 101 + 82 102 switch ($controller->getAction()) { 83 103 case 'checkout': 84 104 $return_uri = $this->getControllerURI( ··· 95 115 96 116 $price = $cart->getTotalPriceAsCurrency(); 97 117 118 + $charge = $cart->willApplyCharge($viewer, $this); 119 + 120 + $params = array( 121 + 'PAYMENTREQUEST_0_AMT' => $price->formatBareValue(), 122 + 'PAYMENTREQUEST_0_CURRENCYCODE' => $price->getCurrency(), 123 + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', 124 + 'PAYMENTREQUEST_0_CUSTOM' => $charge->getPHID(), 125 + 126 + 'RETURNURL' => $return_uri, 127 + 'CANCELURL' => $cancel_uri, 128 + 129 + // TODO: This should be cart-dependent if we eventually support 130 + // physical goods. 131 + 'NOSHIPPING' => '1', 132 + ); 133 + 98 134 $result = $this 99 135 ->newPaypalAPICall() 100 - ->setRawPayPalQuery( 101 - 'SetExpressCheckout', 102 - array( 103 - 'PAYMENTREQUEST_0_AMT' => $price->formatBareValue(), 104 - 'PAYMENTREQUEST_0_CURRENCYCODE' => $price->getCurrency(), 105 - 'RETURNURL' => $return_uri, 106 - 'CANCELURL' => $cancel_uri, 107 - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', 108 - )) 136 + ->setRawPayPalQuery('SetExpressCheckout', $params) 109 137 ->resolve(); 110 138 111 139 $uri = new PhutilURI('https://www.sandbox.paypal.com/cgi-bin/webscr'); ··· 115 143 'token' => $result['TOKEN'], 116 144 )); 117 145 146 + $cart->setMetadataValue('provider.checkoutURI', $uri); 147 + $cart->save(); 148 + 149 + $charge->setMetadataValue('paypal.token', $result['TOKEN']); 150 + $charge->save(); 151 + 118 152 return id(new AphrontRedirectResponse()) 119 153 ->setIsExternal(true) 120 154 ->setURI($uri); 121 155 case 'charge': 122 - var_dump($_REQUEST); 156 + $token = $request->getStr('token'); 157 + 158 + $params = array( 159 + 'TOKEN' => $token, 160 + ); 161 + 162 + $result = $this 163 + ->newPaypalAPICall() 164 + ->setRawPayPalQuery('GetExpressCheckoutDetails', $params) 165 + ->resolve(); 166 + 167 + var_dump($result); 168 + 169 + if ($result['CUSTOM'] !== $charge->getPHID()) { 170 + throw new Exception( 171 + pht('Paypal checkout does not match Phortune charge!')); 172 + } 173 + 174 + if ($result['CHECKOUTSTATUS'] !== 'PaymentActionNotInitiated') { 175 + throw new Exception( 176 + pht( 177 + 'Expected status "%s", got "%s".', 178 + 'PaymentActionNotInitiated', 179 + $result['CHECKOUTSTATUS'])); 180 + } 181 + 182 + $price = $cart->getTotalPriceAsCurrency(); 183 + 184 + $params = array( 185 + 'TOKEN' => $token, 186 + 'PAYERID' => $result['PAYERID'], 187 + 188 + 'PAYMENTREQUEST_0_AMT' => $price->formatBareValue(), 189 + 'PAYMENTREQUEST_0_CURRENCYCODE' => $price->getCurrency(), 190 + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', 191 + ); 192 + 193 + $result = $this 194 + ->newPaypalAPICall() 195 + ->setRawPayPalQuery('DoExpressCheckoutPayment', $params) 196 + ->resolve(); 197 + 198 + // TODO: Paypal can send requests back in "PaymentReview" status, 199 + // and does this for test transactions. We're supposed to hold 200 + // the transaction and poll the API every 6 hours. This is unreasonably 201 + // difficult for now and we can't reasonably just fail these charges. 202 + 203 + var_dump($result); 204 + 205 + die(); 123 206 break; 124 207 case 'cancel': 125 208 var_dump($_REQUEST); 126 209 break; 127 210 } 128 211 129 - throw new Exception("The rest of this isn't implemented yet."); 212 + throw new Exception( 213 + pht('Unsupported action "%s".', $controller->getAction())); 130 214 } 131 215 132 216 private function newPaypalAPICall() {
+1 -9
src/applications/phortune/provider/PhortuneWePayPaymentProvider.php
··· 100 100 101 101 $wepay = new WePay($this->getWePayAccessToken()); 102 102 103 - $charge = id(new PhortuneChargeQuery()) 104 - ->setViewer($viewer) 105 - ->withCartPHIDs(array($cart->getPHID())) 106 - ->withStatuses( 107 - array( 108 - PhortuneCharge::STATUS_CHARGING, 109 - )) 110 - ->executeOne(); 111 - 103 + $charge = $controller->loadActiveCharge($cart); 112 104 switch ($controller->getAction()) { 113 105 case 'checkout': 114 106 if ($charge) {