/**
  * Execute a command and return a response. Does not render
  * @param IRequest $Request
  * @throws \Exception
  * @return IResponse the execution response
  */
 function execute(IRequest $Request)
 {
     $SessionRequest = $Request;
     if (!$SessionRequest instanceof ISessionRequest) {
         throw new \Exception("Session required");
     }
     $Account = AbstractAccountType::loadFromSession($SessionRequest);
     if (!$Account instanceof AdministratorAccount) {
         throw new RequestException("Administrator account required");
     }
     $sourceOptions = array("Choose a Payment Source" => null);
     /** @var AbstractPaymentSource[] $SourceTypes */
     $SourceTypes = array();
     $SourceForms = array();
     foreach (AbstractPaymentSource::loadAllPaymentSourceTypes() as $SourceType) {
         $SourceTypes[$SourceType->getTypeName()] = $SourceType;
         $FieldSet = $SourceType->getFieldSet($Request);
         $FieldSet->setAttribute('data-' . self::PARAM_SOURCE_TYPE, $SourceType->getTypeName());
         $FieldSet->setAttribute('disabled', 'disabled');
         $SourceForms[] = $FieldSet;
         $sourceOptions[$SourceType->getDescription()] = $SourceType->getTypeName();
     }
     $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/payment-source.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/payment-source.css'), new HTMLElement('fieldset', 'fieldset-create-payment-source', new HTMLElement('legend', 'legend-payment-source', self::TITLE), new HTMLElement('label', null, "Status<br/>", new HTMLSelectField(self::PARAM_SOURCE_STATUS, PaymentSourceEntry::$StatusOptions, new RequiredValidation())), "<br/><br/>", new HTMLElement('label', null, "Choose a Payment Source<br/>", new HTMLSelectField(self::PARAM_SOURCE_TYPE, $sourceOptions, new RequiredValidation())), "<br/><br/>", $SourceForms, "<br/>Submit:<br/>", new HTMLButton('submit', 'Submit', 'submit')), "<br/>");
     if (!$Request instanceof IFormRequest) {
         return $Form;
     }
     $status = $Form->validateField($Request, self::PARAM_SOURCE_STATUS);
     $sourceType = $Form->validateField($Request, self::PARAM_SOURCE_TYPE);
     $ChosenSource = $SourceTypes[$sourceType];
     $ChosenSource->validateRequest($Request, $Form);
     $id = PaymentSourceEntry::create($Request, $ChosenSource, $status);
     return new RedirectResponse(ManagePaymentSource::getRequestURL($id), "PaymentSource created successfully. Redirecting...", 5);
 }
 /**
  * Execute a command and return a response. Does not render
  * @param IRequest $Request
  * @return IResponse the execution response
  */
 function execute(IRequest $Request)
 {
     $Entry = PaymentSourceEntry::get($this->id);
     $Source = $Entry->getPaymentSource();
     $SourceForm = $Source->getFieldSet($Request);
     $SessionRequest = $Request;
     if (!$SessionRequest instanceof ISessionRequest) {
         throw new \Exception("Session required");
     }
     $Account = AbstractAccountType::loadFromSession($SessionRequest);
     if (!$Account instanceof AdministratorAccount) {
         throw new RequestException("Administrator account required");
     }
     $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLElement('fieldset', new HTMLElement('legend', 'legend-submit', self::TITLE), new HTMLInputField(self::PARAM_ID, $this->id, 'hidden'), new HTMLElement('label', null, "Status<br/>", $Select = new HTMLSelectField(self::PARAM_SOURCE_STATUS, PaymentSourceEntry::$StatusOptions, new RequiredValidation())), "<br/><br/>", $SourceForm, "<br/>Submit:<br/>", new HTMLButton('submit', 'Submit', 'submit')), "<br/>");
     $Select->setInputValue($Entry->getStatus());
     if (!$Request instanceof IFormRequest) {
         return $Form;
     }
     $status = $Form->validateField($Request, self::PARAM_SOURCE_STATUS);
     $Source->validateRequest($Request, $Form);
     $Entry->update($Request, $Source, $status);
     return new RedirectResponse(ManagePaymentSource::getRequestURL($Entry->getID()), "Payment Source updated successfully. Redirecting...", 5);
 }
 /**
  * @param $key
  * @param $value
  * @param null $arg1
  * @return bool if true, the value has been rendered, otherwise false
  */
 function renderNamedValue($key, $value, $arg1 = null)
 {
     switch ($key) {
         case 'created':
             if ($value) {
                 echo DateUtil::ago($value) . ' ago';
             }
             return true;
         case 'status':
             echo "<span class='status'>", $arg1 ?: $value, "</span>";
             return true;
         case 'amount':
             if ($value) {
                 echo "<span class='amount'>", $value, "</span>";
             }
             return true;
         case 'payment-source':
         case 'payment-source-id':
             $href = $this->domain . ltrim(ManagePaymentSource::getRequestURL($value), '/');
             echo "<a href='{$href}'>", $arg1 ?: $value, "</a>";
             return true;
         case 'transaction':
         case 'transaction-id':
             $href = $this->domain . ltrim(ManageTransaction::getRequestURL($value), '/');
             echo "<a href='{$href}'>", $arg1 ?: $value, "</a>";
             return true;
         case 'product':
         case 'product-id':
             $href = $this->domain . ltrim(ManageProduct::getRequestURL($value), '/');
             echo "<a href='{$href}'>", $arg1 ?: $value, "</a>";
             return true;
         case 'test-url':
             $href = $this->domain . ltrim($value, '/');
             echo "<a href='{$href}'>Test</a>";
             return true;
         case 'order-page-url':
             $href = $this->domain . ltrim($value, '/');
             echo "<a href='{$href}'>Order Page</a>";
             return true;
         case 'account':
         case 'affiliate':
         case 'account-id':
             $href = $this->domain . ltrim(ManageAccount::getRequestURL($value), '/');
             echo "<a href='{$href}'>", $arg1 ?: $value, "</a>";
             return true;
         case 'wallet-id':
             $href = $this->domain . ltrim(ManageWallet::getRequestURL($value), '/');
             echo "<a href='{$href}'>", $value, "</a>";
             return true;
     }
     return false;
 }