Differential D20132 Diff 48071 src/applications/phortune/controller/payment/PhortunePaymentMethodCreateController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/controller/payment/PhortunePaymentMethodCreateController.php
| Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | if (count($providers) == 1) { | ||||
| ->appendChild($content) | ->appendChild($content) | ||||
| ->addCancelButton($cancel_uri); | ->addCancelButton($cancel_uri); | ||||
| } | } | ||||
| } | } | ||||
| $provider = $providers[$provider_id]; | $provider = $providers[$provider_id]; | ||||
| $errors = array(); | $errors = array(); | ||||
| $display_exception = null; | |||||
| if ($request->isFormPost() && $request->getBool('isProviderForm')) { | if ($request->isFormPost() && $request->getBool('isProviderForm')) { | ||||
| $method = id(new PhortunePaymentMethod()) | $method = id(new PhortunePaymentMethod()) | ||||
| ->setAccountPHID($account->getPHID()) | ->setAccountPHID($account->getPHID()) | ||||
| ->setAuthorPHID($viewer->getPHID()) | ->setAuthorPHID($viewer->getPHID()) | ||||
| ->setMerchantPHID($merchant->getPHID()) | ->setMerchantPHID($merchant->getPHID()) | ||||
| ->setProviderPHID($provider->getProviderConfig()->getPHID()) | ->setProviderPHID($provider->getProviderConfig()->getPHID()) | ||||
| ->setStatus(PhortunePaymentMethod::STATUS_ACTIVE); | ->setStatus(PhortunePaymentMethod::STATUS_ACTIVE); | ||||
| Show All 18 Lines | if ($request->isFormPost() && $request->getBool('isProviderForm')) { | ||||
| if (!$provider->validateCreatePaymentMethodToken($client_token)) { | if (!$provider->validateCreatePaymentMethodToken($client_token)) { | ||||
| $errors[] = pht( | $errors[] = pht( | ||||
| 'There was an error with the payment token submitted by the '. | 'There was an error with the payment token submitted by the '. | ||||
| 'client. Expected a valid dictionary, received: %s.', | 'client. Expected a valid dictionary, received: %s.', | ||||
| $client_token_raw); | $client_token_raw); | ||||
| } | } | ||||
| if (!$errors) { | if (!$errors) { | ||||
| $errors = $provider->createPaymentMethodFromRequest( | try { | ||||
| $provider->createPaymentMethodFromRequest( | |||||
| $request, | $request, | ||||
| $method, | $method, | ||||
| $client_token); | $client_token); | ||||
epriestley: (No other payment method can currently actually raise any errors today -- the "Pile of Wealth"… | |||||
| } catch (PhortuneDisplayException $exception) { | |||||
| $display_exception = $exception; | |||||
| } catch (Exception $ex) { | |||||
| $errors = array( | |||||
| pht('There was an error adding this payment method:'), | |||||
| $ex->getMessage(), | |||||
| ); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| if (!$errors) { | if (!$errors && !$display_exception) { | ||||
| $method->save(); | $method->save(); | ||||
| // If we added this method on a cart flow, return to the cart to | // If we added this method on a cart flow, return to the cart to | ||||
| // check out. | // check out. | ||||
| if ($cart_id) { | if ($cart_id) { | ||||
| $next_uri = $this->getApplicationURI( | $next_uri = $this->getApplicationURI( | ||||
| "cart/{$cart_id}/checkout/?paymentMethodID=".$method->getID()); | "cart/{$cart_id}/checkout/?paymentMethodID=".$method->getID()); | ||||
| } else if ($subscription_id) { | } else if ($subscription_id) { | ||||
| $next_uri = new PhutilURI($cancel_uri); | $next_uri = new PhutilURI($cancel_uri); | ||||
| $next_uri->setQueryParam('added', true); | $next_uri->setQueryParam('added', true); | ||||
| } else { | } else { | ||||
| $account_uri = $this->getApplicationURI($account->getID().'/'); | $account_uri = $this->getApplicationURI($account->getID().'/'); | ||||
| $next_uri = new PhutilURI($account_uri); | $next_uri = new PhutilURI($account_uri); | ||||
| $next_uri->setFragment('payment'); | $next_uri->setFragment('payment'); | ||||
| } | } | ||||
| return id(new AphrontRedirectResponse())->setURI($next_uri); | return id(new AphrontRedirectResponse())->setURI($next_uri); | ||||
| } else { | } else { | ||||
| $dialog = id(new AphrontDialogView()) | if ($display_exception) { | ||||
| ->setUser($viewer) | $dialog_body = $display_exception->getView(); | ||||
| } else { | |||||
| $dialog_body = id(new PHUIInfoView()) | |||||
| ->setErrors($errors); | |||||
| } | |||||
| return $this->newDialog() | |||||
| ->setTitle(pht('Error Adding Payment Method')) | ->setTitle(pht('Error Adding Payment Method')) | ||||
| ->appendChild(id(new PHUIInfoView())->setErrors($errors)) | ->appendChild($dialog_body) | ||||
| ->addCancelButton($request->getRequestURI()); | ->addCancelButton($request->getRequestURI()); | ||||
| return id(new AphrontDialogResponse())->setDialog($dialog); | |||||
| } | } | ||||
| } | } | ||||
| $form = $provider->renderCreatePaymentMethodForm($request, $errors); | $form = $provider->renderCreatePaymentMethodForm($request, $errors); | ||||
| $form | $form | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->setAction($request->getRequestURI()) | ->setAction($request->getRequestURI()) | ||||
| ▲ Show 20 Lines • Show All 130 Lines • Show Last 20 Lines | |||||
(No other payment method can currently actually raise any errors today -- the "Pile of Wealth" test provider can't fail, and Paypal doesn't go through this flow.)