function webPayment() { if (!isset($this->payment) || !$this->payment->payment_id) { $this->payment = new Payment(); if (!$this->payment->fillFromDbPk($this->order->payment_id)) { $this->apiError('Invalid Payment Request'); } else { // if this is an SS upsell order and BLS type payment, set the cc_encrypt fields from the DB values if ($this->wsType == 'u' && $this->payment->method_id == 14) { $this->payment->cc_number_encrypt = $this->payment->txt3; $this->payment->cc_cvv_encrypt = $this->payment->txt4; } } } // remove salvage flag if needed if ($this->order->isFlag('salvage')) { $this->order->removeFlags('salvage'); $this->order->save(); } // Is this a real payment profile? check to make sure the gateway is still current. if not, switch to cur // IGNORE FOR ATTACHMENT/CHARITY/1Click CAMPS. gateway_id used will be what's already in the order->gateway_id if ($this->campaign->profile_id && $this->wsType != 'c') { $gid = ProfileGateways::getCurrentGatewayByIds($this->campaign->profile_id, $this->payment->method_id, $this->post['ps']); // ,$this->order->gateway->system_code if ($gid && $gid != $this->order->gateway_id) { $this->order->gateway_id = $gid; } else { if (!$gid && !$this->order->gateway_id) { $gid = 5; } } // set to DEFAULT gateway_id so at least the card can be charged. Do we want to error out here? unset($gid); } $paymentAPI = new PaymentAPI(); $paymentAPI->setModel($this->payment); $total = $this->order->amount_product + $this->order->amount_shipping; $externalRedirect = false; if (!$this->test) { $paymentResponse = $paymentAPI->payOrder($this->order->order_id, $total); if ($this->wsType != 'x1') { fb($paymentAPI); fb($paymentResponse); } } // what happened? // ($this->order->isFlag('test') && $this->payment->cc_number == Config::get()->payments->pacnet['testCC']) || if ($this->test || $paymentResponse->getstatus() != 'error') { // ACCEPTED if ($this->test || !isset($paymentResponse->redirectUrl)) { // || (!isset($paymentResponse->redirectUrl) && $this->payment->method_id != 14) $this->order->status = 'ok'; } if ($this->test || $paymentResponse->attemptStatus == Attempt::SUCCESS_STATUS) { //(stripos($this->payment->method->method_ref,'cc_') !== false && $this->payment->method_id != 14)) { // APPROVED / PAID // was the payment actually processed, like a cc_debit? set order total // set the paid flag and payment_total if an attempt status = success $this->order->addFlags('paid'); $this->order->payment_total = $total; } else { // was the payment accepted by the gateway, but not actually processed? //$this->order->addFlags('paid'); if (isset($paymentResponse->redirectUrl)) { $externalRedirect = true; } } $this->order->updated = 'NOW():sql'; //date("Y-m-d H:i:s"); if (!$this->order->save()) { //this should never happen. just log the error, email the team and assume its all good for the customer fb($this->order->getErrors()); $msg = 'POST PAYMENT ORDER SAVE ERROR ' . print_r($this->order->getErrors(), 1); $ord = json_encode($this->order); $pst = isset($this->post) ? json_encode($this->post) : json_encode($_POST); $dump = $msg . PHP_EOL . PHP_EOL . $ord . PHP_EOL . $pst . PHP_EOL; error_log($dump, 3, getcwd() . "/api_error_log.log"); } // is this a prospect salvage order? DON'T NEED THIS ANYMORE SINCE PROSPECT EMAILS ARE HANDLED BY SILVERPOP // ProspectEmail::setProspectSale($this->order->campaign_id,$this->order->customer_id); // If this is a gc order, don't finalize the order until payment confirmation comes through if (!$externalRedirect && ($this->order->status == 'ok' && $this->order->isFlag('paid'))) { $this->finalizeOrder(); } // GATEWAY ROUTING UPDATE - DISABLED FOR NOW // using try/catch here in case something happens the user will still be taken back to the thankyou page try { // NEED TO UPDATE THE GATEWAY LIMITS AND STATUS. WOULD BE BENEFICIAL IS THIS WERE SOMEHOW AN ASYNCHRONOUS FUNCTION CALL // REENABLE!!!!! //if(!$this->order->isFlag('test')) { $pg = new ProfileGateways('ProfileGateway'); $o = clone $this->order; $pg->processGatewayRoutingByOrder($o); unset($o); //} } catch (Exception $e) { $msg = 'GATEWAY ROUTING UPDATE ERROR'; $ord = json_encode($this->order->getDataArray()); $pst = isset($this->post) ? json_encode($this->post) : json_encode($_POST); $dump = $msg . PHP_EOL . $ord . PHP_EOL . $pst . PHP_EOL; error_log($dump, 3, getcwd() . "/api_error_log.log"); } // If this is a gc order, don't process the attached orders if (!$externalRedirect) { // direct to return_url if not CRM order if ($this->wsType != 'x1') { $this->thankYou(); } } else { // GC Payment redirect $this->apiSuccess($paymentResponse->redirectUrl); } } else { // DECLINED $msg = $this->declinedOrder($paymentResponse); $this->apiError($msg); } }
public function createAction() { $model = new Order(); $_POST['status'] = 'new'; $isPayment = AF::get($_POST, 'is_payment'); if (!$isPayment) { $_POST['ps'] = 'pn'; $_POST['payment_method'] = 'cc_debit'; } /*$rtr = ''; foreach($_POST as $k => $v) { $rtr .= " '".$k."' => '".$v."',"; } Message::echoJsonSuccess($rtr);*/ // is this also a new customer creation if (isset($_POST['newCus']) && $_POST['newCus'] == 1) { $cust = new Customer(); $this->performAjaxValidation($cust); //$shipData = (array)json_decode($_POST['shipAddr']); //$shipData['address_type'] = 'shipping'; $this->performAjaxFormFieldsValidation($_POST, explode(',', 'shipping_fname,shipping_lname,shipping_phone,shipping_address1,shipping_city,shipping_state_id,shipping_country_id,shipping_zip')); //Message::echoJsonSuccess('made it2'); if (!$_POST['billingSameAsShipping']) { //$billData = (array)json_decode($_POST['billAddr']); //$billData['address_type'] = 'billing'; $this->performAjaxFormFieldsValidation($_POST, explode(',', 'billing_fname,billing_lname,billing_phone,billing_address1,billing_city,billing_state_id,billing_country_id,billing_zip')); } $orderRules = "campaign_id,gateway_id,shipping_id,amount_product,amount_shipping,payment_total"; } else { $_POST['newCus'] = 0; $orderRules = "customer_id,campaign_id,gateway_id,shipping_id,amount_product,amount_shipping,payment_total,address_id,billing_address_id"; if (isset($_POST['address_id']) && empty($_POST['billing_address_id'])) { $_POST['billing_address_id'] = $_POST['address_id']; } // before billing validation } // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model, explode(',', $orderRules)); if (isset($_POST['model']) && $_POST['model'] == 'Order') { $isOrderPay = $this->access->actionAccess('order_is_pay') ? (bool) AF::get($_POST, 'is_payment') : false; $_POST['is_payment'] = $isOrderPay ? 1 : 0; // JSON success and error commands handled in the WS functions $ws = new WS(); $ws->crmInit($_POST); $ws->process(); } $orderID = AF::get($this->params, 'order_id', false); $prospectID = AF::get($this->params, 'prospect_id', false); $payments = array(); if ($orderID) { $model->fillFromDbPk($orderID); // if we use clone model then we cannot grab related fields $model->getCopyModel(); $orderProducts = OrderProducts::getProductsArrayByOrder($model->order_id); $payment_methods = ProfileGateways::getMethodsByProfileGateway($model->campaign->profile_id, $model->gateway_id); $cPayments = new Payments('Payment'); $payments = $cPayments->getResultsByCustomerId($model->customer_id, false); } elseif ($prospectID) { $modelProspect = Prospect::model()->findByPk($prospectID); if (!$modelProspect) { throw new AFHttpException(0, 'incorrect_id'); } $model->customer_id = $modelProspect->customer_id; $model->campaign_id = $modelProspect->campaign_id; $model->address_id = $modelProspect->address_id; $orderProducts = array(); $payment_methods = array(); } else { $orderProducts = array(); $payment_methods = array(); } $productModel = new Product(); $products = $productModel->getAvailableByCampaignID($model->campaign_id); $countryModel = new Country(); $languages = $countryModel->getLanguages(); $states = $model->country_id ? State::model()->getStatesByCID($model->country_id) : array(); //$model->country_ids='de,ir'; $countries = $countryModel->getCountries(); $campaigns = Campaign::model()->cache()->findAllInArray(); $shippingModel = new Shipping(); $shipping = $shippingModel->getAvailableByCampaignID($model->campaign_id); $modelGateways = new Gateway(); //$modelGateways->getGateways() $gateways = $orderID ? $modelGateways->getAvailableByCampaignID($model->campaign_id) : array(); $methods = Method::model()->cache()->findAllInArray(); $fields_expyear = array('current_year' => date("Y"), 'last_year' => date("Y") + 12); Assets::js('jquery.form'); Assets::js('jquery.autocomplete'); Assets::js('as24.bind-1.3.5.min'); Assets::js('jquery-ui'); Assets::css('jquery-ui'); $this->addToPageTitle('Create Order'); $this->render('create', array('model' => $model, 'products' => $products, 'languages' => $languages, 'campaigns' => $campaigns, 'states' => $states, 'countries' => $countries, 'fields_expyear' => $fields_expyear, 'shipping' => $shipping, 'gateways' => $gateways, 'orderProducts' => $orderProducts, 'payment_methods' => $payment_methods, 'payments' => $payments, 'methods' => $methods)); }
function getmethodsbycampaigngatewayAction() { $this->checkLogin(); AF::setJsonHeaders('json'); $gateway_id = AF::get($_POST, 'gateway_id', false); if (!$gateway_id) { Message::echoJsonError(__('incorrect_gateway_id')); } $campaign_id = AF::get($_POST, 'campaign_id', false); $model = new Campaign(); if (!$model->fillFromDbPk($campaign_id)) { Message::echoJsonError(__('incorrect_campaign_id')); } $result = ProfileGateways::getMethodsByProfileGateway($model->profile_id, $gateway_id); if (count($result)) { Message::echoJsonSuccess(array('message' => array('data' => $result))); } else { Message::echoJsonError('No Valid Payment Methods For the Selected Campaign and Gateway'); } exit; }
public static function getMethodsByProfileGateway($profile_id, $gateway_id) { if (!$profile_id) { return array(); } $db = self::$_msql = SafeMySQL::getInstance(); $sql = "SELECT \n\t\t\t\t pg.method_id\n\t\t\t\t, m.method_name\n\t\t\tFROM \n\t\t\t\tprofiles_gateways as pg\n\t\t\t\tleft join methods as m using(method_id)\n\t\t\tWHERE \n\t\t\t \tpg.profile_id = ?i\n\t\t\t\tand pg.gateway_id = ?i"; return $db->getAll($sql, $profile_id, $gateway_id); }