Differential D12680 Diff 30538 src/applications/phortune/controller/PhortunePaymentMethodCreateController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/controller/PhortunePaymentMethodCreateController.php
| Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | if ($request->isFormPost() && $request->getBool('isProviderForm')) { | ||||
| if (!$errors) { | if (!$errors) { | ||||
| $errors = $this->processClientErrors( | $errors = $this->processClientErrors( | ||||
| $provider, | $provider, | ||||
| $request->getStr('errors')); | $request->getStr('errors')); | ||||
| } | } | ||||
| if (!$errors) { | if (!$errors) { | ||||
| $client_token_raw = $request->getStr('token'); | $client_token_raw = $request->getStr('token'); | ||||
| $client_token = json_decode($client_token_raw, true); | $client_token = null; | ||||
| if (!is_array($client_token)) { | try { | ||||
| $client_token = phutil_json_decode($client_token_raw); | |||||
| } catch (PhutilJSONParserException $ex) { | |||||
| $errors[] = pht( | $errors[] = pht( | ||||
| 'There was an error decoding token information submitted by the '. | 'There was an error decoding token information submitted by the '. | ||||
| 'client. Expected a JSON-encoded token dictionary, received: %s.', | 'client. Expected a JSON-encoded token dictionary, received: %s.', | ||||
| nonempty($client_token_raw, pht('nothing'))); | nonempty($client_token_raw, pht('nothing'))); | ||||
| } else { | } | ||||
| 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( | $errors = $provider->createPaymentMethodFromRequest( | ||||
| $request, | $request, | ||||
| $method, | $method, | ||||
| $client_token); | $client_token); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | final class PhortunePaymentMethodCreateController | ||||
| } | } | ||||
| private function processClientErrors( | private function processClientErrors( | ||||
| PhortunePaymentProvider $provider, | PhortunePaymentProvider $provider, | ||||
| $client_errors_raw) { | $client_errors_raw) { | ||||
| $errors = array(); | $errors = array(); | ||||
| $client_errors = json_decode($client_errors_raw, true); | $client_errors = null; | ||||
| if (!is_array($client_errors)) { | try { | ||||
| $client_errors = phutil_json_decode($client_errors_raw); | |||||
| } catch (PhutilJSONParserException $ex) { | |||||
| $errors[] = pht( | $errors[] = pht( | ||||
| 'There was an error decoding error information submitted by the '. | 'There was an error decoding error information submitted by the '. | ||||
| 'client. Expected a JSON-encoded list of error codes, received: %s.', | 'client. Expected a JSON-encoded list of error codes, received: %s.', | ||||
| nonempty($client_errors_raw, pht('nothing'))); | nonempty($client_errors_raw, pht('nothing'))); | ||||
| } | } | ||||
| foreach (array_unique($client_errors) as $key => $client_error) { | foreach (array_unique($client_errors) as $key => $client_error) { | ||||
| $client_errors[$key] = $provider->translateCreatePaymentMethodErrorCode( | $client_errors[$key] = $provider->translateCreatePaymentMethodErrorCode( | ||||
| ▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines | |||||