/**
  * 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)
 {
     $TransactionEntry = TransactionEntry::get($this->getTransactionID());
     $transactionLog = $TransactionEntry->fetchLog();
     $Invoice = $TransactionEntry->getInvoice();
     $Product = $Invoice->getProduct();
     $Wallet = $Invoice->getWallet();
     $accounts = array();
     $merchantProfit = $Product->calculateProfit($TransactionEntry->getStatus(), $accounts);
     $accounts[$Product->getAccountID()] = $merchantProfit;
     $ProfitTBody = new HTMLSequenceTableBody(new CallbackSequenceMap(function (ISequenceMapper $Map) use($accounts) {
         foreach ($accounts as $accountID => $profit) {
             $Map->mapNext(array('account' => $accountID, 'profit' => $profit));
         }
     }));
     $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/transaction.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/transaction.css'), new HTMLElement('fieldset', 'fieldset-transaction-info inline', new HTMLElement('legend', 'legend-transaction-info', 'Transaction Information'), new MapRenderer($TransactionEntry)), new HTMLElement('fieldset', 'fieldset-product-profit inline', new HTMLElement('legend', 'legend-product-profit', 'Profit Information'), new HTMLTable($ProfitTBody)), "<br/>", new HTMLElement('fieldset', 'fieldset-product-container inline', new HTMLElement('legend', 'legend-product', 'Order Information'), $Wallet->getFieldSet($Request)->setAttribute('disabled', 'disabled'), $Product->getOrderFieldSet($Request)->setAttribute('disabled', 'disabled'), $Product->getConfigFieldSet($Request)->setAttribute('disabled', 'disabled'), $Product->getFeesFieldSet($Request)->setAttribute('disabled', 'disabled'), "<br/><br/>", new HTMLButton('submit', 'Update', 'submit')), "<br/>", new HTMLElement('fieldset', 'fieldset-transaction-log inline', new HTMLElement('legend', 'legend-transaction-log', 'Transaction Log'), new HTMLTextAreaField(self::PARAM_LOG . '_disabled', $transactionLog, new Attributes('rows', 10, 'cols', 100), new Attributes('disabled', 'disabled')), "<br/>", new HTMLTextAreaField(self::PARAM_LOG, new Attributes('rows', 3, 'cols', 100)), "<br/>", new HTMLButton(self::PARAM_SUBMIT, 'Append', 'append-log')), new HTMLElement('fieldset', 'fieldset-transaction-manage inline', new HTMLElement('legend', 'legend-submit', self::TITLE), new HTMLInputField(self::PARAM_ID, $this->id, 'hidden', new RequiredValidation()), new HTMLElement('label', null, "Status<br/>", $SelectStatus = new HTMLSelectField(self::PARAM_TRANSACTION_STATUS, TransactionEntry::$StatusOptions, new RequiredValidation())), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Update', 'submit')), "<br/>");
     $SelectStatus->setInputValue($TransactionEntry->getStatus());
     if (!$Request instanceof IFormRequest) {
         return $Form;
     }
     switch ($Request[self::PARAM_SUBMIT]) {
         case 'submit':
             $status = $Form->validateField($Request, self::PARAM_TRANSACTION_STATUS);
             $TransactionEntry->update($Request, $status);
             ProfitEntry::update($Request, $TransactionEntry->getID());
             return new RedirectResponse(ManageTransaction::getRequestURL($TransactionEntry->getID()), "Transaction updated successfully. Redirecting...", 5);
         case 'append-log':
             $appendLog = $Request[self::PARAM_LOG];
             $TransactionEntry->appendLog($appendLog);
             return new RedirectResponse(ManageTransaction::getRequestURL($TransactionEntry->getID()), "Log appended successfully. Redirecting...", 5);
         default:
             throw new \InvalidArgumentException("Invalid Submit");
     }
 }
Example #3
0
 /**
  * Execute a command and return a response. Does not render
  * @param IRequest $Request
  * @return IResponse the execution response
  */
 function execute(IRequest $Request)
 {
     $walletOptions = array('Choose a Wallet' => null);
     /** @var AbstractWallet[] $WalletTypes */
     $WalletTypes = array();
     $WalletForms = array();
     foreach (AbstractWallet::loadAllWalletTypes() as $WalletType) {
         $WalletTypes[$WalletType->getTypeName()] = $WalletType;
         $FieldSet = $WalletType->getFieldSet($Request);
         $FieldSet->setAttribute('data-' . self::PARAM_WALLET_TYPE, $WalletType->getTypeName());
         $FieldSet->setAttribute('disabled', 'disabled');
         $WalletForms[] = $FieldSet;
         $walletOptions[$WalletType->getDescription()] = $WalletType->getTypeName();
     }
     $Form = new HTMLForm(self::FORM_METHOD, self::FORM_ACTION, self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '\\assets\\create-wallet.js'), new HTMLHeaderStyleSheet(__DIR__ . '\\assets\\create-wallet.css'), new HTMLElement('fieldset', new HTMLElement('legend', 'legend-wallet', 'Create a new Wallet'), new HTMLElement('label', null, "New Wallet type<br/>", new HTMLSelectField(self::PARAM_WALLET_TYPE, $walletOptions, new RequiredValidation())), "<br/><br/>", $WalletForms, "<br/><br/>", new HTMLButton('create', "Create New Wallet")));
     $Form->setFormValues($Request);
     if (!$Request instanceof IFormRequest) {
         return $Form;
     }
     $walletType = $Form->validateField($Request, self::PARAM_WALLET_TYPE);
     $NewWallet = $WalletTypes[$walletType];
     $NewWallet->validateRequest($Request, $Form);
     //		$name = $Request[self::PARAM_WALLET_NAME];
     //		$email = $Request[self::PARAM_WALLET_EMAIL];
     $id = WalletEntry::create($Request, $NewWallet);
     return new RedirectResponse(ManageWallet::getRequestURL($id), "Wallet created successfully. Redirecting...", 5);
 }
 /**
  * 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();
 }
Example #6
0
 /**
  * Execute a command and return a response. Does not render
  * @param IRequest $Request
  * @return IResponse the execution response
  */
 function execute(IRequest $Request)
 {
     $Table = new ProfitTable();
     $StatsQuery = $Table->select(ProfitTable::COLUMN_ACCOUNT_ID, 'account')->select(ProfitTable::COLUMN_PROFIT, 'profit', 'SUM(%s)')->select(ProfitTable::COLUMN_PROFIT, 'count', 'COUNT(%s)')->groupBy(ProfitTable::COLUMN_ACCOUNT_ID)->limit(50);
     $StatsTable = new HTMLPDOQueryTable($StatsQuery);
     $StatsTable->addColumn('account');
     $StatsTable->addColumn('profit');
     $StatsTable->addColumn('count');
     $StatsTable->addSearchColumn(ProfitTable::COLUMN_ACCOUNT_ID, "account");
     $StatsTable->validateRequest($Request);
     $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderStyleSheet(__DIR__ . '/assets/search-profit.css'), new HTMLElement('fieldset', 'fieldset-search fieldset-filter-search inline', new HTMLElement('legend', 'legend-filter-search', self::TITLE), $StatsTable, "<br/>", new HTMLButton(null, 'Report')), "<br/>");
     $Form->setFormValues($Request);
     return $Form;
 }
