/** * 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); }
/** * Map data to the key map * @param IKeyMapper $Map the map inst to add data to * @internal param \CPath\Request\IRequest $Request * @internal param \CPath\Request\IRequest $Request * @return void */ function mapKeys(IKeyMapper $Map) { $SourceEntry = PaymentSourceEntry::get($this->payment_source_id); // TODO: inefficient $Source = $SourceEntry->getPaymentSource(); $Invoice = $this->getInvoice(); $Product = $Invoice->getProduct(); $Map->map('id', $this->getID()); $Map->map('wallet', $this->getWalletID()); $Map->map('email', $Invoice->getWallet()->getEmail()); $Map->map('product', $this->getProductID(), $Product->getProductTitle()); $Map->map('created', $this->getCreatedTimestamp()); $Map->map('status', $this->getStatusText()); $Map->map('amount', $this->getAmount()); $Map->map('currency', $Source->getCurrency()); // $Map->map('description', $Product->getTypeDescription()); // $Map->map('payment-source', $Source->getTitle()); //todo: flags for mapping headers? // $Map->map('product', $ProductEntry); // $Map->map('product-title', $Product->getTitle()); // $Map->map('total', $Product->getTotalCost()); // $Map->map('type', $Product->getTypeName()); // $Map->map('invoice', $Invoice->getProduct()->); }