/** * Validate the request * @param IRequest $Request * @param HTMLForm $ThrowForm * @throws \CPath\Request\Validation\Exceptions\ValidationException * @return array|void optionally returns an associative array of modified field names and values */ function validateRequest(IRequest $Request, HTMLForm $ThrowForm = null) { $Form = new HTMLForm('POST', $this->getFieldSet($Request)); $Form->validateRequest($Request, $ThrowForm); $this->title = $Request[self::PARAM_SOURCE_TITLE]; $this->currency = $Request[self::PARAM_SOURCE_CURRENCY]; $this->created ?: ($this->created = time()); }
/** * Validate the request * @param IRequest $Request * @param HTMLForm $ThrowForm * @throws \CPath\Request\Validation\Exceptions\ValidationException * @return array|void optionally returns an associative array of modified field names and values */ function validateOrderRequest(IRequest $Request, HTMLForm $ThrowForm = null) { $Form = new HTMLForm('POST', $this->getOrderFieldSet($Request)); $Form->validateRequest($Request, $ThrowForm); $this->full_name = $Request[self::PARAM_SHIPPING_FULL_NAME]; $this->address = $Request[self::PARAM_SHIPPING_ADDRESS]; $this->address2 = $Request[self::PARAM_SHIPPING_ADDRESS2]; $this->city = $Request[self::PARAM_SHIPPING_CITY]; $this->state = $Request[self::PARAM_SHIPPING_STATE]; $this->country = $Request[self::PARAM_SHIPPING_COUNTRY]; $this->zip = $Request[self::PARAM_SHIPPING_ZIPCODE]; $this->created = time(); }
/** * 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"); } $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/account.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/account.css'), new HTMLElement('fieldset', 'fieldset-create-account', new HTMLElement('legend', 'legend-account', self::TITLE), new HTMLElement('label', null, "Choose a Account Type<br/>", new HTMLInputField(self::PARAM_ACCOUNT_NAME, new RequiredValidation())), "<br/><br/>", new HTMLElement('label', null, "Status<br/>", new HTMLInputField(self::PARAM_ACCOUNT_PASSWORD, null, 'password', new RequiredValidation())), "<br/><br/>Login:<br/>", new HTMLButton('submit', 'Login', 'submit')), "<br/>"); $Form->setFormValues($Request); if (!$Request instanceof IFormRequest) { return $Form; } $Form->validateRequest($Request); $AccountEntry = AccountEntry::search($Request[self::PARAM_ACCOUNT_NAME]); $Account = $AccountEntry->getAccount(); $Account->assertPassword($Request[self::PARAM_ACCOUNT_PASSWORD]); $Account->startSession($SessionRequest); return new RedirectResponse(ManageAccount::getRequestURL($AccountEntry->getID()), "Logged in successfully. Redirecting...", 5); }
/** * 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); $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE . ' - ' . $Account->getAccountName()), new HTMLHeaderScript(__DIR__ . '/assets/account.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/account.css'), new HTMLElement('fieldset', 'fieldset-create-account', new HTMLElement('legend', 'legend-account', self::TITLE . ' - ' . $Account->getAccountName()), new HTMLButton('submit', 'Logout', 'submit')), "<br/>"); $Form->setFormValues($Request); if (!$Request instanceof IFormRequest) { return $Form; } $Form->validateRequest($Request); if (!$SessionRequest->isStarted()) { $SessionRequest->startSession(); } $SessionRequest->destroySession(); return new RedirectResponse(Login::getRequestURL(), "Logged out successfully. Redirecting...", 5); }
/** * Validate the request * @param IRequest $Request * @param HTMLForm $ThrowForm * @throws \CPath\Request\Validation\Exceptions\ValidationException * @throw Exception if validation failed * @return array|void optionally returns an associative array of modified field names and values */ function validateRequest(IRequest $Request, HTMLForm $ThrowForm = null) { $Form = new HTMLForm('POST', $this->getFieldSet($Request)); $Form->validateRequest($Request, $ThrowForm); $this->name = $Request[self::PARAM_BILLING_NAME]; $this->email = $Request[self::PARAM_BILLING_EMAIL]; $this->time ?: ($this->time = time()); $this->card = $Request[self::PARAM_CARD_NUMBER]; $this->csc = $Request[self::PARAM_CARD_CSC]; $this->exp = $Request[self::PARAM_EXP_MONTH] . '/' . $Request[self::PARAM_EXP_YEAR]; $this->address = $Request[self::PARAM_BILLING_ADDRESS]; $this->address2 = $Request[self::PARAM_BILLING_ADDRESS2]; $this->city = $Request[self::PARAM_BILLING_CITY]; $this->state = $Request[self::PARAM_BILLING_STATE]; $this->zip = $Request[self::PARAM_BILLING_ZIPCODE]; $this->country = $Request[self::PARAM_BILLING_COUNTRY]; }
/** * Validate the request * @param IRequest $Request * @param HTMLForm $ThrowForm * @throws \CPath\Request\Validation\Exceptions\ValidationException * @return array|void optionally returns an associative array of modified field names and values */ function validateFeesRequest(IRequest $Request, HTMLForm $ThrowForm = null) { $Form = new HTMLForm('POST', $this->getFeesFieldSet($Request)); $Form->setFormValues($Request); $Form->validateRequest($Request, $ThrowForm); $this->fees = $Request[self::PARAM_PRODUCT_FEE]; foreach ($Request[self::PARAM_PRODUCT_FEE] as $accountID => $fee) { $fees = explode(';', $fee); foreach ($fees as &$f) { $f = preg_replace('/[^0-9;.%]/', '', $f); if (!$f) { $f = null; } else { if (strpos($fee, '.') === false) { $f .= '.00'; } } } $this->fees[$accountID] = implode('; ', $fees) ?: '0.00'; } }
/** * Execute a command and return a response. Does not render * @param IRequest $Request * @throws \CPath\Request\Validation\Exceptions\ValidationException * @throws \Exception * @return IResponse the execution response */ function execute(IRequest $Request) { $ProductEntry = ProductEntry::get($this->id); $Product = $ProductEntry->getProduct(); $SessionRequest = $Request; if (!$SessionRequest instanceof ISessionRequest) { throw new \Exception("Session required"); } $walletOptions = array('Choose a Wallet' => null); $WalletForms = array(); /** @var AbstractWallet[] $WalletTypes */ $WalletTypes = array(); $SessionWalletEntries = AbstractWallet::loadSessionWallets($SessionRequest); foreach ($SessionWalletEntries as $WalletEntry) { $Wallet = $WalletEntry->getWallet(); $key = $WalletEntry->getID(); $WalletTypes[$key] = $Wallet; $FieldSet = $Wallet->getFieldSet($Request); $FieldSet->setAttribute('data-' . self::PARAM_WALLET_ID, $key); $FieldSet->setAttribute('disabled', 'disabled'); $WalletForms[] = $FieldSet; $walletOptions[$Wallet->getTitle() . ' - ' . $Wallet->getDescription()] = $key; } foreach ($Product->getWalletTypes() as $Wallet) { $key = $Wallet->getTypeName(); $WalletTypes[$key] = $Wallet; $FieldSet = $Wallet->getFieldSet($Request); $FieldSet->setAttribute('data-' . self::PARAM_WALLET_ID, $key); $FieldSet->setAttribute('disabled', 'disabled'); $WalletForms[] = $FieldSet; $walletOptions['New ' . $Wallet->getDescription()] = $key; } // $walletTypes = Config::$AvailableWalletTypes; $Form = new HTMLForm(self::FORM_METHOD, self::getRequestURL($this->id), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/order-form.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/order-form.css'), new HTMLElement('fieldset', 'fieldset-order-form', new HTMLElement('legend', 'legend-order-form', self::TITLE), new HTMLElement('fieldset', 'fieldset-choose-wallet', new HTMLElement('legend', 'legend-choose-wallet', 'Choose a Wallet'), new HTMLElement('label', null, new HTMLSelectField(self::PARAM_WALLET_ID, $walletOptions, new RequiredValidation())), "<br/><br/>", $WalletForms), new HTMLElement('fieldset', 'fieldset-transaction-details', new HTMLElement('legend', 'legend-transaction-details', 'Transaction Details'), $Product->getTypeDescription(), "<br/>", $Product->getOrderFieldSet($Request)), "<br/><br/>", new HTMLElement('fieldset', 'fieldset-submit', new HTMLElement('legend', 'legend-submit', 'Submit'), new HTMLButton('submit', 'Submit', 'submit'))), "<br/>"); if (!$Request instanceof IFormRequest) { return $Form; } $Form->setFormValues($Request); $Form->validateRequest($Request); $walletType = $Form->validateField($Request, self::PARAM_WALLET_ID); $ChosenWallet = $WalletTypes[$walletType]; $ChosenWallet->validateRequest($Request, $Form); $productID = $this->getProductID(); //$Form->validateField($Request, self::PARAM_PRODUCT_ID); $ProductEntry = ProductEntry::get($productID); $Product = $ProductEntry->getProduct(); $Invoice = $Product->createNewInvoice($Request, $ChosenWallet); $responses = array(); foreach (PaymentSourceEntry::getActiveSources() as $PaymentSourceEntry) { $PaymentSource = $PaymentSourceEntry->getPaymentSource(); if ($PaymentSource->supportsWalletType($ChosenWallet)) { $Response = $PaymentSource->executeWalletTransaction($ChosenWallet); $responses[] = $Response->getMessage(); $paymentSourceID = $PaymentSourceEntry->getID(); $walletID = WalletEntry::createOrUpdate($Request, $ChosenWallet); if ($Response->getCode() === TransactionEntry::STATUS_APPROVED) { $status = TransactionEntry::STATUS_APPROVED; $id = TransactionEntry::create($Request, $Invoice, $status, $walletID, $productID, $paymentSourceID); ProfitEntry::update($Request, $id); return new RedirectResponse(ManageTransaction::getRequestURL($id), "Transaction created successfully. Redirecting...", 5); } else { $status = TransactionEntry::STATUS_DECLINED; $id = TransactionEntry::create($Request, $Invoice, $status, $walletID, $productID, $paymentSourceID); ProfitEntry::update($Request, $id); } } } throw new ValidationException($Form, "Transaction declined: \n\t" . implode("\n\t", $responses)); // // // if(true) { // $status = TransactionEntry::STATUS_APPROVED; // // $id = TransactionEntry::create($Request, $Invoice, $status, $walletID, $productID, $paymentSourceID); // ProfitEntry::update($Request, $id); // return new RedirectResponse(ManageTransaction::getRequestURL($id), "Purchase was successful. Redirecting...", 5); // // } else { // $status = TransactionEntry::STATUS_DECLINED; // $id = TransactionEntry::create($Request, $Invoice, $status, $walletID, $productID, $paymentSourceID); // ProfitEntry::update($Request, $id); // return new RequestException("Transaction has declined"); // } }
/** * Validate the request * @param IRequest $Request * @param HTMLForm $ThrowForm * @throws \CPath\Request\Validation\Exceptions\ValidationException * @return array|void optionally returns an associative array of modified field names and values */ function validateRequest(IRequest $Request, HTMLForm $ThrowForm = null) { $Form = new HTMLForm('POST', $this->getFieldSet($Request)); $Form->validateRequest($Request, $ThrowForm); $pass = $Request[self::PARAM_ACCOUNT_PASSWORD]; if ($pass && $pass !== self::PASS_BLANK) { $salt = uniqid('', true); $this->pass = crypt($Request[self::PARAM_ACCOUNT_PASSWORD], $salt); } $this->name = $Request[self::PARAM_ACCOUNT_NAME]; $this->email = $Request[self::PARAM_ACCOUNT_EMAIL]; }