Example #1
0
 public function getAttachedOrders()
 {
     // grab attachment campaign info
     $attachedCampaigns = CampaignAttachs::getAttachedByCampaign($this->campaign_id, false);
     foreach ($attachedCampaigns as &$ac) {
         $campaingModel = new Campaign();
         $c = $campaingModel->findByPk($ac['campaign_attach_id']);
         if ($c) {
             $ac['campaign_attach_name_format'] = '[' . $c->campaign_id . '] ' . $c->campaign_name;
         }
         // is there already an order for the camp?  if so build order details
         $result = self::getOrderByParent($ac['campaign_attach_id'], $this->order_id);
         if (!empty($result)) {
             // doing this results in the instance of $this being reset to the attached order
             //$o = Order::model()->fillFromDbPk($result);
             $o = new Order();
             $o->fillFromDbPk($result);
             $ac['order_id'] = $o->getorder_id_name_link();
             $ac['status'] = $o->getstatus_image();
             $ac['created'] = $o->getcreated_formatted();
             unset($o);
         }
     }
     return $attachedCampaigns;
 }
Example #2
0
<?php

include_once '../settings/autoload.php';
$msql = SafeMySQL::getInstance();
// grab chargeback records
$sql = "\nSELECT \n\t`at`.temp_attempt_id\n  , `at`.tracking_number\n  , `a`.order_id \n  , `a`.amount\nFROM \n\tattempts_temp `at` \n\tJOIN attempts `a` USING (tracking_number) \nWHERE \n\t`at`.type = 'CHARGEBACK'";
$cb_success = array();
$chargeBacks = $msql->getAll($sql);
foreach ($chargeBacks as $cb) {
    // check order status
    $order = new Order();
    if ($order->fillFromDbPk($cb['order_id'])) {
        $order->chargeBackSet($cb['amount']);
        // check status
        if ($order->isFlag('chargeback')) {
            // delete from attempts_temp
            $cb_success[] = $cb['temp_attempt_id'];
            echo $order->order_id . '<br>';
        } else {
            // order not saved?  what now? leave in db for now
            /*
            $headers = 'From: "CB BLS' . Config::get()->prefix . ' IPN" <*****@*****.**>';
            mail('*****@*****.**', 'Chargeback order save failed', print_r($cb,1), $headers);
            */
        }
    } else {
        // bad order id
        echo $cb['order_id'] . ' - NOT VALID ORDER<br>';
        continue;
    }
    unset($order);
Example #3
0
 public function process()
 {
     // States list request from sales site
     if ($this->wsType == 'st') {
         // set headers
         AF::setJsonHeaders('json');
         // country_id has already been verified as set
         $states = State::model()->getStatesByCID($this->post['country_id']);
         // return json state list if present
         Message::echoJsonSuccess(array('message' => $states));
         exit;
     }
     // CRM Order
     if ($this->wsType == 'x1') {
         // EXISTING CUSTOMER CHECK
         if (!$this->newCustomer) {
             $this->customer = Customer::model()->fillFromDbPk($this->post['customer_id']);
             $this->shippingAddress = Address::model()->fillFromDbPk($this->post['address_id']);
             $this->billingAddress = Address::model()->fillFromDbPk($this->post['billing_address_id']);
         }
         // if customer already built then check for blacklist
         $this->buildCustomer();
         // EXISTING ORDER Check - DON'T NEED THIS I THINK
         $this->order = new Order();
         /*if (!$this->newCustomer && $this->order->fillFromDbPk($this->customer->getCustomerOkOrder($this->campaign->campaign_id)))
         		$this->apiError('An "OK" order already exists for this customer.  Order ID ' . $this->order->order_id);*/
         // addresses
         if (!isset($this->shippingAddress) || !$this->shippingAddress->getPkvalue()) {
             $this->buildAddress();
             if ($this->post['billingSameAsShipping']) {
                 $this->billingAddress = $this->shippingAddress;
             } else {
                 $this->buildAddress('billing');
             }
         }
         // payment before order.  if no payment specified allow order to still be built
         if ($this->isPayment && isset($this->post['payment_id']) && $this->post['payment_id']) {
             $this->payment = Payment::model()->fillFromDbPk($this->post['payment_id']);
         }
         if ($this->isPayment) {
             $this->buildPayment();
         }
         // order
         $this->buildOrder();
         // pay or return
         if ($this->isPayment) {
             $this->webPayment();
         } else {
             $this->order->status = 'ok';
             $this->order->addFlags('paid');
             // this needs to be set in order to have the order get sent to fulfillment
             $this->order->amount_product = '0.00';
             $this->order->amount_shipping = '0.00';
             $this->order->save();
         }
         $this->apiSuccess('Order ' . $this->order->order_id . ' created');
     }
     // Build prospect, click and customer info
     if (in_array($this->wsType, array('p', 'l'))) {
         $this->customer = new Customer();
         $this->order = new Order();
         $this->prospect = new Prospect();
         // EXISTING ORDER/CUSTOMER CHECK - make sure there isn't already an order for this campaign and email
         if ($this->customer->getCustomerByEmail($this->post['email']) && $this->customer->getCustomerOkOrder($this->campaign->campaign_id) && $this->order->fillFromDbPk($this->customer->getCustomerOkOrder($this->campaign->campaign_id))) {
             $this->thankYou(true);
         }
         // BlueSnap Pending Order Check
         // Has an order already been submitted to the gateway and is pending final approval?  If so, redirect to the thankyou page
         if (isset($this->customer->customer_id) && $this->order->orderPendingAttemptExists($this->campaign->campaign_id, $this->customer->customer_id)) {
             $this->thankYou(true);
         }
         // Existing Prospect check if customer already exists.  If no prospect, build click
         if ($this->customer->getPkValue()) {
             if (!$this->prospect->prospectExists($this->customer->customer_id, $this->campaign->campaign_id)) {
                 $this->buildClick();
             } else {
                 //prospect already exists. let's update the updated column
                 $this->prospect->created = 'NOW():sql';
                 //date("Y-m-d H:i:s");
                 $this->prospect->save();
                 // check the click info.  if its new then we need to double check it all
                 $this->buildClick($this->prospect->click_id);
             }
         } else {
             $this->buildClick();
         }
         $this->buildCustomer();
         $this->buildAddress();
         $this->buildProspect();
         // if this is not a lastchance request, then redirect the user to the order page
         if ($this->wsType != 'l') {
             // build return object.  SET TO HTTPS WHEN TESTING IS COMPLETE
             $url = $this->campaign->order_url . '?tempOrderId=' . $this->prospect->getPkValue();
             $this->apiSuccess($url);
         }
     }
     // Build Order
     if (in_array($this->wsType, array('o', 'l'))) {
         if ($this->wsType == 'o') {
             // load objects
             $this->prospect = new Prospect();
             if (!$this->prospect->fillFromDbPk($this->post['tempOrderId'])) {
                 $this->apiError('Error:12 - This temporary transaction is invalid');
             }
             $this->shippingAddress = new Address();
             if (!$this->shippingAddress->fillFromDbPk($this->prospect->address_id)) {
                 $this->apiError('Error:12 - This temporary transaction is invalid');
             }
             $this->customer = new Customer();
             if (!$this->customer->fillFromDbPk($this->prospect->customer_id)) {
                 $this->apiError('Error:12 - This temporary transaction is invalid');
             }
         }
         $this->buildOrder();
     }
     // Upsell
     if (in_array($this->wsType, array('u'))) {
         // load objects
         $this->order = new Order();
         if (!$this->order->fillFromDbPk($this->post['tempOrderId'])) {
             $this->apiError('Error:12 - This transaction is invalid');
         }
         // already processed?  if so send to TY page, unless there's been a decline/error
         if (!in_array($this->order->status, array('new', 'error'))) {
             $this->thankYou(true);
         }
         // check for test order
         if ($this->order->isFlag('test')) {
             $this->setTest();
         }
         $this->upsellProcess();
     }
     // 1Click
     if (in_array($this->wsType, array('c'))) {
         // add some time to the request to give the payment gateway rest time
         sleep(2);
         $this->customer = new Customer();
         $existingOrder = new Order();
         // EXISTING ORDER/CUSTOMER CHECK - make sure there isn't already an order for this campaign and email
         if ($this->customer->getCustomerByEmail($this->order->customer->email) && $this->customer->getCustomerOkOrder($this->campaign->campaign_id) && $existingOrder->fillFromDbPk($this->order->customer->getCustomerOkOrder($this->campaign->campaign_id))) {
             $this->thankYou();
         }
         // BlueSnap Pending Order Check
         // Has an order already been submitted to the gateway and is pending final approval?  If so, redirect to the thankyou page
         if ($this->order->orderPendingAttemptExists($this->campaign->campaign_id, $this->order->customer->customer_id)) {
             $this->thankYou(true);
         }
         // load/build objects
         $this->buildClick();
         // order already built in isValid()
         $this->customer = Customer::model()->fillFromDbPk($this->order->customer_id);
         $this->payment = Payment::model()->fillFromDbPk($this->order->payment_id);
         $this->shippingAddress = Address::model()->fillFromDbPk($this->order->address_id);
         $this->billingAddress = Address::model()->fillFromDbPk($this->order->billing_address_id);
         $this->post['ps'] = $this->order->gateway->system_code;
         $this->buildOrder();
     }
 }
Example #4
0
 function setaddressAction()
 {
     $this->checkLogin();
     AF::setJsonHeaders('json');
     $order_id = AF::get($_POST, 'order_id', false);
     $order = new Order();
     $order->fillFromDbPk($order_id);
     $address_id = AF::get($_POST, 'address_id', false);
     if (!$address_id) {
         Message::echoJsonError(__('incorrect_address_id'));
     }
     $address_type = AF::get($_POST, 'address_type', false);
     if ($address_type == "shipping") {
         $order->address_id = $address_id;
     } else {
         $order->billing_address_id = $address_id;
     }
     $model = new Address();
     $model = $model->getAddressById($address_id);
     $table_rows = array('fname' => 'fname', 'lname' => 'lname', 'phone' => 'phone', 'address1' => 'address1', 'address2' => 'address2', 'country' => 'country_id', 'state' => 'state_id', 'city' => 'city', 'zip' => 'zip');
     foreach ($table_rows as $key => $value) {
         if ($value == "country_id") {
             $model[$value] = $model['country_name'] . " (" . $model['country_id'] . ")";
         }
         if ($value == "state_id") {
             $model[$value] = $model['state_name'] . " (" . $model['state_id'] . ")";
         }
         $table[] = "<tr><td>" . __($address_type . "_" . $key) . "</td><td>" . $model[$value] . "</td></tr>";
     }
     if ($order->save(false)) {
         Message::echoJsonSuccess(array('message' => 'Address Updated', 'table_result' => implode('', $table)));
     } else {
         Message::echoJsonError('Error Saving');
     }
     exit;
 }
Example #5
0
 function deleteAction()
 {
     $id = AF::get($_POST, 'id', 0);
     $modelsID = explode(',', $id);
     $errors = FALSE;
     foreach ($modelsID as $id) {
         $model = new Order();
         if ($model->fillFromDbPk($id)) {
             $orderDeleteModel = new OrderDelete();
             $orderDeleteModel->fillFromArray($model->getAttributes());
             if ($orderDeleteModel->save()) {
                 if (!$model->delete()) {
                     $errors = true;
                 }
             } else {
                 $errors = true;
             }
             OrderLog::createLog($this->user->user_id, $id, 25);
         } else {
             $errors = TRUE;
         }
         if ($model->getErrors()) {
             $errors = TRUE;
         }
         unset($model);
     }
     if (isset($_POST['ajax'])) {
         AF::setJsonHeaders('json');
         if ($errors) {
             Message::echoJsonError(__('order_no_deleted'));
         } else {
             Message::echoJsonSuccess(__('order_deleted'));
         }
     }
 }
Example #6
0
<?php

include_once '../settings/autoload.php';
$msql = SafeMySQL::getInstance();
//$jobModel = new Job();
//$jobModel->getOneNew();
//if(!$jobModel->job_id)
//    exit();
while ($jobModel = Job::getOne()) {
    switch ($jobModel->job_type) {
        case 'refund':
            $orderModel = new Order();
            $orderModel->fillFromDbPk($jobModel->order_id);
            if (!($countRefunded = $orderModel->countRefunded)) {
                exit;
            }
            @(include_once '../../ws/class/lib.class.php');
            @(include_once '../../ws/class/ipayment.class.php');
            @(include_once '../../ws/class/payment.class.php');
            @(include_once '../../ws/class/raven_config_demo.php');
            @(include_once '../../ws/class/ravenrequest.class.php');
            @(include_once '../../ws/class/payment_' . $orderModel->payment_type . '.class.php');
            $paymentSystem = Payment::getPaymentSystem($orderModel);
            try {
                if ($paymentSystem->setRefund($countRefunded)) {
                    $jobModel->done();
                    $saveOrder = new Order();
                    $saveOrder->order_id = $jobModel->order_id;
                    $saveOrder->payment_total = $orderModel->payment_total - $countRefunded;
                    echo $saveOrder->payment_total . '<br>';
                    $saveOrder->setIsNewRecord(false);