Ejemplo n.º 1
0
 public function createAction()
 {
     $model = new Tax();
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['model']) && $_POST['model'] == 'Tax') {
         $model->fillFromArray($_POST);
         if (isset($_POST['defaultCountryCheck']) && $_POST['defaultCountryCheck']) {
             $model->state_code = null;
         }
         $model->user_id_created = $this->user->user_id;
         $model->user_id_updated = $this->user->user_id;
         $model->updated = 'NOW():sql';
         $model->created = 'NOW():sql';
         $model->model_uset_id = $this->user->user_id;
         if (isset($_POST['ajax'])) {
             if ($model->save()) {
                 $link = AF::link(array('taxes' => 'view'), array('country_id' => $_POST['country_id']));
                 Message::echoJson('success', array('redirect' => $link));
             } else {
                 Message::echoJsonError(__('taxes_not_created') . '. ' . __('tax_record_exists'));
             }
             die;
         } else {
             if (!$model->save()) {
             } else {
                 $this->redirect('view/country_id=' . $_POST['country_id']);
             }
         }
         die;
     }
     $stateCode = AF::get($this->params, 'state_code', null);
     $countryID = AF::get($this->params, 'country_id', null);
     $stateModel = new State();
     if ($stateCode && !$countryID) {
         $stateModel->fillFromStateCode($stateCode);
         $countryID = $stateModel->country_id;
         $this->params['country_id'] = $countryID;
     }
     $countries = Country::model()->cache()->findAllInArray();
     $states = State::model()->getStates($countryID);
     //$countryDefault = Taxs::getCountryDefault($countryID);
     Assets::js('jquery.form');
     $this->addToPageTitle('Create Tax record');
     $this->render('create', array('model' => $model, 'states' => $states, 'countries' => $countries));
 }
Ejemplo n.º 2
0
 public function getStateName()
 {
     $state = new State();
     $state->fillFromStateCode($this->state_id);
     return $state->state_name;
 }