Example #7
0
 /**
  * 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);
 }
Example #8
0
 /**
  * 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);
 }
Example #9
0
 /**
  * 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 MerchantAccount) {
         throw new RequestException("Only merchants may create a new Product");
     }
     $productOptions = array("Choose a Product Type" => null);
     /** @var AbstractProductType[] $ProductTypes */
     $ProductTypes = array();
     $ProductForms = array();
     foreach (Types\AbstractProductType::loadAllProductTypes() as $ProductType) {
         $ProductTypes[$ProductType->getTypeName()] = $ProductType;
         $FieldSet = $ProductType->getConfigFieldSet($Request);
         $FieldSet->setAttribute('disabled', 'disabled');
         $ProductForms[] = $FieldSet;
         //			$FieldSet = $ProductType->getRatesFieldSet($Request);
         //			$FieldSet->setAttribute('disabled', 'disabled');
         //			$ProductForms[] = $FieldSet;
         $productOptions[$ProductType->getTypeDescription()] = $ProductType->getTypeName();
     }
     $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/product.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/product.css'), new HTMLElement('fieldset', 'fieldset-create-product', new HTMLElement('legend', 'legend-product', self::TITLE), new HTMLElement('label', null, "Status<br/>", new HTMLSelectField(self::PARAM_PRODUCT_STATUS, ProductEntry::$StatusOptions, new RequiredValidation())), "<br/><br/>", new HTMLElement('label', null, "Choose a Product Type<br/>", new HTMLSelectField(self::PARAM_PRODUCT_TYPE, $productOptions, new RequiredValidation())), "<br/><br/>", $ProductForms, "<br/><br/>Submit:<br/>", new HTMLButton('submit', 'Submit', 'submit')), "<br/>");
     if (!$Request instanceof IFormRequest) {
         return $Form;
     }
     $status = $Form->validateField($Request, self::PARAM_PRODUCT_STATUS);
     $productType = $Form->validateField($Request, self::PARAM_PRODUCT_TYPE);
     //		$sourceID = $Form->validateField($Request, self::PARAM_PAYMENT_SOURCE_TYPE);
     $ChosenProduct = $ProductTypes[$productType];
     $ChosenProduct->validateConfigRequest($Request, $Form);
     $accountID = 'default';
     if ($Account) {
         $accountID = $Account->getID();
     }
     $id = ProductEntry::create($Request, $ChosenProduct, $accountID, $status);
     return new RedirectResponse(ManageProduct::getRequestURL($id), "Product created successfully. Redirecting...", 5);
 }
