Example #1
0
 public function getResultsById($id, $ps = null)
 {
     if (!$id) {
         return array();
     }
     $db = self::$_msql = SafeMySQL::getInstance();
     $sql = "SELECT\n\t\t\t\tpm.`profile_id`,\n\t\t\t\tpm.`method_id`,\n\t\t\t\tm.`method_name`,\n\t\t\t\tm.`method_ref`,\n\t\t\t\tpm.`load_balance`,\n\t\t\t\tg.`system_code`\n              FROM `profiles_methods` as pm\n\t\t\t  JOIN `methods` as m on m.`method_id` = pm.`method_id`\n\t\t\t  JOIN `profiles_gateways` as pg on pg.`profile_id` = pm.`profile_id` and pg.`method_id` = pm.`method_id`\n\t\t\t  JOIN `gateways` as g on g.`gateway_id` = pg.`gateway_id`\n              WHERE pm.`profile_id` = ?i";
     if ($ps && strlen($ps)) {
         $sql .= " AND g.`system_code` = ?s";
         $sqlParse = $db->parse($sql, $id, $ps);
     } else {
         $sqlParse = $db->parse($sql, $id);
     }
     return $this->getSqlParse($sqlParse);
 }
Example #2
0
 private function buildPayment()
 {
     // check payment variables.  default to cc_debit
     if (!isset($this->post['ps'])) {
         $this->post['ps'] = null;
     }
     // removing PS and letting the profile functions figure out the payment system
     //$this->post['ps'] = (strlen($this->post['ps'])) ? $this->post['ps'] : 'pn';
     $this->post['payment_method'] = strlen($this->post['payment_method']) ? $this->post['payment_method'] : 'cc_debit';
     if (!isset($this->payment)) {
         $this->payment = new Payment();
     }
     if (!$this->payment->getPkValue()) {
         $this->payment->created = $this->payment->updated = 'NOW():sql';
         //date("Y-m-d H:i:s");
         $this->payment->customer_id = $this->customer->customer_id;
         // Check for 'DRY RUN GATEWAY'
         if ($this->campaign->profile_id) {
             // grab accepted payment methods based on payment system
             $profileMethods = new ProfileMethods('ProfileMethod');
             $profileMethods->loadId($this->campaign->profile_id, $this->post['ps']);
             if (!$profileMethods->isMethodValid($this->post['payment_method'], $this->post['ps'])) {
                 //is there only available option? if so, assign id to the value
                 if (count($profileMethods->records) == 1) {
                     $this->post['payment_method'] = $profileMethods->records[0]->method_ref;
                 } else {
                     // multiple ids available. abort
                     $this->apiError('invalid payment supplied');
                 }
             }
             // set payment method id
             $this->payment->method_id = $profileMethods->getMethodId($this->post['payment_method'], $this->post['ps']);
         } else {
             // DRY RUN GATEWAY - let's setup some values
             $mid = Method::getMethodsIdByRef($this->post['payment_method']);
             $this->payment->method_id = $mid ? $mid : 1;
         }
         $this->payment->fillFromMethodArray($this->post);
         if (!$this->payment->validateByMethodFields()) {
             $errors = $this->payment->errors;
             $validationErrors = $errors['validation_errors'];
             fb($this->payment->getErrors());
             $this->apiError('Invalid Payment Information - ');
         }
         // Is this a cc_debit order?  If so, are there any specific CC methods setup for this campaign? DISABLE FOR CRM Orders
         // for example, if the CC is a mastercard and we have a mastercard only gateway, then default to it
         if ($this->campaign->profile_id && $this->payment->method_id == 1 && $this->wsType != 'x1') {
             // check for other CC methods
             $ccMethodId = ProfileGateways::getMethodByCC($this->campaign->profile_id, 'cc_' . PaymentSystem::getCardTypeSimple($this->payment->cc_number), $this->post['ps']);
             if ($ccMethodId) {
                 $this->payment->method_id = $ccMethodId;
             }
             unset($ccMethodId);
         }
         // is this a new customer?  if not, are there any other payment records for this customer that might be the same?
         $payments = new Payments('Payment');
         $payments->loadPaymentsByCustomer($this->customer->customer_id);
         // existing payment ID flag/PK
         $pid = 0;
         // check to see if the sent over info is duplicate
         if (count($payments->records)) {
             $pid = $payments->paymentExists($this->payment);
         }
         if (!$pid) {
             // save new payment record
             if (!$this->payment->save()) {
                 $this->apiError('invalid payment record');
             }
         } else {
             $this->payment->fillFromDbPk($pid);
         }
         unset($payments);
     }
 }