Ejemplo n.º 3
0
 public function payCreditCard()
 {
     $shipStateModel = new State();
     $shipStateModel->fillFromStateCode($this->shippingAddressModel->state_id);
     if ($this->shippingAddressModel->state_id == $this->billingAddressModel->state_id) {
         $billingStateModel = $shipStateModel;
     } else {
         $billingStateModel = new State();
         $billingStateModel->fillFromStateCode($this->billingAddressModel->state_id);
     }
     //set currency_id to options
     $pacnetOptions = $this->gatewayModel->getAttributes();
     $pacnetOptions['currency_id'] = $this->campaignModel->currency_id;
     $pacnetOptions['isTest'] = self::$isTest;
     // Create and populate a request object
     $pymtReq = new RavenRequest('submit', $pacnetOptions);
     $pymtReq->set('Currency', $this->campaignModel->currency_id);
     $pymtReq->set('RequestID', $this->attemptModel->getrequest_id('pn'));
     $pymtReq->set('Amount', $this->attemptModel->amount * 100);
     $pymtReq->set('PymtType', self::CC_DEBIT);
     $pymtReq->set('CardNumber', $this->paymentModel->cc_number);
     $pymtReq->set('ExpiryDate', $this->paymentModel->exp_date);
     $pymtReq->set('CVV2', $this->paymentModel->cc_cvv);
     /*$pymtReq->set('BillingAddressLine1', $this->billingAddressModel->address1);
       $pymtReq->set('BillingAddressLine2', $this->billingAddressModel->address2);
       $pymtReq->set('BillingCity', $this->billingAddressModel->city);
       $pymtReq->set('BillingRegion', $billingStateModel->state_name);
       $pymtReq->set('BillingPostal', $this->billingAddressModel->zip);
       $pymtReq->set('BillingCountry', $this->billingAddressModel->country_id);
       $pymtReq->set('ShipToRegion', $shipStateModel->state_name);
       $pymtReq->set('ShipToCity', $this->shippingAddressModel->city);
       $pymtReq->set('ShipToPostal', $this->shippingAddressModel->zip);
       $pymtReq->set('ShipToCountry', $this->shippingAddressModel->country_id);
       $pymtReq->set('ShippingAddressLine1', $this->shippingAddressModel->address1);
       $pymtReq->set('ShippingAddressLine2', $this->shippingAddressModel->address2);
       $pymtReq->set('ContactEmail', $this->customerModel->email);
       $pymtReq->set('CustomerPhone', $this->shippingAddressModel->phone);*/
     $pymtReq->set('Description', $this->campaignModel->profile->descriptor_name);
     $pymtReq->set('Description2', $this->campaignModel->profile->descriptor_phone);
     //Change Attempt Status to inprogress
     Attempt::setAttemptStatus($this->attemptModel, Attempt::INPROGRESS_STATUS);
     // Submit the request
     try {
         fb($pymtReq);
         //Send request
         $pymtResp = $pymtReq->send();
         fb($pymtResp);
     } catch (Exception $e) {
         //Change Attempt Status to unknown
         Attempt::setAttemptStatus($this->attemptModel, Attempt::UNKNOWN_STATUS);
         $this->_paymetnResponse->addError('error_processing_request');
         $this->_paymetnResponse->addAlert('error_processing_your_request');
         $this->_paymetnResponse->status = PaymentAPIResponse::ERROR_STATUS;
         return false;
     }
     $errors = array();
     if ($pymtResp->get('httpStatus') == 'timeout') {
         $respReq = new RavenRequest('response', $this->gatewayModel->getAttributes());
         $respReq->set('RequestID', $pymtReq->get('RequestID'));
         $pymtResp = $respReq->send();
     }
     if ($pymtResp->get('httpStatus') != 200) {
         $errors['httpStatus'] = $pymtResp->get('httpStatus');
     }
     if ($pymtResp->get('ErrorCode')) {
         $errorCode = strtolower($pymtResp->get('ErrorCode'));
         if (!in_array($errorCode, $errors)) {
             $errors['ErrorCode'] = $errorCode;
         }
     }
     if ($pymtResp->get('Status') != 'Approved') {
         $statusCode = strtolower($pymtResp->get('Status'));
         if (!in_array($statusCode, $errors)) {
             $errors['Status'] = $statusCode;
         }
         if ($pymtResp->get('Message')) {
             $errors['Message'] = $pymtResp->get('Message');
         }
     }
     if ($errors) {
         //Change Attempt Status to decline and save status note
         //Attempt::setAttemptStatus($this->attemptModel, Attempt::DECLINED_STATUS);
         $this->attemptModel->status = Attempt::DECLINED_STATUS;
         // including try catch because I'm not sure the "get" command will work for all error statuses
         try {
             if ($pymtResp->get('TrackingNumber')) {
                 $this->attemptModel->tracking_number = $pymtResp->get('TrackingNumber');
             }
         } catch (Exception $e) {
             // do nothing
         }
         $this->attemptModel->status_note = implode(',', $errors);
         $this->attemptModel->save();
         foreach ($errors as $key => $error) {
             $this->_paymetnResponse->addError($key, $error);
         }
         $this->_paymetnResponse->addAlert('error_processing_your_request');
         $this->_paymetnResponse->status = PaymentAPIResponse::ERROR_STATUS;
         $this->_paymetnResponse->attemptModel = $this->attemptModel;
         $this->_paymetnResponse->paymentModel = $this->paymentModel;
         OrderLog::createLog(0, $this->orderModel->order_id, 21, implode(',', $errors));
         return false;
     }
     // Fill and save attempt Model
     $this->attemptModel->status = Attempt::SUCCESS_STATUS;
     $this->attemptModel->tracking_number = $pymtResp->get('TrackingNumber');
     $this->attemptModel->status_note = $pymtResp->get('Status') ? $pymtResp->get('Status') : '';
     $this->attemptModel->amount = round($pymtResp->get('Amount') / 100, 2);
     //I think we need to save this fields too: Filename, ApprovalCode, CVV2ResponseCode, Currency
     $this->attemptModel->save();
     /*
     'approval_code'    => $pymtResp->get('ApprovalCode'),
     'currency'         => $pymtResp->get('Currency'),
     'response_cc_cvv'  => $pymtResp->get('CVV2ResponseCode'),
     'filename'         => $pymtResp->get('Filename'),
     */
     //Set success status to response
     $this->_paymetnResponse->status = PaymentAPIResponse::SUCCESS_STATUS;
     $this->_paymetnResponse->attemptModel = $this->attemptModel;
     $this->_paymetnResponse->paymentModel = $this->paymentModel;
     OrderLog::createLog(0, $this->orderModel->order_id, 22, $this->attemptModel->amount . ' ' . $this->campaignModel->currency_id);
     return true;
 }