/** * Init payment listeners * * @param \Zend\EventManager\EventInterface $e */ public function initPaymentListeners(EventInterface $e) { $model = $this->serviceManager->get('Application\\Model\\ModelManager')->getInstance('Payment\\Model\\PaymentBase'); // update a user transactions info $eventManager = PaymentEvent::getEventManager(); if ($model->getModuleInfo('Payment')) { // init edit and update events for payment modules foreach ($model->getPaymentModules() as $module) { // get the payment handler $paymentHandler = $this->serviceManager->get('Payment\\Handler\\PaymentHandlerManager')->getInstance($module->handler); // update items $eventManager->attach($module->update_event, function ($e) use($model, $paymentHandler, $module) { $model->updateItemGlobally($e->getParam('object_id'), $paymentHandler, $module); }); // delete items $eventManager->attach($module->delete_event, function ($e) use($model, $module) { $model->deleteItemGlobally($e->getParam('object_id'), $module->module); }); } } }
/** * Activate a discount coupon */ public function ajaxActivateDiscountCouponAction() { $refreshPage = false; $discountForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('Payment\\Form\\PaymentDiscountForm')->setModel($this->getModel()); $request = $this->getRequest(); if ($request->isPost()) { $discountForm->getForm()->setData($request->getPost(), false); if ($discountForm->getForm()->isValid()) { // activate a discount coupon $couponCode = $discountForm->getForm()->getData()['coupon']; // save the activated discount coupon's ID in sessions PaymentService::setDiscountCouponId($this->getModel()->getCouponInfo($couponCode, 'slug')['id']); // fire the activate discount coupon event PaymentEvent::fireActivateDiscountCouponEvent($couponCode); $this->flashMessenger()->setNamespace('success')->addMessage($this->getTranslator()->translate('The coupon code has been activated')); $refreshPage = true; } } $view = new ViewModel(['discount_form' => $discountForm->getForm(), 'refresh_page' => $refreshPage]); return $view; }
/** * Add to shopping cart * * @param array $itemInfo * integer object_id - required * integer module - required * string title - required * string|integer slug - optional * float cost - required * integer|float discount - optional * integer count - required * string extra_options - optional (serialized array) * @return integer|string */ public function addToShoppingCart(array $itemInfo) { try { $this->adapter->getDriver()->getConnection()->beginTransaction(); $insert = $this->insert()->into('payment_shopping_cart')->values(array_merge($itemInfo, ['shopping_cart_id' => $this->getShoppingCartId(), 'date' => time(), 'language' => $this->getCurrentLanguage()])); $statement = $this->prepareStatementForSqlObject($insert); $statement->execute(); $insertId = $this->adapter->getDriver()->getLastGeneratedValue(); $this->adapter->getDriver()->getConnection()->commit(); } catch (Exception $e) { $this->adapter->getDriver()->getConnection()->rollback(); ApplicationErrorLogger::log($e); return $e->getMessage(); } // fire the add item to shopping cart event PaymentEvent::fireAddItemToShoppingCartEvent($insertId); return $insertId; }
/** * Edit exchange rates * * @param array $exchangeRatesInfo * integer id * string code * sting name * float rate * @param array $exchangeRates * float rate * @param integer $currencyId * @return boolean|string */ public function editExchangeRates(array $exchangeRatesInfo, array $exchangeRates, $currencyId) { try { $this->adapter->getDriver()->getConnection()->beginTransaction(); // delete old rates $this->clearExchangeRates(); // insert new rates foreach ($exchangeRates as $code => $rate) { // skip empty values if (!(double) $rate) { continue; } $insert = $this->insert()->into('payment_exchange_rate')->values(['rate' => $rate, 'currency' => $exchangeRatesInfo[$code]['id']]); $statement = $this->prepareStatementForSqlObject($insert); $statement->execute(); } $this->adapter->getDriver()->getConnection()->commit(); } catch (Exception $e) { $this->adapter->getDriver()->getConnection()->rollback(); ApplicationErrorLogger::log($e); return $e->getMessage(); } // fire the edit exchange rates event PaymentEvent::fireEditExchangeRatesEvent($currencyId); return true; }
/** * Delete transaction * * @param integer $transactionId * @param integer $userId * @param string $type * @return boolean|string */ public function deleteTransaction($transactionId, $userId = null, $type = null) { try { $this->adapter->getDriver()->getConnection()->beginTransaction(); $delete = $this->delete()->from('payment_transaction_list')->where(['id' => $transactionId]); if ($userId) { $delete->where(['user_id' => $userId]); } $statement = $this->prepareStatementForSqlObject($delete); $result = $statement->execute(); $this->adapter->getDriver()->getConnection()->commit(); } catch (Exception $e) { $this->adapter->getDriver()->getConnection()->rollback(); ApplicationErrorLogger::log($e); return $e->getMessage(); } if ($result->count()) { // fire the delete payment transaction event PaymentEvent::fireDeletePaymentTransactionEvent($transactionId, $type); return true; } return false; }