protected function _beforeRender(KControllerContextInterface $context) { $controller = $context->getSubject(); $request = $controller->getRequest(); foreach ($this->_vars as $name => $param) { if (is_numeric($name)) $name = $param; $method = '_set' . ucfirst($name); if (method_exists($this, $method)) { call_user_func_array(array($this, $method), array($request, $param)); } else { $request->query->set($name, $this->_params->get($param)); } } if ($request->getFormat() == 'rss') { $query = $request->getQuery(); $states = array('limit' => 20, 'offset' => 0, 'sort' => 'created_on', 'direction' => 'desc'); foreach ($states as $name => $value) { $query->set($name, $value); // Set as internal. $controller->getModel()->getState()->setProperty($name, 'internal', true); } } // Update the model state. $controller->getModel()->setState($request->getQuery()->toArray()); }
public function prepareGatewayPaypal_express_checkout(KControllerContextInterface $context) { //TODO: Check if cart is not empty! $data = $context->request->data; $entity = $context->result; $storage = $this->getPayum()->getStorage('ComSalesModelEntityPayment'); $payment = $storage->create(); $payment->setNumber(uniqid()); $payment->setCurrencyCode($entity->currency_code); $payment->setClientEmail($data->email); $items = array(); $index = 0; foreach ($entity->cart->items as $item) { $items['L_PAYMENTREQUEST_0_NAME' . $index] = $item['name']; $items['L_PAYMENTREQUEST_0_AMT' . $index] = number_format($item['price'], 2); $items['L_PAYMENTREQUEST_0_QTY' . $index] = $item['quantity']; $index++; } //TODO: Improve! $entity->discount = $entity->discount ? $entity->discount : new KObjectConfig(array()); $entity->discount->append(array('coupons' => array(), 'amount' => 0)); foreach ($entity->discount->coupons as $coupon) { $items['L_PAYMENTREQUEST_0_NAME' . $index] = $coupon->title; $items['L_PAYMENTREQUEST_0_DESC' . $index] = '20% discount'; $items['L_PAYMENTREQUEST_0_AMT' . $index] = number_format(-$coupon->amount, 2); $items['L_PAYMENTREQUEST_0_QTY' . $index] = 1; $index++; } $payment->setTotalAmount(($entity->cart['total_price'] - $entity->discount['amount']) * 100); $payment->setDetails(array_merge($items, array('uuid' => $entity->uuid, 'referrer' => urlencode($context->request->getReferrer()), 'transaction_id' => 'N/A', 'payment_type' => 'PayPal Express Checkout', 'account_info' => 'N/A'))); $storage->update($payment); $context->getSubject()->setPayment($payment); }
/** * Before Attach command handler. * * Serves as a validation check. * * @param KControllerContextInterface $context The context object. */ protected function _beforeAttach(KControllerContextInterface $context) { $entity = $context->getSubject()->getModel()->fetch(); if ($entity->isNew()) { throw new RuntimeException('Entity does not exists'); } $context->entity = $entity; }
/** * Create an Invoice * * @todo define an array of entity fields to map to invoice fields * * @param KControllerContextInterface $context * * @return void */ protected function _afterAdd(KControllerContextInterface $context) { $entity = $context->result; // Order entity $data = array('package' => $context->getSubject()->getIdentifier()->package, 'customer_id' => $entity->account_number, 'order_id' => $entity->id, 'product_name' => $entity->package_name, 'amount' => $entity->package_price); $controller = $this->getObject($this->_controller); if ($controller instanceof KControllerModellable) { $controller->add($data); } }
public function prepareGatewayPaypal_pro_checkout(KControllerContextInterface $context) { //TODO: Check if cart is not empty! $data = $context->request->data; $entity = $context->result; $storage = $this->getPayum()->getStorage('ComSalesModelEntityPayment'); $payment = $storage->create(); $payment->setNumber(uniqid()); $payment->setCurrencyCode($entity->currency_code); $payment->setTotalAmount(number_format($entity->cart->total_price - $entity->discount->amount, 2, '.', '')); $payment->setClientEmail($data->email); $payment->setDetails(array('uuid' => $entity->uuid, 'referrer' => urlencode($context->request->getReferrer()), 'payment_type' => 'Credit Card', 'ACCT' => preg_replace('/\\s+/', '', $data->cc_num), 'CVV2' => $data->cc_cvc, 'EXPDATE' => $data->cc_exp_month . $data->cc_exp_year, 'NAME' => isset($data->card_holders_name) ? $data->card_holders_name : null, 'COMMENT1' => isset($data->comment_1) ? $data->comment_1 : null, 'COMMENT2' => isset($data->comment_2) ? $data->comment_2 : null, 'FIRSTNAME' => isset($data->first_name) ? $data->first_name : null, 'LASTNAME' => isset($data->last_name) ? $data->last_name : null, 'EMAIL' => isset($data->email) ? $data->email : null, 'PHONENUM' => isset($data->phone_number) ? $data->phone_number : null, 'STREET' => isset($data->street_address) ? $data->street_address : null, 'CITY' => isset($data->city) ? $data->city : null, 'STATE' => isset($data->state) ? $data->state : null, 'ZIP' => isset($data->zip_code) ? $data->zip_code : null)); $storage->update($payment); $context->getSubject()->setPayment($payment); }
public function prepareGatewayOffline(KControllerContextInterface $context) { //TODO: Check if cart is not empty! $data = $context->request->data; $entity = $context->result; $storage = $this->getPayum()->getStorage('ComSalesModelEntityPayment'); $payment = $storage->create(); $payment->setNumber(uniqid()); $payment->setCurrencyCode($entity->currency_code); $payment->setClientEmail($data->email); $payment->setTotalAmount($entity->total_price); $payment->setDetails(array('uuid' => $entity->uuid, 'referrer' => urlencode($context->request->getReferrer()), 'transaction_id' => 'N/A', 'payment_type' => 'Offline', 'account_info' => 'N/A', 'paid' => 0)); $storage->update($payment); $context->getSubject()->setPayment($payment); }
/** * Execute an action by triggering a method in the derived class. * * @param string $action The action to execute * @param KControllerContextInterface $context A command context object * @throws Exception * @throws BadMethodCallException * @return mixed|bool The value returned by the called method, false in error case. */ public function execute($action, KControllerContextInterface $context) { $action = strtolower($action); //Set the context subject $context_subject = $context->getSubject(); $context->setSubject($this); //Set the context action $context_action = $context->getAction(); $context->setAction($action); //Execute the action if ($this->invokeCommand('before.' . $action, $context) !== false) { $method = '_action' . ucfirst($action); if (!method_exists($this, $method)) { if (isset($this->_mixed_methods[$action])) { $context->setName('action.' . $action); $context->result = $this->_mixed_methods[$action]->execute($context, $this->getCommandChain()); } else { throw new KControllerExceptionActionNotImplemented("Can't execute '{$action}', method: '{$method}' does not exist"); } } else { $context->result = $this->{$method}($context); } $this->invokeCommand('after.' . $action, $context); } //Reset the context $context->setSubject($context_subject); $context->setAction($context_action); return $context->result; }