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); } }