function createBillingTransaction($method, $amount, $result, $trax_state)
 {
     global $order, $db, $user;
     $bt = new billingtransaction();
     $bt->billingmethods_id = $method->id;
     $bt->billingcalculator_id = $method->billingcalculator_id;
     $bt->billing_cost = $amount;
     $bt->billing_options = serialize($result);
     $bt->extra_data = '';
     $bt->transaction_state = $trax_state;
     //$bt->result = $result;
     $bt->save();
 }
Example #2
0
 function save_new_order()
 {
     //eDebug($this->params);
     /*addresses_id
       customer_type = 1 //new
       customer_type = 2 //existing Internal
       customer_type = 3 //existing external*/
     global $user, $db;
     //eDebug($this->params,true);
     //$order = new order($this->params['original_orderid']);
     //eDebug($order,true);
     $newAddy = new address();
     if ($this->params['customer_type'] == 1) {
         //blank order
         $newAddy->save(false);
     } else {
         if ($this->params['customer_type'] == 2) {
             //internal customer
             $newAddy = new address($this->params['addresses_id']);
         } else {
             if ($this->params['customer_type'] == 3) {
                 //other customer
                 $otherAddy = new external_address($this->params['addresses_id']);
                 $newAddy->user_id = $otherAddy->user_id;
                 $newAddy->firstname = $otherAddy->firstname;
                 $newAddy->lastname = $otherAddy->lastname;
                 $newAddy->organization = $otherAddy->organization;
                 $newAddy->address1 = $otherAddy->address1;
                 $newAddy->address2 = $otherAddy->address2;
                 $newAddy->city = $otherAddy->city;
                 $newAddy->state = $otherAddy->state;
                 $newAddy->zip = $otherAddy->zip;
                 $newAddy->phone = $otherAddy->phone;
                 $newAddy->email = $otherAddy->email;
                 $newAddy->save();
             }
         }
     }
     $newOrder = new order();
     $newOrder->order_status_id = $this->params['order_status_id'];
     $newOrder->order_type_id = $this->params['order_type_id'];
     //$newOrder->order_references = $order->id;
     $newOrder->reference_id = 0;
     $newOrder->user_id = 0;
     $newOrder->purchased = time();
     $newOrder->updated = time();
     $newOrder->invoice_id = $newOrder->getInvoiceNumber();
     $newOrder->orderitem = array();
     $newOrder->subtotal = 0;
     $newOrder->total_discounts = 0;
     $newOrder->tax = 0;
     $newOrder->shipping_total = 0;
     $newOrder->surcharge_total = 0;
     $newOrder->grand_total = 0;
     $newOrder->save();
     $newOrder->refresh();
     $tObj->result->errorCode = 0;
     $tObj->result->message = "Reference Order Pending";
     $tObj->result->PNREF = "Pending";
     $tObj->result->authorization_code = "Pending";
     $tObj->result->AVSADDR = "Pending";
     $tObj->result->AVSZIP = "Pending";
     $tObj->result->CVV2MATCH = "Pending";
     $tObj->result->traction_type = "Pending";
     $newBillingMethod = new billingmethod();
     $newBillingMethod->addresses_id = $newAddy->id;
     $newBillingMethod->orders_id = $newOrder->id;
     $newBillingMethod->billing_cost = 0;
     $newBillingMethod->billingcalculator_id = 6;
     $newBillingMethod->transaction_state = 'authorization pending';
     $newBillingMethod->billing_options = serialize($tObj);
     $newBillingMethod->firstname = $newAddy->firstname;
     $newBillingMethod->lastname = $newAddy->lastname;
     $newBillingMethod->organization = $newAddy->organization;
     $newBillingMethod->address1 = $newAddy->address1;
     $newBillingMethod->address2 = $newAddy->address2;
     $newBillingMethod->city = $newAddy->city;
     $newBillingMethod->state = $newAddy->state;
     $newBillingMethod->zip = $newAddy->zip;
     $newBillingMethod->phone = $newAddy->phone;
     $newBillingMethod->email = $newAddy->email;
     $newBillingMethod->save();
     //eDebug(expUnserialize($order->billingmethod[0]->billing_options));
     //eDebug(expUnserialize($order->billingmethod[0]->billingtransaction[0]->billing_options),true);
     $newBillingTransaction = new billingtransaction();
     $newBillingTransaction->billingcalculator_id = 6;
     ///setting to manual/passthru
     $newBillingTransaction->billing_cost = 0;
     $newBillingTransaction->billingmethods_id = $newBillingMethod->id;
     $newBillingTransaction->transaction_state = 'authorization pending';
     $newBillingTransaction->billing_options = serialize($tObj);
     $newBillingTransaction->save();
     $newShippingMethod = new shippingmethod();
     $newShippingMethod->shipping_cost = 0;
     $newShippingMethod->shippingcalculator_id = $db->selectValue('shippingcalculator', 'id', 'is_default=1');
     $newShippingMethod->addresses_id = $newAddy->id;
     $newShippingMethod->firstname = $newAddy->firstname;
     $newShippingMethod->lastname = $newAddy->lastname;
     $newShippingMethod->organization = $newAddy->organization;
     $newShippingMethod->address1 = $newAddy->address1;
     $newShippingMethod->address2 = $newAddy->address2;
     $newShippingMethod->city = $newAddy->city;
     $newShippingMethod->state = $newAddy->state;
     $newShippingMethod->zip = $newAddy->zip;
     $newShippingMethod->phone = $newAddy->phone;
     $newShippingMethod->email = $newAddy->email;
     $newShippingMethod->save();
     $newShippingMethod->refresh();
     $oi = new orderitem();
     $oi->orders_id = $newOrder->id;
     $oi->product_id = 0;
     $oi->product_type = 'product';
     $oi->products_name = "N/A";
     $oi->products_model = "N/A";
     $oi->products_price = 0;
     $oi->shippingmethods_id = $newShippingMethod->id;
     $oi->save(false);
     flash('message', gt('New Order #') . $newOrder->invoice_id . " " . gt("created successfully."));
     redirect_to(array('controller' => 'order', 'action' => 'show', 'id' => $newOrder->id));
 }