protected function recomputeCommissions() { $transactions = $this->getTransactionsSelect(); $this->rule->setTransactionsWhere($transactions->where, 't'); foreach ($transactions->getAllRowsIterator() as $record) { $newCommission = new Pap_Db_Commission(); $newCommission->setTypeId($record->get(Pap_Db_Table_Transactions::COMMISSIONTYPEID)); $newCommission->setTier($record->get(Pap_Db_Table_Transactions::TIER)); $newCommission->setGroupId($this->rule->getCommissionGroupId()); if ($record->get(Pap_Db_Table_Transactions::R_TYPE) == Pap_Common_Constants::TYPE_RECURRING) { $newCommission->setSubtype(Pap_Db_Table_Commissions::SUBTYPE_RECURRING); } else { $newCommission->setSubtype(Pap_Db_Table_Commissions::SUBTYPE_NORMAL); } try { $newCommission->loadFromData(); } catch (Exception $e) { $this->logMessage(sprintf("Error loading commission (%s)", $e->getMessage())); return; } $transaction = new Pap_Db_Transaction(); $transaction->fillFromRecord($record); $transaction->recompute($newCommission); $transaction->update(); $refundTransaction = $transaction->getRefundOrChargebackTransaction(); if (!is_null($refundTransaction) && $refundTransaction->getStatus() != Pap_Common_Constants::STATUS_DECLINED && $refundTransaction->getPayoutStatus() == Pap_Common_Constants::PSTATUS_UNPAID) { $refundTransaction->recompute($newCommission); $refundTransaction->update(); } } $this->logMessage(sprintf("Transactions were updated based on new commission group %s", $this->rule->getCommissionGroupId())); }
private function makeRefund() { $this->debug('2checkout refund started'); $transaction = new Pap_Db_Transaction(); $transaction->setOrderId($this->getSubscriptionID()); try{ $collection = $transaction->loadCollection(array(Pap_Db_Table_Transactions::ORDER_ID)); } catch (Gpf_Exception $e) { $this->debug('2checkout refund failed - Error in loading transactions: '.$e->getMessage()); return; } if($collection->getSize() == 0) { $this->debug('2checkout refund failed: No transactions with order id: '.$this->getSubscriptionID()); return; } foreach($collection as $transactionDb) { $transaction = new Pap_Common_Transaction(); $transaction->processRefundChargeback($transactionDb->getId(), $transactionDb->getType()); $this->debug('2checkout refunded transaction with id '.$transactionDb->getId()); } }
protected function saveTransaction(Pap_Db_Transaction $transaction, $dateInserted) { $transaction->setDateInserted($dateInserted); $transaction->save(); }
public function finishTransaction($newStatus) { $transaction = new Pap_Db_Transaction(); $transaction->setOrderId($_POST['LMI_PAYMENT_NO']); $transaction->setData5($_POST['LMI_SYS_TRANS_NO']); try { $transaction->loadFromData(array(Pap_Db_Table_Transactions::ORDER_ID, Pap_Db_Table_Transactions::DATA5)); } catch (Gpf_DbEngine_NoRowException $e) { $this->debug('No such transaction with order id: ' . $transaction->getOrderId() . ' and data5: ' . $transaction->getData5() . '. Changing status ended.'); return; } $transaction->setStatus($newStatus); $transaction->update(); }
/** * @param array $transactionIds * @return Gpf_DbEngine_Row_Collection */ private function getCollectionFromIds($transactionIds) { $collection = new Gpf_DbEngine_Row_Collection(); foreach ($transactionIds as $transactionId) { $row = new Pap_Db_Transaction(); $row->setId($transactionId); $row->load(); $collection->add($row); } return $collection; }
/** * * @service commission write * @param $fields * @return Gpf_Rpc_Action */ public function deleteCommissionType(Gpf_Rpc_Params $params) { $action = new Gpf_Rpc_Action($params); $action->setErrorMessage($this->_('Failed to delete type, some transactions are connected to this type. Remove them first.')); $action->setInfoMessage($this->_('Commission type successfully removed')); $commTypeId = $action->getParam('commtypeid'); $transaction = new Pap_Db_Transaction(); $transaction->setCommissionTypeId($commTypeId); $collection = $transaction->loadCollection(array(Pap_Db_Table_Transactions::COMMISSIONTYPEID)); if ($collection->getSize() > 0) { $action->addError(); return $action; } $commissionType = new Pap_Db_CommissionType(); $commissionType->setId($commTypeId); $commissionType->delete(); $action->addOk(); return $action; }
/** * @return Pap_Db_Transaction */ public function getRefundOrChargebackTransaction() { $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->addAll(Pap_Db_Table_Transactions::getInstance()); $select->from->add(Pap_Db_Table_Transactions::getName()); $select->where->add(Pap_Db_Table_Transactions::PARRENT_TRANSACTION_ID, '=', $this->getId()); $select->where->add(Pap_Db_Table_Transactions::R_TYPE, 'IN', array(Pap_Db_Transaction::TYPE_REFUND, Pap_Db_Transaction::TYPE_CHARGE_BACK)); try { $record = $select->getOneRow(); $transaction = new Pap_Db_Transaction(); $transaction->fillFromRecord($record); return $transaction; } catch (Gpf_Exception $e) { return null; } }
protected function insertTransaction($record) { $obj = new Pap_Db_Transaction(); $obj->setId($record->get('transid')); $obj->setUserId($record->get('affiliateid')); $obj->setCampaignId($record->get('campaignid')); $obj->setDateInserted($record->get('dateinserted')); if($record->get('dateapproved') != '') { $obj->setDateApproved($record->get('dateapproved')); } $obj->setSystemNote("Migrated from PAP3"); $obj->set('countrycode', $record->get('countrycode')); $obj->set('ip', $record->get('ip')); $obj->set('refererurl', $record->get('refererurl')); $obj->set('browser', $record->get('browser')); $obj->setCommission($record->get('commission')); $obj->set('data1', $record->get('data1')); $obj->set('data2', $record->get('data2')); $obj->set('data3', $record->get('data3')); $obj->setFixedCost(0); $obj->setTotalCost($record->get('totalcost')); $obj->setOrderId($record->get('orderid')); $obj->setProductId($record->get('productid')); $obj->setAllowFirstClickData(GPF::YES); $obj->setAllowLastClickData(GPF::YES); if($record->get('payoutstatus') == 2) { $obj->setPayoutStatus('P'); } else { $obj->setPayoutStatus('U'); } $obj->setClickCount(1); $obj->setStatus(Pap3Compatibility_Migration_Pap3Constants::translateStatus($record->get('rstatus'))); $obj->setType(Pap3Compatibility_Migration_Pap3Constants::translateTransType($record->get('transtype'))); $transKind = $record->get('transkind'); if($transKind > Pap3Compatibility_Migration_Pap3Constants::TRANSKIND_SECONDTIER) { $tier = $transKind - Pap3Compatibility_Migration_Pap3Constants::TRANSKIND_SECONDTIER; } else { $tier = 1; } $obj->setTier($tier); $obj->set('bannerid', $record->get('bannerid')); $obj->set('commtypeid', $record->get('campcategoryid')); if($record->get('accountingid') != '') { $obj->set('payouthistoryid', $record->get('accountingid')); } $obj->save(); //bannerid char(8) utf8_general_ci YES MUL (NULL) select,insert,update,references //parentbannerid varchar(8) utf8_general_ci YES MUL (NULL) select,insert,update,references //parenttransid char(8) utf8_general_ci YES MUL (NULL) select,insert,update,references //recurringcommid char(8) utf8_general_ci YES (NULL) select,insert,update,references //firstclicktime datetime (NULL) YES (NULL) select,insert,update,references //firstclickreferer varchar(250) utf8_general_ci YES (NULL) select,insert,update,references //firstclickip varchar(15) utf8_general_ci YES (NULL) select,insert,update,references //firstclickdata1 varchar(40) utf8_general_ci YES (NULL) select,insert,update,references //firstclickdata2 varchar(40) utf8_general_ci YES (NULL) select,insert,update,references //lastclicktime datetime (NULL) YES (NULL) select,insert,update,references //lastclickreferer varchar(250) utf8_general_ci YES (NULL) select,insert,update,references //lastclickip varchar(15) utf8_general_ci YES (NULL) select,insert,update,references //lastclickdata1 varchar(40) utf8_general_ci YES (NULL) select,insert,update,references //lastclickdata2 varchar(40) utf8_general_ci YES (NULL) select,insert,update,references //trackmethod char(1) utf8_general_ci YES U select,insert,update,references //commtypeid char(8) utf8_general_ci YES MUL (NULL) select,insert,update,references //payouthistoryid char(8) utf8_general_ci YES MUL (NULL) select,insert,update,references $this->countSales++; }
public function getUserId() { return $this->transaction->getUserId(); }
protected function addRefundChargeback(Pap_Db_Transaction $refundChargeback, $type, $note = '', $orderId = '', $fee = 0) { foreach ($this as $name => $value) { $refundChargeback->set($name, $value); } $refundChargeback->setId(Gpf_Common_String::generateId()); $refundChargeback->setCommission(($this->getCommission() * -1) - $fee); $refundChargeback->setType($type); if ($orderId != '') { $refundChargeback->setOrderId($orderId); } $refundChargeback->setParentTransactionId($this->getId()); $refundChargeback->setDateInserted(Gpf_Common_DateUtils::now()); $refundChargeback->setPayoutStatus(Pap_Common_Constants::PSTATUS_UNPAID); $refundChargeback->setMerchantNote($note); if ($refundChargeback->getStatus() == Pap_Common_Constants::STATUS_APPROVED) { $refundChargeback->setDateApproved($refundChargeback->getDateInserted()); } else { $refundChargeback->setDateApproved(''); } $refundChargeback->insert(); }
/** * @param Pap_Db_Transaction $transaction * @return string */ private function outputAddedTransacion(Pap_Db_Transaction $transaction) { $output = ''; $output .= $this->outputln($this->_('Added transaction:'), 'font-weight: bold; color: green;'); $output .= $this->output($this->_('Transaction ID'), 'font-weight: bold;') . ': ' . $transaction->getId() . ', '; $output .= $this->output($this->_('Parent transaction ID'), 'font-weight: bold;') . ': ' . $transaction->getParentTransactionId() . ', '; $output .= $this->output($this->_('Order ID'), 'font-weight: bold;') . ': ' . $transaction->getOrderId() . ', '; $output .= $this->output($this->_('Affiliate'), 'font-weight: bold;') . ': ' . $transaction->getUserId() . ', '; $output .= $this->output($this->_('TotalCost'), 'font-weight: bold;') . ': ' . $transaction->getTotalCost() . ', '; $output .= $this->output($this->_('Commission'), 'font-weight: bold;') . ': ' . $transaction->getCommission() . ', '; $output .= $this->output($this->_('Tier'), 'font-weight: bold;') . ': ' . $transaction->getTier(); $output .= '<br />'; return $output; }
/** * * @param $transaction * @return Pap_Db_Transaction */ private function copyTransaction(Pap_Common_Transaction $transaction) { $dbTransaction = new Pap_Db_Transaction(); foreach ($transaction->getAttributes() as $name => $value) { $dbTransaction->set($name, $value); } return $dbTransaction; }