Example #10
0
 /**
  * Execute a command and return a response. Does not render
  * @param IRequest $Request
  * @throws RequestException
  * @throws \CPath\Request\Validation\Exceptions\ValidationException
  * @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);
     $AccountEntry = AccountEntry::get($Account->getID());
     $AffiliateQuery = AccountAffiliationEntry::queryAccountAffiliates($Account->getID());
     $AffiliateListTable = new HTMLPDOQueryTable($AffiliateQuery);
     $AffiliateListTable->addColumn('affiliate');
     $AffiliateListTable->addColumn('type');
     $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-info inline', new HTMLElement('legend', 'legend-info', self::TITLE), new MapRenderer($AccountEntry)), new HTMLElement('fieldset', 'fieldset-manage inline', new HTMLElement('legend', 'legend-manage', "Manage Account"), $Account->getFieldSet($Request)->addClass('inline'), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Update', 'update')), new HTMLElement('fieldset', 'fieldset-affiliates inline', new HTMLElement('legend', 'legend-affiliates', "Add affiliation"), "Account ID:<br/>", new HTMLInputField(self::PARAM_AFFILIATE_ID), "<br/><br/>Affiliation Type:<br/>", $TypeSelect = new HTMLSelectField(self::PARAM_AFFILIATE_TYPE, array("Request New Affiliate" => AccountAffiliationEntry::TYPE_REQUEST_AFFILIATE, "Request New Reseller" => AccountAffiliationEntry::TYPE_REQUEST_RESELLER, "Request New Processor" => AccountAffiliationEntry::TYPE_REQUEST_PROCESSOR)), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Request', 'request')), new HTMLElement('fieldset', 'fieldset-affiliate-list inline', new HTMLElement('legend', 'legend-affiliate-list', "Affiliates"), $AffiliateListTable), new HTMLElement('fieldset', 'fieldset-affiliate-approve inline', new HTMLElement('legend', 'legend-affiliate-approve', "Approve Affiliates"), $ApproveSelect = new HTMLSelectField(self::PARAM_APPROVE_AFFILIATE_ID, array('Pending affiliate approvals' => null)), "<br/><br/>", new HTMLButton(self::PARAM_SUBMIT, 'Approve', 'approve')));
     $AffiliateQuery->addRowCallback(function (AccountAffiliationEntry $Affiliation) use($Account, $ApproveSelect) {
         if ($Affiliation->isAwaitingApproval()) {
             $ApproveSelect->addOption($Affiliation->getAffiliateID(), "Approve '" . $Affiliation->getTypeText() . "' - " . $Affiliation->getAffiliateID());
         }
     });
     if (!$Request instanceof IFormRequest) {
         return $Form;
     }
     $submit = $Request[self::PARAM_SUBMIT];
     switch ($submit) {
         case 'update':
             $status = $Form->validateField($Request, self::PARAM_ACCOUNT_STATUS);
             $AccountEntry->update($Request, $Account, $status);
             return new RedirectResponse(AccountHome::getRequestURL(), "Account updated successfully. Redirecting...", 5);
         case 'approve':
             $affiliateID = $Form->validateField($Request, self::PARAM_APPROVE_AFFILIATE_ID);
             AccountAffiliationEntry::approveAffiliation($Request, $Account->getID(), $affiliateID);
             return new RedirectResponse(AccountHome::getRequestURL(), "Account deleted successfully. Redirecting...", 5);
         case 'request':
             $affiliateID = $Form->validateField($Request, self::PARAM_AFFILIATE_ID);
             $type = $Form->validateField($Request, self::PARAM_AFFILIATE_TYPE);
             AccountAffiliationEntry::setAffiliate($Request, $Account->getID(), $affiliateID, $type);
             return new RedirectResponse(AccountHome::getRequestURL(), "Affiliation requested successfully. Redirecting...", 5);
     }
     throw new \InvalidArgumentException($submit);
 }
Example #11
0
 /**
  * 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 ResellerAccount) {
     } else {
         if ($Account instanceof AdministratorAccount) {
         } else {
             throw new RequestException("Only resellers may create a new Account");
         }
     }
     $accountOptions = array("Choose a Account Type" => null);
     /** @var AbstractAccountType[] $AccountTypes */
     $AccountTypes = array();
     $AccountForms = array();
     foreach (Types\AbstractAccountType::loadAllAccountTypes() as $AccountType) {
         $AccountTypes[$AccountType->getTypeName()] = $AccountType;
         $FieldSet = $AccountType->getFieldSet($Request);
         $FieldSet->addClass($AccountType::CLS_FIELDSET_CHOOSE_ACCOUNT);
         $FieldSet->setAttribute('disabled', 'disabled');
         $AccountForms[] = $FieldSet;
         $accountOptions[ucfirst($AccountType->getTypeName())] = $AccountType->getTypeName();
     }
     $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 HTMLSelectField(self::PARAM_ACCOUNT_TYPE, $accountOptions, new RequiredValidation())), "<br/><br/>", $AccountForms, "<br/><br/>Submit:<br/>", new HTMLButton('submit', 'Submit', 'submit')), "<br/>");
     if (!$Request instanceof IFormRequest) {
         return $Form;
     }
     //		$status = $Form->validateField($Request, self::PARAM_ACCOUNT_STATUS);
     $accountType = $Form->validateField($Request, self::PARAM_ACCOUNT_TYPE);
     $ChosenAccount = $AccountTypes[$accountType];
     $ChosenAccount->validateRequest($Request, $Form);
     $id = AccountEntry::create($Request, $ChosenAccount);
     AccountAffiliationEntry::setAffiliate($Request, $Account->getID(), $id, AccountAffiliationEntry::TYPE_RESELLER);
     return new RedirectResponse(ManageAccount::getRequestURL($id), "Account 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);
 }
 /**
  * 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];
 }
 /**
  * Execute a command and return a response. Does not render
  * @param IRequest $Request
  * @throws RequestException
  * @return IResponse the execution response
  */
 function execute(IRequest $Request)
 {
     $SessionRequest = $Request;
     if (!$SessionRequest instanceof ISessionRequest) {
         throw new RequestException("Session required");
     }
     $page = 0;
     $total = null;
     $row_count = 5;
     if (isset($Request[self::PARAM_PAGE])) {
         $page = $Request[self::PARAM_PAGE];
     }
     $offset = $page * $row_count;
     $Pagination = new HTMLPagination($row_count, $page, $total);
     $Table = new TransactionTable();
     $SearchQuery = $Table->select()->limit("{$row_count} OFFSET {$offset}");
     //		$SearchQuery->orderBy(TransactionTable::COLUMN_CREATED, "DESC");
     $SearchTable = new HTMLPDOQueryTable($SearchQuery);
     $SearchTable->addColumn('id', "transaction");
     $SearchTable->addColumn('product', "product");
     $SearchTable->addColumn('wallet', "wallet");
     $SearchTable->addColumn('created', "created");
     $SearchTable->addColumn('status', "status");
     $SearchTable->addColumn('amount', "amount");
     $SearchTable->addColumn('email', "email");
     $SearchTable->addColumn('product', "product");
     $SearchTable->addColumn('currency', "currency");
     $SearchTable->addSearchColumn(TransactionTable::COLUMN_ID, "transaction");
     $SearchTable->addSearchColumn(TransactionTable::COLUMN_WALLET_ID, "wallet");
     $SearchTable->addSearchColumn(TransactionTable::COLUMN_PRODUCT_ID, "product");
     $SearchTable->addSortColumn(TransactionTable::COLUMN_CREATED, "created");
     $SearchTable->addSortColumn(TransactionTable::COLUMN_STATUS, "status");
     $SearchTable->addSortColumn(TransactionTable::COLUMN_AMOUNT, "amount");
     $SearchTable->validateRequest($Request);
     $StatsQuery = $Table->select(TransactionTable::COLUMN_AMOUNT, 'count', 'COUNT(%s)')->select(TransactionTable::COLUMN_AMOUNT, 'total', 'SUM(%s)')->select(TransactionTable::COLUMN_STATUS, 'approves', 'SUM(%s = ' . TransactionEntry::STATUS_APPROVED . ')')->select(TransactionTable::COLUMN_STATUS, 'approves_total', 'SUM(IF(%s = ' . TransactionEntry::STATUS_APPROVED . ', ' . TransactionTable::COLUMN_AMOUNT . ', 0))')->select(TransactionTable::COLUMN_STATUS, 'pending', 'SUM(%s = ' . TransactionEntry::STATUS_PENDING . ')')->select(TransactionTable::COLUMN_STATUS, 'pending_total', 'SUM(IF(%s = ' . TransactionEntry::STATUS_PENDING . ', ' . TransactionTable::COLUMN_AMOUNT . ', 0))')->select(TransactionTable::COLUMN_STATUS, 'declines', 'SUM(%s = ' . TransactionEntry::STATUS_DECLINED . ')')->select(TransactionTable::COLUMN_STATUS, 'declines_total', 'SUM(IF(%s = ' . TransactionEntry::STATUS_DECLINED . ', ' . TransactionTable::COLUMN_AMOUNT . ', 0))')->select(TransactionTable::COLUMN_STATUS, 'refunds', 'SUM(%s = ' . TransactionEntry::STATUS_REFUNDED . ')')->select(TransactionTable::COLUMN_STATUS, 'refunds_total', 'SUM(IF(%s = ' . TransactionEntry::STATUS_REFUNDED . ', ' . TransactionTable::COLUMN_AMOUNT . ', 0))')->select(TransactionTable::COLUMN_STATUS, 'chargebacks', 'SUM(%s = ' . TransactionEntry::STATUS_CHARGE_BACK . ')')->select(TransactionTable::COLUMN_STATUS, 'chargebacks_total', 'SUM(IF(%s = ' . TransactionEntry::STATUS_CHARGE_BACK . ', ' . TransactionTable::COLUMN_AMOUNT . ', 0))')->select(TransactionTable::COLUMN_PAYMENT_SOURCE_ID, PaymentSourceTable::COLUMN_SOURCE, "(Select " . PaymentSourceTable::COLUMN_SOURCE . " FROM " . PaymentSourceTable::TABLE_NAME . " WHERE " . PaymentSourceTable::COLUMN_ID . '=' . TransactionTable::COLUMN_PAYMENT_SOURCE_ID . ")")->select(TransactionTable::COLUMN_PRODUCT_ID, "Product")->groupBy(TransactionTable::COLUMN_PAYMENT_SOURCE_ID . ', ' . TransactionTable::COLUMN_PRODUCT_ID)->limit(50)->addRowCallback(function (&$row) {
         /** @var AbstractPaymentSource $Source */
         $Source = unserialize($row[PaymentSourceTable::COLUMN_SOURCE]);
         unset($row[PaymentSourceTable::COLUMN_SOURCE]);
         $cur = $Source->getCurrency();
         $row['total '] = vsprintf('(%0d) <span class="total">%1.2f</span>', $row) . ' ' . $cur;
         unset($row['count'], $row['total']);
         $row['approves '] = vsprintf('(%0d) <span class="total">%1.2f</span>', $row) . ' ' . $cur;
         unset($row['approves'], $row['approves_total']);
         $row['pending '] = vsprintf('(%0d) <span class="total">%1.2f</span>', $row) . ' ' . $cur;
         unset($row['pending'], $row['pending_total']);
         $row['declines '] = vsprintf('(%0d) <span class="total">%1.2f</span>', $row) . ' ' . $cur;
         unset($row['declines'], $row['declines_total']);
         $row['refunds '] = vsprintf('(%0d) <span class="total">%1.2f</span>', $row) . ' ' . $cur;
         unset($row['refunds'], $row['refunds_total']);
         $row['chargebacks '] = vsprintf('(%0d) <span class="total">%1.2f</span>', $row) . ' ' . $cur;
         unset($row['chargebacks'], $row['chargebacks_total']);
     });
     $StatsTHead = new HTMLPDOQueryTableBody($StatsQuery);
     $StatsTBody = new HTMLSequenceTableBody($StatsQuery, self::CLS_TABLE_TRANSACTION_SEARCH);
     $Account = AbstractAccountType::loadFromSession($SessionRequest);
     if ($Account instanceof MerchantAccount) {
         $SearchQuery->where(TransactionTable::COLUMN_PRODUCT_ID, $Account->getID(), "IN (Select " . ProductTable::COLUMN_ID . "\n\tFROM " . ProductTable::TABLE_NAME . "\n\tWHERE " . ProductTable::COLUMN_ACCOUNT_ID . " = ?)");
         $StatsQuery->where(TransactionTable::COLUMN_PRODUCT_ID, $Account->getID(), "IN (Select " . ProductTable::COLUMN_ID . "\n\tFROM " . ProductTable::TABLE_NAME . "\n\tWHERE " . ProductTable::COLUMN_ACCOUNT_ID . " = ?)");
     } else {
         if ($Account instanceof AdministratorAccount) {
             //		} else if ($Account instanceof ProcessorAccount) {
             //			$SearchQuery->where(TransactionTable::COLUMN_PAYMENT_SOURCE_ID, $Account->getID(),
             //				"IN (Select " . PaymentSourceTable::COLUMN_ID
             //				. "\n\tFROM " . PaymentSourceTable::TABLE_NAME
             //				. "\n\tWHERE " . PaymentSourceTable::C. " = ?)"
             //			);
         } else {
             $SearchQuery->where(TransactionTable::COLUMN_ID, '-1');
         }
     }
     $Form = new HTMLForm(self::FORM_METHOD, $Request->getPath(), self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderStyleSheet(__DIR__ . '/assets/search-transaction.css'), new HTMLElement('fieldset', 'fieldset-search fieldset-filter-search', new HTMLElement('legend', 'legend-filter-search', self::TITLE), new HTMLElement('fieldset', 'fieldset-filter-stats-results', new HTMLElement('legend', 'legend-filter-stats-results', 'Stats'), new HTMLTable($StatsTHead, $StatsTBody)), "<br/>", new HTMLElement('fieldset', 'fieldset-filter-search-results', new HTMLElement('legend', 'legend-filter-search-results', 'Search Results'), $SearchTable, $Pagination), "<br/>", new HTMLSubmit(null, 'Search')), "<br/>");
     $Form->setFormValues($Request);
     return $Form;
 }
 /**
  * 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 \Exception
  * @return IResponse the execution response
  */
 function execute(IRequest $Request)
 {
     $SessionRequest = $Request;
     if (!$SessionRequest instanceof ISessionRequest) {
         throw new \Exception("Session required");
     }
     $ProductForms = array();
     /** @var AbstractWallet[] $WalletTypes */
     $WalletTypes = array();
     $walletOptions = array('Choose a Wallet' => null);
     $WalletForms = array();
     $Products = ProductEntry::loadSessionProducts($SessionRequest);
     $productOptions = array('Choose a Product' => null);
     foreach ($Products as $ProductEntry) {
         $Product = $ProductEntry->getProduct();
         $productOptions[$Product->getTotalCost() . ' - ' . $Product->getProductTitle()] = $ProductEntry->getID();
         $Product = $ProductEntry->getProduct();
         $FieldSet = $Product->getOrderFieldSet($Request);
         $key = $ProductEntry->getID();
         $FieldSet->setAttribute('data-' . self::PARAM_PRODUCT_ID, $key);
         $ProductForms[] = $FieldSet;
         foreach ($Product->getWalletTypes() as $WalletType) {
             $key = $WalletType->getTypeName();
             $WalletTypes[$key] = $WalletType;
             $FieldSet = $WalletType->getFieldSet($Request);
             $FieldSet->setAttribute('data-' . self::PARAM_WALLET_ID, $key);
             $FieldSet->setAttribute('disabled', 'disabled');
             $WalletForms[] = $FieldSet;
             $walletOptions['New ' . $WalletType->getDescription()] = $key;
         }
     }
     $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;
     }
     //		$walletTypes = Config::$AvailableWalletTypes;
     $Form = new HTMLForm(self::FORM_METHOD, self::FORM_ACTION, self::FORM_NAME, new HTMLMetaTag(HTMLMetaTag::META_TITLE, self::TITLE), new HTMLHeaderScript(__DIR__ . '/assets/transaction.js'), new HTMLHeaderStyleSheet(__DIR__ . '/assets/transaction.css'), new HTMLElement('fieldset', 'fieldset-create-transaction', new HTMLElement('legend', 'legend-wallet', self::TITLE), new HTMLElement('fieldset', 'fieldset-transaction', new HTMLElement('legend', 'legend-transaction', 'Transaction Details'), new HTMLElement('label', null, "Status<br/>", new HTMLSelectField(self::PARAM_TRANSACTION_STATUS, TransactionEntry::$StatusOptions, new RequiredValidation())), "<br/><br/>", new HTMLElement('label', null, "Product<br/>", new HTMLSelectField(self::PARAM_PRODUCT_ID, $productOptions, new RequiredValidation())), "<br/><br/>", $ProductForms), new HTMLElement('fieldset', 'fieldset-choose-wallet', new HTMLElement('legend', 'legend-wallet', 'Choose a Wallet'), new HTMLElement('label', null, new HTMLSelectField(self::PARAM_WALLET_ID, $walletOptions, new RequiredValidation())), "<br/><br/>", $WalletForms), "<br/><br/>Submit:<br/>", new HTMLButton('submit', 'Create Transaction', 'submit')), "<br/>");
     if (!$Request instanceof IFormRequest) {
         return $Form;
     }
     $Form->setFormValues($Request);
     //		$status = (int)$Form->validateField($Request, self::PARAM_TRANSACTION_STATUS);
     //		$email = $Form->validateField($Request, self::PARAM_TRANSACTION_EMAIL);
     $walletType = $Form->validateField($Request, self::PARAM_WALLET_ID);
     $ChosenWallet = $WalletTypes[$walletType];
     $ChosenWallet->validateRequest($Request, $Form);
     $productID = $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));
 }
 /**
  * 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];
 }