Differential D20733 Diff 49429 src/applications/phortune/controller/merchant/PhortuneMerchantProviderEditController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/controller/merchant/PhortuneMerchantProviderEditController.php
- This file was moved from src/applications/phortune/controller/provider/PhortuneProviderEditController.php.
<?php | <?php | ||||
final class PhortuneProviderEditController | final class PhortuneMerchantProviderEditController | ||||
extends PhortuneMerchantController { | extends PhortuneMerchantController { | ||||
public function handleRequest(AphrontRequest $request) { | protected function shouldRequireMerchantEditCapability() { | ||||
return true; | |||||
} | |||||
protected function handleMerchantRequest(AphrontRequest $request) { | |||||
$viewer = $request->getViewer(); | $viewer = $request->getViewer(); | ||||
$merchant = $this->getMerchant(); | |||||
$id = $request->getURIData('id'); | $id = $request->getURIData('id'); | ||||
if ($id) { | if ($id) { | ||||
$provider_config = id(new PhortunePaymentProviderConfigQuery()) | $provider_config = id(new PhortunePaymentProviderConfigQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIDs(array($id)) | ->withIDs(array($id)) | ||||
->withMerchantPHIDs(array($merchant->getPHID())) | |||||
->requireCapabilities( | ->requireCapabilities( | ||||
array( | array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
)) | )) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$provider_config) { | if (!$provider_config) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$is_new = false; | $is_new = false; | ||||
$is_choose_type = false; | $is_choose_type = false; | ||||
$merchant = $provider_config->getMerchant(); | $merchant = $provider_config->getMerchant(); | ||||
$merchant_id = $merchant->getID(); | $merchant_id = $merchant->getID(); | ||||
$cancel_uri = $this->getApplicationURI("merchant/{$merchant_id}/"); | $cancel_uri = $provider_config->getURI(); | ||||
} else { | } else { | ||||
$merchant = id(new PhortuneMerchantQuery()) | |||||
->setViewer($viewer) | |||||
->withIDs(array($request->getStr('merchantID'))) | |||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->executeOne(); | |||||
if (!$merchant) { | |||||
return new Aphront404Response(); | |||||
} | |||||
$merchant_id = $merchant->getID(); | $merchant_id = $merchant->getID(); | ||||
$current_providers = id(new PhortunePaymentProviderConfigQuery()) | $current_providers = id(new PhortunePaymentProviderConfigQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withMerchantPHIDs(array($merchant->getPHID())) | ->withMerchantPHIDs(array($merchant->getPHID())) | ||||
->execute(); | ->execute(); | ||||
$current_map = mgroup($current_providers, 'getProviderClass'); | $current_map = mgroup($current_providers, 'getProviderClass'); | ||||
$provider_config = PhortunePaymentProviderConfig::initializeNewProvider( | $provider_config = PhortunePaymentProviderConfig::initializeNewProvider( | ||||
$merchant); | $merchant); | ||||
$is_new = true; | $is_new = true; | ||||
$classes = PhortunePaymentProvider::getAllProviders(); | $classes = PhortunePaymentProvider::getAllProviders(); | ||||
$class = $request->getStr('class'); | $class = $request->getStr('class'); | ||||
if (empty($classes[$class]) || isset($current_map[$class])) { | if (empty($classes[$class]) || isset($current_map[$class])) { | ||||
return $this->processChooseClassRequest( | return $this->processChooseClassRequest( | ||||
$request, | $request, | ||||
$merchant, | $merchant, | ||||
$current_map); | $current_map); | ||||
} | } | ||||
$provider_config->setProviderClass($class); | $provider_config->setProviderClass($class); | ||||
$cancel_uri = $merchant->getPaymentProvidersURI(); | |||||
$cancel_uri = $this->getApplicationURI( | |||||
'provider/edit/?merchantID='.$merchant_id); | |||||
} | } | ||||
$provider = $provider_config->buildProvider(); | $provider = $provider_config->buildProvider(); | ||||
if ($is_new) { | if ($is_new) { | ||||
$title = pht('Create Payment Provider'); | $title = pht('Create Payment Provider'); | ||||
$button_text = pht('Create Provider'); | $button_text = pht('Create Provider'); | ||||
} else { | } else { | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if ($request->isFormPost() && $request->getStr('edit')) { | ||||
if (!$errors) { | if (!$errors) { | ||||
$template = id(new PhortunePaymentProviderConfigTransaction()) | $template = id(new PhortunePaymentProviderConfigTransaction()) | ||||
->setTransactionType( | ->setTransactionType( | ||||
PhortunePaymentProviderConfigTransaction::TYPE_PROPERTY); | PhortunePaymentProviderConfigTransaction::TYPE_PROPERTY); | ||||
$xactions = array(); | $xactions = array(); | ||||
if (!$provider_config->getID()) { | |||||
$xactions[] = id(new PhortunePaymentProviderConfigTransaction()) | $xactions[] = id(new PhortunePaymentProviderConfigTransaction()) | ||||
->setTransactionType( | ->setTransactionType( | ||||
PhortunePaymentProviderConfigTransaction::TYPE_CREATE) | PhortunePaymentProviderConfigTransaction::TYPE_CREATE) | ||||
->setNewValue(true); | ->setNewValue(true); | ||||
} | |||||
foreach ($xaction_values as $key => $value) { | foreach ($xaction_values as $key => $value) { | ||||
$xactions[] = id(clone $template) | $xactions[] = id(clone $template) | ||||
->setMetadataValue( | ->setMetadataValue( | ||||
PhortunePaymentProviderConfigTransaction::PROPERTY_KEY, | PhortunePaymentProviderConfigTransaction::PROPERTY_KEY, | ||||
$key) | $key) | ||||
->setNewValue($value); | ->setNewValue($value); | ||||
} | } | ||||
$editor = id(new PhortunePaymentProviderConfigEditor()) | $editor = id(new PhortunePaymentProviderConfigEditor()) | ||||
->setActor($viewer) | ->setActor($viewer) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setContinueOnNoEffect(true); | ->setContinueOnNoEffect(true); | ||||
$editor->applyTransactions($provider_config, $xactions); | $editor->applyTransactions($provider_config, $xactions); | ||||
$merchant_uri = $this->getApplicationURI( | $next_uri = $provider_config->getURI(); | ||||
'merchant/'.$merchant->getID().'/'); | |||||
return id(new AphrontRedirectResponse())->setURI($merchant_uri); | return id(new AphrontRedirectResponse())->setURI($next_uri); | ||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
$form_values = $provider->readEditFormValuesFromProviderConfig(); | $form_values = $provider->readEditFormValuesFromProviderConfig(); | ||||
$issues = array(); | $issues = array(); | ||||
} | } | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->addHiddenInput('merchantID', $merchant->getID()) | |||||
->addHiddenInput('class', $provider_config->getProviderClass()) | ->addHiddenInput('class', $provider_config->getProviderClass()) | ||||
->addHiddenInput('edit', true) | ->addHiddenInput('edit', true) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormMarkupControl()) | id(new AphrontFormMarkupControl()) | ||||
->setLabel(pht('Provider Type')) | ->setLabel(pht('Provider Type')) | ||||
->setValue($provider->getName())); | ->setValue($provider->getName())); | ||||
$provider->extendEditForm($request, $form, $form_values, $issues); | $provider->extendEditForm($request, $form, $form_values, $issues); | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | foreach ($providers as $class => $provider) { | ||||
$provider->getConfigureName(), | $provider->getConfigureName(), | ||||
$description, | $description, | ||||
null, | null, | ||||
$disabled); | $disabled); | ||||
} | } | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->addHiddenInput('merchantID', $merchant->getID()) | |||||
->appendRemarkupInstructions( | ->appendRemarkupInstructions( | ||||
pht('Choose the type of payment provider to add:')) | pht('Choose the type of payment provider to add:')) | ||||
->appendChild($panel_classes) | ->appendChild($panel_classes) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormSubmitControl()) | id(new AphrontFormSubmitControl()) | ||||
->setValue(pht('Continue')) | ->setValue(pht('Continue')) | ||||
->addCancelButton($cancel_uri)); | ->addCancelButton($cancel_uri)); | ||||
Show All 30 Lines |